Skip to content

Commit

Permalink
Merge pull request #205 from yujiosaka/separately-run-redis-cache-test
Browse files Browse the repository at this point in the history
Separately run redis cache test
  • Loading branch information
yujiosaka authored Apr 7, 2018
2 parents 7c4092d + 97e35ce commit e81c4ae
Show file tree
Hide file tree
Showing 17 changed files with 447 additions and 405 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ jobs:
- node_modules
key: v1-dependencies-{{ checksum "package.json" }}
- run: yarn greenkeeper-lockfile-update
- run: yarn test
- run: yarn test-all
- run: yarn greenkeeper-lockfile-upload
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]

### changed

- Bump Node.js version up to 8.10.0.
- Move [node_redis](https://github.com/NodeRedis/node_redis) to the peer dependencies.

## [1.5.0] - 2018-03-25

### Added
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Please note that this project has a [code of conduct](https://github.com/yujiosa
## Contributing Process

1. Modify code following [ESLint](https://eslint.org) and the code should be annotated with [JSDoc annotations](https://github.com/Microsoft/TypeScript/wiki/JSDoc-support-in-JavaScript).
2. Make sure all tests are passed by `yarn test`. Modify tests when the interface has changed.
2. Make sure all tests are passed by `yarn test` (or run `yarn test-all` when you modify the [RedisCache](https://github.com/yujiosaka/headless-chrome-crawler/blob/master/cache/redis.js)'s code). Modify tests when the interface has changed.
2. Update the [README.md](https://github.com/yujiosaka/headless-chrome-crawler/blob/master/README.md) with details of changes to the interface.
3. Update the [CHANGELOG.md](https://github.com/yujiosaka/headless-chrome-crawler/blob/master/CHANGELOG.md). The versioning scheme we use is [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
4. Make your commit message following [Conventional Commits](https://conventionalcommits.org/).
Expand Down
18 changes: 16 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Powered by Headless Chrome, the crawler provides [simple APIs](#api-reference) t

### Installation

```
```sh
yarn add headless-chrome-crawler
# or "npm i headless-chrome-crawler"
```
Expand Down Expand Up @@ -530,11 +530,25 @@ Also, the `args` option is passed to the browser instance. List of Chromium flag
HCCrawler.launch({ args: ['--disable-web-security'] });
```

### Running tests

All tests but [RedisCache's](https://github.com/yujiosaka/headless-chrome-crawler/blob/master/test/cache/redis.test.js) are run by the following command:

```sh
yarn test
```

When you modify [RedisCache](https://github.com/yujiosaka/headless-chrome-crawler/blob/master/cache/redis.js)'s code, make sure that [Redis](https://redis.io/) is installed, start the server and run all tests with the following command:

```sh
yarn test-all
```

### Enable debug logging

All requests and browser's logs are logged via the [debug](https://github.com/visionmedia/debug) module under the `hccrawler` namespace.

```
```sh
env DEBUG="hccrawler:*" node script.js
env DEBUG="hccrawler:request" node script.js
env DEBUG="hccrawler:browser" node script.js
Expand Down
2 changes: 1 addition & 1 deletion lib/hccrawler.js
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ class HCCrawler extends EventEmitter {
if (!options.followSitemapXml) return;
const robot = await this._getRobot(options);
const sitemapUrls = robot.getSitemaps();
await Promise.resolve(map(sitemapUrls, async (sitemapUrl) => {
await Promise.resolve(map(sitemapUrls, async sitemapUrl => {
const sitemapXml = await this._getSitemapXml(sitemapUrl);
const urls = getSitemapUrls(sitemapXml);
each(urls, url => void this._push(extend({}, options, { url }), depth));
Expand Down
12 changes: 9 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@
"greenkeeper-lockfile-update": "greenkeeper-lockfile-update",
"greenkeeper-lockfile-upload": "greenkeeper-lockfile-upload",
"lint": "eslint --quiet -f codeframe . || eslint .",
"test": "yarn tsc && yarn lint && mocha",
"mocha-exclude-redis-cache": "mocha $(find test -name '*.test.js') --exclude test/cache/redis.test.js",
"mocha-redis-cache": "mocha test/cache/redis.test.js",
"test": "yarn tsc && yarn lint && yarn mocha-exclude-redis-cache",
"test-all": "yarn test && yarn mocha-redis-cache",
"tsc": "tsc -p ."
},
"repository": {
Expand All @@ -27,11 +30,13 @@
"jquery": "3.3.1",
"lodash": "4.17.5",
"puppeteer": "1.2.0",
"redis": "2.8.0",
"request": "2.83.0",
"request-promise": "4.2.2",
"robots-parser": "1.0.2"
},
"peerDependencies": {
"redis": "^2.8.0"
},
"devDependencies": {
"@commitlint/cli": "6.1.3",
"@commitlint/config-conventional": "6.1.3",
Expand All @@ -45,8 +50,9 @@
"eslint-plugin-import": "2.10.0",
"greenkeeper-lockfile": "1.14.0",
"mime": "2.2.1",
"mocha": "5.0.5",
"mocha": "mochajs/mocha#88b9882",
"power-assert": "1.5.0",
"redis": "2.8.0",
"sinon": "5.0.0",
"typescript": "2.7.2"
},
Expand Down
4 changes: 4 additions & 0 deletions test/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,8 @@ module.exports = {
"env": {
"mocha": true,
},
"rules": {
"global-require": 0,
"prefer-arrow-callback": 0,
},
};
24 changes: 11 additions & 13 deletions test/async-events.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,22 @@ const assert = require('assert');
const AsyncEventEmitter = require('../lib/async-events');
const { delay } = require('../lib/helper');

describe('AsyncEventEmitter', () => {
describe('AsyncEventEmitter', function () {
let eventEmitter;

beforeEach(() => {
beforeEach(function () {
eventEmitter = new AsyncEventEmitter();
});

it('listens to an event', () => {
it('listens to an event', function () {
let actual = 0;
const expected = 1;
eventEmitter.on('success', () => { actual += 1; });
eventEmitter.emitAsync('success');
assert.equal(actual, expected);
});

it('listens to an event emitted multiple times', () => {
it('listens to an event emitted multiple times', function () {
let actual = 0;
const expected = 2;
eventEmitter.on('success', () => { actual += 1; });
Expand All @@ -26,7 +26,7 @@ describe('AsyncEventEmitter', () => {
assert.equal(actual, expected);
});

it('listens multiple times to an event', () => {
it('listens multiple times to an event', function () {
let actual = 0;
const expected = 3;
eventEmitter.on('success', () => { actual += 1; });
Expand All @@ -35,23 +35,23 @@ describe('AsyncEventEmitter', () => {
assert.equal(actual, expected);
});

it('listens to an event with single argument', () => {
it('listens to an event with single argument', function () {
let actual;
const expected = new Error('Url must be defined!');
eventEmitter.on('error', error => { actual = error; });
eventEmitter.emitAsync('error', expected);
assert.equal(actual, expected);
});

it('listens to an event with multiple arguments', () => {
it('listens to an event with multiple arguments', function () {
let actual;
const expected = 1;
eventEmitter.on('pull', (options, depth) => { actual = depth; });
eventEmitter.emitAsync('pull', { url: 'http://example.com/' }, 1);
assert.equal(actual, expected);
});

it('listens to an async event', () => {
it('listens to an async event', function () {
let actual = 0;
const expected = 0;
eventEmitter.on('success', async () => {
Expand All @@ -62,16 +62,14 @@ describe('AsyncEventEmitter', () => {
assert.equal(actual, expected);
});

it('waits until resolving async event', () => {
it('waits until resolving async event', async function () {
let actual = 0;
const expected = 1;
eventEmitter.on('success', async () => {
await delay(100);
actual += 1;
});
return eventEmitter.emitAsync('success')
.then(() => {
assert.equal(actual, expected);
});
await eventEmitter.emitAsync('success');
assert.equal(actual, expected);
});
});
153 changes: 0 additions & 153 deletions test/cache.test.js

This file was deleted.

Loading

0 comments on commit e81c4ae

Please sign in to comment.