Skip to content

Commit bf8965a

Browse files
committedOct 27, 2017
add test infrastructure and fix lint
1 parent 6b0acac commit bf8965a

12 files changed

+139
-9
lines changed
 

‎.eslintignore

+3
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
1+
.git
2+
.nyc_output
3+
coverage
14
node_modules

‎.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
node_modules
22
npm-debug.log
3+
.nyc_output
4+
coverage

‎.npmignore

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
*.json
22
!package.json
3-
!test
4-
!.git
3+
test
4+
.git
5+
.nyc_output
6+
coverage

‎lib/auth.js

+6-3
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ async function auth() {
4444
await writeFile(authFile, json, { mode:
4545
0o600 /* owner read/write */
4646
});
47-
return await auth();
47+
return auth();
4848
}
4949

5050
async function prompt(question) {
@@ -66,7 +66,10 @@ async function prompt(question) {
6666
function lazy(fn) {
6767
let cachedValue;
6868
return function() {
69-
if (cachedValue !== undefined) { return cachedValue; }
70-
return cachedValue = fn();
69+
if (cachedValue !== undefined) {
70+
return cachedValue;
71+
}
72+
cachedValue = fn();
73+
return cachedValue;
7174
};
7275
}

‎lib/request.js

-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ async function request(query, variables) {
3535
async function requestAll(query, variables, path) {
3636
let after = null;
3737
let all = [];
38-
let totalCount;
3938
// first page
4039
do {
4140
const varWithPage = Object.assign({
@@ -51,7 +50,6 @@ async function requestAll(query, variables, path) {
5150
// pageInfo { hasNextPage, endCursor }
5251
// nodes
5352
all = all.concat(current.nodes);
54-
totalCount = current.totalCount;
5553
if (current.pageInfo.hasNextPage) {
5654
after = current.pageInfo.endCursor;
5755
} else {

‎package.json

+10-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@
77
"get-metadata": "./bin/metadata.js"
88
},
99
"scripts": {
10-
"test": "echo \"Error: no test specified\" && exit 1",
10+
"test": "npm run test-unit && npm run lint",
11+
"test-unit": "mocha --require intelli-espower-loader test/unit/*.test.js",
12+
"test-all": "mocha --require intelli-espower-loader test/**/*.test.js",
13+
"coverage": "nyc npm test",
14+
"coverage-all": "nyc npm run test-all",
1115
"lint": "eslint ."
1216
},
1317
"author": "Joyee Cheung <joyeec9h3@gmail.com>",
@@ -25,6 +29,10 @@
2529
"eslint-plugin-import": "^2.8.0",
2630
"eslint-plugin-node": "^5.2.1",
2731
"eslint-plugin-promise": "^3.6.0",
28-
"eslint-plugin-standard": "^3.0.1"
32+
"eslint-plugin-standard": "^3.0.1",
33+
"intelli-espower-loader": "^1.0.1",
34+
"mocha": "^4.0.1",
35+
"nyc": "^11.2.1",
36+
"power-assert": "^1.4.4"
2937
}
3038
}

‎test/.eslintrc

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"env": {
3+
"node": true,
4+
"mocha": true
5+
}
6+
}

‎test/fixtures/comments_with_ci.json

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
[
2+
{
3+
"publishedAt": "2017-10-27T04:16:36.458Z",
4+
"bodyText": "CI: https://ci.nodejs.org/job/node-test-pull-request/10984/\ncitgm: https://ci.nodejs.org/view/Node.js-citgm/job/citgm-smoker/1030/"
5+
},
6+
{
7+
"publishedAt": "2017-10-24T04:16:36.458Z",
8+
"bodyText": "https://ci.nodejs.org/view/libuv/job/libuv-test-commit/537/"
9+
},
10+
{
11+
"publishedAt": "2017-10-23T04:16:36.458Z",
12+
"bodyText": "https://ci.nodejs.org/job/node-test-commit-linux-nointl/7"
13+
},
14+
{
15+
"publishedAt": "2017-10-22T04:16:36.458Z",
16+
"bodyText": "CI: https://ci.nodejs.org/job/node-test-pull-request/10992/\nV8 CI: https://ci.nodejs.org/job/node-test-commit-v8-linux/1018/"
17+
},
18+
{
19+
"publishedAt": "2017-10-21T04:16:36.458Z",
20+
"bodyText": "Oh nice, it's back now. Benchmark CI: https://ci.nodejs.org/job/benchmark-node-micro-benchmarks/20/"
21+
}
22+
]

‎test/fixtures/index.js

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
'use strict';
2+
3+
const fs = require('fs');
4+
const path = require('path');
5+
6+
exports.readFile = function(filePath) {
7+
const file = path.resolve(__dirname, filePath);
8+
return fs.readFileSync(file, 'utf8');
9+
};
10+
11+
exports.readJSON = function(filePath) {
12+
const file = exports.readFile(filePath);
13+
return JSON.parse(file);
14+
};

‎test/fixtures/op_html.json

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[
2+
"<p>The npm install rules had a hidden dependency on the <code>node</code> binary<br>\ninstall rule creating the <code>$PREFIX/bin</code> directory.</p>\n<p>Because with <code>./configure --shared</code> no binary is created, the rule<br>\nsubsequently failed. Fix that by creating the directory before<br>\ncreating the symlinks to the npm and npx scripts.</p>\n<p>(Whether it makes sense to install npm without a <code>node</code> binary is<br>\na separate question. This commit is not taking positions. :-))</p>\n<p>Regression introduced in commit <a href=\"https://github.com/nodejs/node/commit/ed8c89a07d159b72a2e351a76c92b8b6a15515bd\" class=\"commit-link\"><tt>ed8c89a</tt></a> (\"build: fix shared installing<br>\ntarget\") which, as the commit log indicates, was itself a bug fix for<br>\nthe <code>./configure --shared</code> install.</p>\n<p>Fixes: <a href=\"https://github.com/nodejs/node/issues/16437\" class=\"issue-link js-issue-link\" data-error-text=\"Failed to load issue title\" data-id=\"267969588\" data-permission-text=\"Issue title is private\" data-url=\"https://github.com/nodejs/node/issues/16437\">#16437</a><br>\nRefs: <a href=\"https://github.com/nodejs/node/pull/15148\" class=\"issue-link js-issue-link\" data-error-text=\"Failed to load issue title\" data-id=\"254809069\" data-permission-text=\"Issue title is private\" data-url=\"https://github.com/nodejs/node/issues/15148\">#15148</a></p>",
3+
"<p>Refs: <a href=\"https://github.com/nodejs/node/pull/16293\" class=\"issue-link js-issue-link\" data-error-text=\"Failed to load issue title\" data-id=\"266519190\" data-permission-text=\"Issue title is private\" data-url=\"https://github.com/nodejs/node/issues/16293\">#16293</a></p>\n<h5>Checklist</h5>\n\n<ul class=\"contains-task-list\">\n<li class=\"task-list-item\"><input checked=\"\" class=\"task-list-item-checkbox\" disabled=\"\" id=\"\" type=\"checkbox\"> <code>make -j4 test</code> (UNIX), or <code>vcbuild test</code> (Windows) passes</li>\n<li class=\"task-list-item\"><input checked=\"\" class=\"task-list-item-checkbox\" disabled=\"\" id=\"\" type=\"checkbox\"> commit message follows <a href=\"https://github.com/nodejs/node/blob/master/CONTRIBUTING.md#commit-message-guidelines\">commit guidelines</a></li>\n</ul>\n<h5>Affected core subsystem(s)</h5>\n\n<p>vm</p>"
4+
]

‎test/unit/ci.test.js

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
'use strict';
2+
3+
const CIParser = require('../../lib/ci');
4+
const fixtures = require('../fixtures');
5+
const assert = require('assert');
6+
const comments = fixtures.readJSON('comments_with_ci.json');
7+
8+
const expected = new Map([
9+
['FULL', {
10+
link: 'https://ci.nodejs.org/job/node-test-pull-request/10984/',
11+
date: '2017-10-27T04:16:36.458Z'
12+
}],
13+
['CITGM', {
14+
link: 'https://ci.nodejs.org/view/Node.js-citgm/job/citgm-smoker/1030/',
15+
date: '2017-10-27T04:16:36.458Z'
16+
}],
17+
['LIBUV', {
18+
link: 'https://ci.nodejs.org/view/libuv/job/libuv-test-commit/537/',
19+
date: '2017-10-24T04:16:36.458Z'
20+
}],
21+
['NOINTL', {
22+
link: 'https://ci.nodejs.org/job/node-test-commit-linux-nointl/7',
23+
date: '2017-10-23T04:16:36.458Z'
24+
}],
25+
['V8', {
26+
link: 'https://ci.nodejs.org/job/node-test-commit-v8-linux/1018/',
27+
date: '2017-10-22T04:16:36.458Z'
28+
}],
29+
['BENCHMARK', {
30+
link: 'https://ci.nodejs.org/job/benchmark-node-micro-benchmarks/20/',
31+
date: '2017-10-21T04:16:36.458Z'
32+
}]
33+
]);
34+
35+
describe('CIparser', () => {
36+
it('should parse CI results', () => {
37+
const results = new CIParser(comments).parse();
38+
assert.deepStrictEqual(expected, results);
39+
});
40+
});

‎test/unit/links.test.js

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
'use strict';
2+
3+
const LinkParser = require('../../lib/links');
4+
const fixtures = require('../fixtures');
5+
const assert = require('assert');
6+
const htmls = fixtures.readJSON('op_html.json');
7+
8+
const expected = [{
9+
fixes: ['https://github.com/node/issues/16437'],
10+
refs: ['https://github.com/nodejs/node/pull/15148']
11+
}, {
12+
fixes: [],
13+
refs: ['https://github.com/nodejs/node/pull/16293']
14+
}];
15+
16+
describe('CIparser', () => {
17+
it('should parse CI results', () => {
18+
for (let i = 0; i < htmls.length; ++i) {
19+
const op = htmls[i];
20+
const parser = new LinkParser('node', op);
21+
const actual = {
22+
fixes: parser.getFixes(),
23+
refs: parser.getRefs()
24+
};
25+
assert.deepStrictEqual(actual, expected[i]);
26+
}
27+
});
28+
});

0 commit comments

Comments
 (0)
Please sign in to comment.