Skip to content

Commit

Permalink
Test Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
rwaldron committed Mar 30, 2019
1 parent 0f851ca commit 3f2e039
Show file tree
Hide file tree
Showing 9 changed files with 426 additions and 1,086 deletions.
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
---
os:
- osx
- linux
language: node_js
node_js:
- 10
- 11
dist: trusty
sudo: false
install: npm install
script: npm test
2 changes: 1 addition & 1 deletion bin/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ let transform;
let preprocessor;

if (argv.transformer || argv.transform) {
transform = require(argv.transformer || argv.transform);
transform = require(path.join(process.cwd(), argv.transformer || argv.transform));
}

if (argv.preprocessor) {
Expand Down
1,274 changes: 284 additions & 990 deletions package-lock.json

Large diffs are not rendered by default.

5 changes: 1 addition & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@
"test262-harness": "bin/run.js"
},
"scripts": {
"test": "node_modules/.bin/tap test/*.js"
"test": "node_modules/.bin/tap --no-esm -T test/*.js"
},
"dependencies": {
"chalk": "^2.4.2",
"eshost": "^5.0.0",
"minimatch": "^3.0.4",
"rxjs": "^6.4.0",
Expand All @@ -27,8 +26,6 @@
"test"
],
"devDependencies": {
"@babel/core": "^7.4.0",
"@babel/preset-env": "^7.4.2",
"rimraf": "^2.6.3",
"tap": "^12.6.0"
}
Expand Down
22 changes: 2 additions & 20 deletions test/preprocessor/autofail.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,8 @@
const babel = require("@babel/core");
const options = {
cwd: __dirname,
presets: [
[
"@babel/preset-env",
{
spec: true
}
]
]
};

class Test262Fake extends Error {}

module.exports = function(test) {
test.result = {
stderr: 'This is a fake test.',
stderr: 'Test262Fake: This is a fake test.',
stdout: '',
error: {
name: 'Test262Error',
message: 'Test262Fake: This is a fake test.'
}
error: null
};

return test;
Expand Down
23 changes: 0 additions & 23 deletions test/preprocessor/spec.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,3 @@
const babel = require("@babel/core");
const options = {
cwd: __dirname,
presets: [
[
"@babel/preset-env",
{
spec: true
}
]
]
};

module.exports = function(test) {
try {
test.contents = babel.transform(test.contents, options).code;
} catch (error) {
test.result = {
stderr: error.toString(),
stdout: '',
error: null
};
}

return test;
};
155 changes: 129 additions & 26 deletions test/test.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,122 @@
'use strict';

const parseFile = require('test262-parser').parseFile;
const run = require('./util/run');
const tap = require('tap');
const path = require('path');

const tests = [
[['test/**/*.js'], { cwd: 'test/collateral-with-harness/test262' }],
[['--test262Dir', './test/collateral-with-harness/test262', './test/collateral-with-harness/test262/test/**/*.js']],
[['--test262Dir', './test/collateral-with-harness/test262', './test/collateral-with-harness/test262/test/**/*.js', './test/collateral-with-harness/loose-tests/*']],
[['--test262Dir', './collateral-with-harness/test262', 'collateral-with-harness/test262/test/**/*.js'], { cwd: 'test' }],
[['--includesDir', './test/test-includes', './test/collateral/test/**/*.js']],
[['test/collateral-with-harness/test262/test/**/*.js']],
[['--includesDir', './test-includes', 'collateral/test/**/*.js'], { cwd: 'test' }],
[['collateral-with-harness/test262/test/**/*.js'], { cwd: 'test' }],
[['--includesDir', './test/test-includes', '--prelude', './test/fixtures/prelude-a.js', '--prelude', './test/fixtures/prelude-b.js', './test/collateral/test/bothStrict.js'], { prelude: true }],
[['--includesDir', './test/test-includes', '--reporter-keys', 'attrs,result', './test/collateral/test/bothStrict.js'], { noRawResult: true }],
[['--includesDir', './test/test-includes', '--reporter-keys', 'rawResult,attrs,result', './test/collateral/test/bothStrict.js']],
[['--includesDir', './test/test-includes', '--reporter-keys', 'attrs,rawResult,result', './test/collateral/test/bothStrict.js']],
[['--includesDir', './test/test-includes', '--reporter-keys', 'attrs,result,rawResult', './test/collateral/test/bothStrict.js']],
[['--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']],
[['--includesDir', './test/test-includes', '--preprocessor', './test/preprocessor/spec.js', '--reporter-keys', 'attrs,result,rawResult', './test/collateral-preprocessor/test/spread-sngl-obj-ident.js']],
[['--includesDir', './test/test-includes', '--preprocessor', './test/preprocessor/autofail.js', '--reporter-keys', 'attrs,result,rawResult', './test/collateral-preprocessor/test/autofail.js']],
[
[
'test/**/*.js',
],
{ cwd: 'test/collateral-with-harness/test262' },
],
[
[
'--test262Dir', './test/collateral-with-harness/test262',
'./test/collateral-with-harness/test262/test/**/*.js',
],
],
[
[
'--test262Dir', './test/collateral-with-harness/test262',
'./test/collateral-with-harness/test262/test/**/*.js',
'./test/collateral-with-harness/loose-tests/*',
],
],
[
[
'--test262Dir', './collateral-with-harness/test262',
'collateral-with-harness/test262/test/**/*.js',
],
{ cwd: 'test' },
],
[
[
'--includesDir', './test/test-includes',
'./test/collateral/test/**/*.js',
],
],
[
[
'test/collateral-with-harness/test262/test/**/*.js',
],
],
[
[
'--includesDir', './test-includes',
'collateral/test/**/*.js',
],
{ cwd: 'test' },
],
[
[
'collateral-with-harness/test262/test/**/*.js',
],
{ cwd: 'test' },
],
[
[
'--includesDir', './test/test-includes',
'--prelude', './test/fixtures/prelude-a.js',
'--prelude', './test/fixtures/prelude-b.js',
'./test/collateral/test/bothStrict.js',
],
{ prelude: true },
],
[
[
'--includesDir', './test/test-includes',
'--reporter-keys', 'attrs,result',
'./test/collateral/test/bothStrict.js',
],
{ noRawResult: true },
],
[
[
'--includesDir', './test/test-includes',
'--reporter-keys', 'rawResult,attrs,result',
'./test/collateral/test/bothStrict.js',
],
],
[
[
'--includesDir', './test/test-includes',
'--reporter-keys', 'attrs,rawResult,result',
'./test/collateral/test/bothStrict.js',
],
],
[
[
'--includesDir', './test/test-includes',
'--reporter-keys', 'attrs,result,rawResult',
'./test/collateral/test/bothStrict.js',
],
],
[
[
'--includesDir', './test/test-includes',
'--transformer', './test/transformer/spec.js',
'--reporter-keys', 'attrs,result,rawResult',
'./test/babel-collateral/test/spread-sngl-obj-ident.js',
],
],
[
[
'--includesDir', './test/test-includes',
'--preprocessor', './test/preprocessor/spec.js',
'--reporter-keys', 'attrs,result,rawResult',
'./test/collateral-preprocessor/test/spread-sngl-obj-ident.js',
]
],
[
[
'--includesDir', './test/test-includes',
'--preprocessor', './test/preprocessor/autofail.js',
'--reporter-keys', 'attrs,result,rawResult',
'./test/collateral-preprocessor/test/autofail.js',
]
],
].reduce((accum, a) => {
let b = a.slice();

Expand All @@ -38,9 +133,8 @@ const tests = [
return accum;
}, []);



Promise.all(tests.map(args => run(...args).then(validate)))
Promise.all(tests.map(args => run(...args)))
.then(outcomes => outcomes.map(outcome => validate(outcome)))
.catch(reportRunError);

function reportRunError(error) {
Expand All @@ -50,8 +144,10 @@ function reportRunError(error) {
}

function validate({ args, records, options = { prelude: false } }) {

if (options.reporter === 'json') {
records.forEach(record => {

const description = options.prelude ?
`${record.attrs.description} with prelude` :
record.attrs.description;
Expand All @@ -66,22 +162,29 @@ function validate({ args, records, options = { prelude: false } }) {
}
}

assert.notEqual(record.attrs.expected, undefined, 'Test has an "expected" frontmatter');
assert.notEqual(record.attrs.expected, undefined,
'Test has an "expected" frontmatter');

if (!record.attrs.expected) {
// can't do anything else
assert.end();
return;
}

assert.equal(record.result.pass, record.attrs.expected.pass, 'Test passes or fails as expected');
assert.equal(record.result.pass, record.attrs.expected.pass,
'Test passes or fails as expected');

if (record.attrs.expected.message) {
assert.equal(record.result.message, record.attrs.expected.message, 'Test fails with appropriate message');
assert.equal(record.result.message, record.attrs.expected.message,
'Test fails with appropriate message');
}

if (options.prelude) {
assert.ok(record.rawResult.stdout.includes('prelude a!'), 'Has prelude-a content');
assert.ok(record.rawResult.stdout.includes('prelude b!'), 'Has prelude-b content');
assert.ok(record.rawResult.stdout.includes('prelude a!'),
'Has prelude-a content');

assert.ok(record.rawResult.stdout.includes('prelude b!'),
'Has prelude-b content');
}

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

assert.equal(report, `Ran ${pass + fail} tests`);
assert.equal(report.trim(), `Ran ${pass + fail} tests`);
assert.equal(passed, `${pass} passed`);
assert.equal(failed, `${fail} failed`);
assert.end();
Expand Down
15 changes: 1 addition & 14 deletions test/transformer/spec.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,3 @@
const babel = require("@babel/core");
const options = {
cwd: __dirname,
presets: [
[
"@babel/preset-env",
{
spec: true
}
]
]
};

module.exports = function(code) {
return babel.transform(code, options).code;
return code;
};
10 changes: 5 additions & 5 deletions test/util/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,23 @@ module.exports = function run(extraArgs, options) {
let args = [
'--hostType', 'node',
'--hostPath', process.execPath,
'--timeout', '2000',
...[ '-r', options.reporter ],
].concat(extraArgs);

const cwd = options && options.cwd;
const child = cp.fork(binPath, args, { cwd, silent: true });
const child = cp.spawn(binPath, args, { cwd, silent: true });

child.stdout.on('data', data => { stdout += data });
child.stderr.on('data', data => { stderr += data });
child.on('exit', () => {
child.on('close', () => {
if (stderr) {
return reject(new Error(`Got stderr: ${stderr.toString()}`));
}

try {

let records = options.reporter === 'json' ?
JSON.parse(stdout) :
JSON.parse(stdout.trim()) :
stdout.trim().split('\n');

resolve({
Expand All @@ -35,7 +35,7 @@ module.exports = function run(extraArgs, options) {
records,
});
} catch(e) {
reject(e);
reject(new Error(`Got stderr: ${e.toString()}`));
}
});
});
Expand Down

0 comments on commit 3f2e039

Please sign in to comment.