Skip to content

Commit b07680b

Browse files
committed
Add tests, fix a few bugs
1 parent 0501e94 commit b07680b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+3418
-281
lines changed

bin/run.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,19 @@ const argv = require('../lib/cli.js').argv;
99
const validator = require('../lib/validator.js');
1010
const Rx = require('rx');
1111
const util = require('util');
12-
const simpleReporter = require('../lib/reporters/simple.js');
1312
const resultsEmitter = require('../lib/resultsEmitter.js');
1413
const agentPool = require('../lib/agentPool.js');
1514
const test262Finder = require('../lib/findTest262.js');
1615
const scenariosForTest = require('../lib/scenarios.js');
1716

17+
let reporter;
18+
if (fs.existsSync('lib/reporters/' + argv.reporter + '.js')) {
19+
reporter = require('../lib/reporters/' + argv.reporter + '.js');
20+
} else {
21+
console.error(`Reporter ${argv.reporter} not found.`);
22+
process.exit(1);
23+
}
24+
1825
let includesDir = argv.includesDir;
1926
let test262Dir = argv.test262Dir;
2027

@@ -34,7 +41,7 @@ const results = rawResults.map(function (test) {
3441
return test;
3542
});
3643
const resultEmitter = resultsEmitter(results);
37-
simpleReporter(resultEmitter);
44+
reporter(resultEmitter);
3845

3946
function printVersion() {
4047
var p = require(path.resolve(__dirname, "..", "package.json"));

lib/agentPool.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ function makePool(agents, hostType, hostArgs, hostPath) {
2424
pool.runTest = function (record) {
2525
const agent = record[0];
2626
const test = record[1];
27-
return agent.evalScript(test.contents)
27+
return agent.evalScript(test.contents, { async: true })
2828
.then(result => {
2929
pool.onNext(agent);
3030
test.rawResult = result;

lib/cli.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@ const yargv = yargs
1111
.nargs('threads', 1)
1212
.default('threads', 1)
1313
.alias('threads', 't')
14-
.describe('reporter', 'select a reporter to use (simple, json, or tap)')
14+
.describe('reporter', 'select a reporter to use (simple or json)')
1515
.nargs('reporter', 1)
1616
.alias('reporter', 'r')
17+
.default('reporter', 'simple')
1718
.help('help')
1819
.alias('help', 'h')
1920
.example('test262-harness path/to/test.js')

lib/reporters/json.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
'use strict';
2+
3+
function jsonReporter(results) {
4+
let started = false;
5+
6+
results.on('start', function () {
7+
console.log('[');
8+
});
9+
10+
results.on('end', function () {
11+
console.log(']');
12+
});
13+
14+
results.on('test end', function (test) {
15+
if (started) {
16+
process.stdout.write(',');
17+
} else {
18+
started = true;
19+
}
20+
21+
console.log(JSON.stringify(test));
22+
});
23+
}
24+
25+
module.exports = jsonReporter;

lib/resultsEmitter.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,15 @@
33
const EventEmitter = require('events');
44

55
function resultsEmitter(results) {
6+
let started = false;
67
const emitter = new EventEmitter();
7-
emitter.emit('start');
88
results.forEach(
99
function (test) {
10+
if (!started) {
11+
emitter.emit('start');
12+
started = true;
13+
}
14+
1015
emitter.emit('test end', test);
1116

1217
if (test.result.pass) {

package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,8 @@
1111
"test": "node_modules/.bin/tape test/test.js"
1212
},
1313
"dependencies": {
14-
"async": "^2.0.0-rc.6",
1514
"eshost": "^3.0.0",
16-
"glob": "~4.0.3",
15+
"glob": "^7.0.5",
1716
"rx": "^4.1.0",
1817
"test262-compiler": "^1.0.0",
1918
"yargs": "^4.7.1"
@@ -28,6 +27,6 @@
2827
],
2928
"devDependencies": {
3029
"rimraf": "^2.5.3",
31-
"tape": "^3.0.3"
30+
"tape": "^3.6.1"
3231
}
3332
}

test/collateral/async.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
/*---
22
description: Async test
3-
note: Will only work in hosts with setTimeout...
3+
expected:
4+
pass: true
45
---*/
56

6-
process.nextTick(function() {
7-
$DONE()
8-
})
7+
var p = new Promise(function(resolve) {
8+
resolve();
9+
});
10+
11+
p.then($DONE, $DONE);

test/collateral/asyncNegative.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
/*---
22
description: Async test
33
negative: RangeError
4+
expected:
5+
pass: true
46
---*/
57

68
process.nextTick(function() {

test/collateral/bothStrict.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
/*---
22
description: Should test in both modes
33
negative: ReferenceError
4+
expected:
5+
pass: true
46
---*/
57
var strict;
68
try { x = 1; strict = false;} catch(e) { strict = true }

test/collateral/error.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
/*---
22
description: Fails by calling $ERROR
3+
expected:
4+
pass: false
5+
message: failure message
36
---*/
47

58
$ERROR('failure message');

0 commit comments

Comments
 (0)