Skip to content

Commit 3f2e039

Browse files
committed
Test Cleanup
1 parent 0f851ca commit 3f2e039

File tree

9 files changed

+426
-1086
lines changed

9 files changed

+426
-1086
lines changed

.travis.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
---
1+
os:
2+
- osx
3+
- linux
24
language: node_js
35
node_js:
46
- 10
57
- 11
6-
dist: trusty
7-
sudo: false
88
install: npm install
99
script: npm test

bin/run.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ let transform;
107107
let preprocessor;
108108

109109
if (argv.transformer || argv.transform) {
110-
transform = require(argv.transformer || argv.transform);
110+
transform = require(path.join(process.cwd(), argv.transformer || argv.transform));
111111
}
112112

113113
if (argv.preprocessor) {

package-lock.json

+284-990
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-4
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,9 @@
88
"test262-harness": "bin/run.js"
99
},
1010
"scripts": {
11-
"test": "node_modules/.bin/tap test/*.js"
11+
"test": "node_modules/.bin/tap --no-esm -T test/*.js"
1212
},
1313
"dependencies": {
14-
"chalk": "^2.4.2",
1514
"eshost": "^5.0.0",
1615
"minimatch": "^3.0.4",
1716
"rxjs": "^6.4.0",
@@ -27,8 +26,6 @@
2726
"test"
2827
],
2928
"devDependencies": {
30-
"@babel/core": "^7.4.0",
31-
"@babel/preset-env": "^7.4.2",
3229
"rimraf": "^2.6.3",
3330
"tap": "^12.6.0"
3431
}

test/preprocessor/autofail.js

+2-20
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,8 @@
1-
const babel = require("@babel/core");
2-
const options = {
3-
cwd: __dirname,
4-
presets: [
5-
[
6-
"@babel/preset-env",
7-
{
8-
spec: true
9-
}
10-
]
11-
]
12-
};
13-
14-
class Test262Fake extends Error {}
15-
161
module.exports = function(test) {
172
test.result = {
18-
stderr: 'This is a fake test.',
3+
stderr: 'Test262Fake: This is a fake test.',
194
stdout: '',
20-
error: {
21-
name: 'Test262Error',
22-
message: 'Test262Fake: This is a fake test.'
23-
}
5+
error: null
246
};
257

268
return test;

test/preprocessor/spec.js

-23
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,3 @@
1-
const babel = require("@babel/core");
2-
const options = {
3-
cwd: __dirname,
4-
presets: [
5-
[
6-
"@babel/preset-env",
7-
{
8-
spec: true
9-
}
10-
]
11-
]
12-
};
13-
141
module.exports = function(test) {
15-
try {
16-
test.contents = babel.transform(test.contents, options).code;
17-
} catch (error) {
18-
test.result = {
19-
stderr: error.toString(),
20-
stdout: '',
21-
error: null
22-
};
23-
}
24-
252
return test;
263
};

test/test.js

+129-26
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,122 @@
11
'use strict';
22

3-
const parseFile = require('test262-parser').parseFile;
43
const run = require('./util/run');
54
const tap = require('tap');
65
const path = require('path');
76

87
const tests = [
9-
[['test/**/*.js'], { cwd: 'test/collateral-with-harness/test262' }],
10-
[['--test262Dir', './test/collateral-with-harness/test262', './test/collateral-with-harness/test262/test/**/*.js']],
11-
[['--test262Dir', './test/collateral-with-harness/test262', './test/collateral-with-harness/test262/test/**/*.js', './test/collateral-with-harness/loose-tests/*']],
12-
[['--test262Dir', './collateral-with-harness/test262', 'collateral-with-harness/test262/test/**/*.js'], { cwd: 'test' }],
13-
[['--includesDir', './test/test-includes', './test/collateral/test/**/*.js']],
14-
[['test/collateral-with-harness/test262/test/**/*.js']],
15-
[['--includesDir', './test-includes', 'collateral/test/**/*.js'], { cwd: 'test' }],
16-
[['collateral-with-harness/test262/test/**/*.js'], { cwd: 'test' }],
17-
[['--includesDir', './test/test-includes', '--prelude', './test/fixtures/prelude-a.js', '--prelude', './test/fixtures/prelude-b.js', './test/collateral/test/bothStrict.js'], { prelude: true }],
18-
[['--includesDir', './test/test-includes', '--reporter-keys', 'attrs,result', './test/collateral/test/bothStrict.js'], { noRawResult: true }],
19-
[['--includesDir', './test/test-includes', '--reporter-keys', 'rawResult,attrs,result', './test/collateral/test/bothStrict.js']],
20-
[['--includesDir', './test/test-includes', '--reporter-keys', 'attrs,rawResult,result', './test/collateral/test/bothStrict.js']],
21-
[['--includesDir', './test/test-includes', '--reporter-keys', 'attrs,result,rawResult', './test/collateral/test/bothStrict.js']],
22-
[['--includesDir', './test/test-includes', '--transformer', path.join(__dirname, './transformer/spec.js'), '--reporter-keys', 'attrs,result,rawResult', './test/babel-collateral/test/spread-sngl-obj-ident.js']],
23-
[['--includesDir', './test/test-includes', '--preprocessor', './test/preprocessor/spec.js', '--reporter-keys', 'attrs,result,rawResult', './test/collateral-preprocessor/test/spread-sngl-obj-ident.js']],
24-
[['--includesDir', './test/test-includes', '--preprocessor', './test/preprocessor/autofail.js', '--reporter-keys', 'attrs,result,rawResult', './test/collateral-preprocessor/test/autofail.js']],
8+
[
9+
[
10+
'test/**/*.js',
11+
],
12+
{ cwd: 'test/collateral-with-harness/test262' },
13+
],
14+
[
15+
[
16+
'--test262Dir', './test/collateral-with-harness/test262',
17+
'./test/collateral-with-harness/test262/test/**/*.js',
18+
],
19+
],
20+
[
21+
[
22+
'--test262Dir', './test/collateral-with-harness/test262',
23+
'./test/collateral-with-harness/test262/test/**/*.js',
24+
'./test/collateral-with-harness/loose-tests/*',
25+
],
26+
],
27+
[
28+
[
29+
'--test262Dir', './collateral-with-harness/test262',
30+
'collateral-with-harness/test262/test/**/*.js',
31+
],
32+
{ cwd: 'test' },
33+
],
34+
[
35+
[
36+
'--includesDir', './test/test-includes',
37+
'./test/collateral/test/**/*.js',
38+
],
39+
],
40+
[
41+
[
42+
'test/collateral-with-harness/test262/test/**/*.js',
43+
],
44+
],
45+
[
46+
[
47+
'--includesDir', './test-includes',
48+
'collateral/test/**/*.js',
49+
],
50+
{ cwd: 'test' },
51+
],
52+
[
53+
[
54+
'collateral-with-harness/test262/test/**/*.js',
55+
],
56+
{ cwd: 'test' },
57+
],
58+
[
59+
[
60+
'--includesDir', './test/test-includes',
61+
'--prelude', './test/fixtures/prelude-a.js',
62+
'--prelude', './test/fixtures/prelude-b.js',
63+
'./test/collateral/test/bothStrict.js',
64+
],
65+
{ prelude: true },
66+
],
67+
[
68+
[
69+
'--includesDir', './test/test-includes',
70+
'--reporter-keys', 'attrs,result',
71+
'./test/collateral/test/bothStrict.js',
72+
],
73+
{ noRawResult: true },
74+
],
75+
[
76+
[
77+
'--includesDir', './test/test-includes',
78+
'--reporter-keys', 'rawResult,attrs,result',
79+
'./test/collateral/test/bothStrict.js',
80+
],
81+
],
82+
[
83+
[
84+
'--includesDir', './test/test-includes',
85+
'--reporter-keys', 'attrs,rawResult,result',
86+
'./test/collateral/test/bothStrict.js',
87+
],
88+
],
89+
[
90+
[
91+
'--includesDir', './test/test-includes',
92+
'--reporter-keys', 'attrs,result,rawResult',
93+
'./test/collateral/test/bothStrict.js',
94+
],
95+
],
96+
[
97+
[
98+
'--includesDir', './test/test-includes',
99+
'--transformer', './test/transformer/spec.js',
100+
'--reporter-keys', 'attrs,result,rawResult',
101+
'./test/babel-collateral/test/spread-sngl-obj-ident.js',
102+
],
103+
],
104+
[
105+
[
106+
'--includesDir', './test/test-includes',
107+
'--preprocessor', './test/preprocessor/spec.js',
108+
'--reporter-keys', 'attrs,result,rawResult',
109+
'./test/collateral-preprocessor/test/spread-sngl-obj-ident.js',
110+
]
111+
],
112+
[
113+
[
114+
'--includesDir', './test/test-includes',
115+
'--preprocessor', './test/preprocessor/autofail.js',
116+
'--reporter-keys', 'attrs,result,rawResult',
117+
'./test/collateral-preprocessor/test/autofail.js',
118+
]
119+
],
25120
].reduce((accum, a) => {
26121
let b = a.slice();
27122

@@ -38,9 +133,8 @@ const tests = [
38133
return accum;
39134
}, []);
40135

41-
42-
43-
Promise.all(tests.map(args => run(...args).then(validate)))
136+
Promise.all(tests.map(args => run(...args)))
137+
.then(outcomes => outcomes.map(outcome => validate(outcome)))
44138
.catch(reportRunError);
45139

46140
function reportRunError(error) {
@@ -50,8 +144,10 @@ function reportRunError(error) {
50144
}
51145

52146
function validate({ args, records, options = { prelude: false } }) {
147+
53148
if (options.reporter === 'json') {
54149
records.forEach(record => {
150+
55151
const description = options.prelude ?
56152
`${record.attrs.description} with prelude` :
57153
record.attrs.description;
@@ -66,22 +162,29 @@ function validate({ args, records, options = { prelude: false } }) {
66162
}
67163
}
68164

69-
assert.notEqual(record.attrs.expected, undefined, 'Test has an "expected" frontmatter');
165+
assert.notEqual(record.attrs.expected, undefined,
166+
'Test has an "expected" frontmatter');
167+
70168
if (!record.attrs.expected) {
71169
// can't do anything else
72170
assert.end();
73171
return;
74172
}
75173

76-
assert.equal(record.result.pass, record.attrs.expected.pass, 'Test passes or fails as expected');
174+
assert.equal(record.result.pass, record.attrs.expected.pass,
175+
'Test passes or fails as expected');
77176

78177
if (record.attrs.expected.message) {
79-
assert.equal(record.result.message, record.attrs.expected.message, 'Test fails with appropriate message');
178+
assert.equal(record.result.message, record.attrs.expected.message,
179+
'Test fails with appropriate message');
80180
}
81181

82182
if (options.prelude) {
83-
assert.ok(record.rawResult.stdout.includes('prelude a!'), 'Has prelude-a content');
84-
assert.ok(record.rawResult.stdout.includes('prelude b!'), 'Has prelude-b content');
183+
assert.ok(record.rawResult.stdout.includes('prelude a!'),
184+
'Has prelude-a content');
185+
186+
assert.ok(record.rawResult.stdout.includes('prelude b!'),
187+
'Has prelude-b content');
85188
}
86189

87190
if (options.noRawResult) {
@@ -104,7 +207,7 @@ function validate({ args, records, options = { prelude: false } }) {
104207
const fail = stdouts.filter(out => out.startsWith('FAIL')).length;
105208
const [report, passed, failed] = captured;
106209

107-
assert.equal(report, `Ran ${pass + fail} tests`);
210+
assert.equal(report.trim(), `Ran ${pass + fail} tests`);
108211
assert.equal(passed, `${pass} passed`);
109212
assert.equal(failed, `${fail} failed`);
110213
assert.end();

test/transformer/spec.js

+1-14
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,3 @@
1-
const babel = require("@babel/core");
2-
const options = {
3-
cwd: __dirname,
4-
presets: [
5-
[
6-
"@babel/preset-env",
7-
{
8-
spec: true
9-
}
10-
]
11-
]
12-
};
13-
141
module.exports = function(code) {
15-
return babel.transform(code, options).code;
2+
return code;
163
};

test/util/run.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,23 @@ module.exports = function run(extraArgs, options) {
1010
let args = [
1111
'--hostType', 'node',
1212
'--hostPath', process.execPath,
13-
'--timeout', '2000',
1413
...[ '-r', options.reporter ],
1514
].concat(extraArgs);
1615

1716
const cwd = options && options.cwd;
18-
const child = cp.fork(binPath, args, { cwd, silent: true });
17+
const child = cp.spawn(binPath, args, { cwd, silent: true });
1918

2019
child.stdout.on('data', data => { stdout += data });
2120
child.stderr.on('data', data => { stderr += data });
22-
child.on('exit', () => {
21+
child.on('close', () => {
2322
if (stderr) {
2423
return reject(new Error(`Got stderr: ${stderr.toString()}`));
2524
}
2625

2726
try {
27+
2828
let records = options.reporter === 'json' ?
29-
JSON.parse(stdout) :
29+
JSON.parse(stdout.trim()) :
3030
stdout.trim().split('\n');
3131

3232
resolve({
@@ -35,7 +35,7 @@ module.exports = function run(extraArgs, options) {
3535
records,
3636
});
3737
} catch(e) {
38-
reject(e);
38+
reject(new Error(`Got stderr: ${e.toString()}`));
3939
}
4040
});
4141
});

0 commit comments

Comments
 (0)