Skip to content

Commit

Permalink
Merge pull request #181 from yujiosaka/support-slowmo-option-for-connect
Browse files Browse the repository at this point in the history
feat(hccrawler): support slowMo option for connection
  • Loading branch information
yujiosaka authored Mar 24, 2018
2 parents 35aa2a7 + 3b5055a commit 77a134e
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
### Added

- Support `waitFor` for [crawler.queue()](https://github.com/yujiosaka/headless-chrome-crawler#crawlerqueueoptions)'s options.
- Support `slowMo` for [HCCrawler.connect()](#hccrawlerconnectoptions)'s options.

### Fixed

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ HCCrawler.launch({
This method connects to an existing Chromium instance. The following options are passed to [puppeteer.connect()](https://github.com/GoogleChrome/puppeteer/blob/master/docs/api.md#puppeteerconnectoptions).

```
browserWSEndpoint, ignoreHTTPSErrors
browserWSEndpoint, ignoreHTTPSErrors, slowMo
```

Also, the following options can be set as default values when [crawler.queue()](#crawlerqueueoptions) are executed.
Expand Down
1 change: 1 addition & 0 deletions lib/hccrawler.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const SessionCache = require('../cache/session');
const CONNECT_OPTIONS = [
'browserWSEndpoint',
'ignoreHTTPSErrors',
'slowMo',
];
const LAUNCH_OPTIONS = [
'ignoreHTTPSErrors',
Expand Down
34 changes: 34 additions & 0 deletions test/hccrawler.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,33 @@ describe('HCCrawler', () => {
});
});

describe('HCCrawler.connect', () => {
let crawler;

beforeEach(() => (
HCCrawler.launch(DEFAULT_OPTIONS)
.then(_crawler => {
crawler = _crawler;
})
));

afterEach(() => crawler.close());

it('connects multiple times to the same crawler', () => (
HCCrawler.connect({ browserWSEndpoint: crawler.wsEndpoint() })
.then(secondCrawler => secondCrawler.close())
));

it('reconnects to an already disconnected crawler', () => {
const browserWSEndpoint = crawler.wsEndpoint();
return crawler.disconnect()
.then(() => HCCrawler.connect({ browserWSEndpoint }))
.then(_crawler => {
crawler = _crawler;
});
});
});

describe('HCCrawler.launch', () => {
let crawler;
let onSuccess;
Expand All @@ -46,6 +73,13 @@ describe('HCCrawler', () => {

afterEach(() => crawler.close());

it('launches a crawler', () => (
HCCrawler.launch(DEFAULT_OPTIONS)
.then(_crawler => {
crawler = _crawler;
})
));

context('when the server is running', () => {
let server;

Expand Down

0 comments on commit 77a134e

Please sign in to comment.