Skip to content

Commit

Permalink
Add tests, fix a few bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
bterlson committed Jul 12, 2016
1 parent 0501e94 commit b07680b
Show file tree
Hide file tree
Showing 51 changed files with 3,418 additions and 281 deletions.
11 changes: 9 additions & 2 deletions bin/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,19 @@ const argv = require('../lib/cli.js').argv;
const validator = require('../lib/validator.js');
const Rx = require('rx');
const util = require('util');
const simpleReporter = require('../lib/reporters/simple.js');
const resultsEmitter = require('../lib/resultsEmitter.js');
const agentPool = require('../lib/agentPool.js');
const test262Finder = require('../lib/findTest262.js');
const scenariosForTest = require('../lib/scenarios.js');

let reporter;
if (fs.existsSync('lib/reporters/' + argv.reporter + '.js')) {
reporter = require('../lib/reporters/' + argv.reporter + '.js');
} else {
console.error(`Reporter ${argv.reporter} not found.`);
process.exit(1);
}

let includesDir = argv.includesDir;
let test262Dir = argv.test262Dir;

Expand All @@ -34,7 +41,7 @@ const results = rawResults.map(function (test) {
return test;
});
const resultEmitter = resultsEmitter(results);
simpleReporter(resultEmitter);
reporter(resultEmitter);

function printVersion() {
var p = require(path.resolve(__dirname, "..", "package.json"));
Expand Down
2 changes: 1 addition & 1 deletion lib/agentPool.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function makePool(agents, hostType, hostArgs, hostPath) {
pool.runTest = function (record) {
const agent = record[0];
const test = record[1];
return agent.evalScript(test.contents)
return agent.evalScript(test.contents, { async: true })
.then(result => {
pool.onNext(agent);
test.rawResult = result;
Expand Down
3 changes: 2 additions & 1 deletion lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ const yargv = yargs
.nargs('threads', 1)
.default('threads', 1)
.alias('threads', 't')
.describe('reporter', 'select a reporter to use (simple, json, or tap)')
.describe('reporter', 'select a reporter to use (simple or json)')
.nargs('reporter', 1)
.alias('reporter', 'r')
.default('reporter', 'simple')
.help('help')
.alias('help', 'h')
.example('test262-harness path/to/test.js')
Expand Down
25 changes: 25 additions & 0 deletions lib/reporters/json.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
'use strict';

function jsonReporter(results) {
let started = false;

results.on('start', function () {
console.log('[');
});

results.on('end', function () {
console.log(']');
});

results.on('test end', function (test) {
if (started) {
process.stdout.write(',');
} else {
started = true;
}

console.log(JSON.stringify(test));
});
}

module.exports = jsonReporter;
7 changes: 6 additions & 1 deletion lib/resultsEmitter.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,15 @@
const EventEmitter = require('events');

function resultsEmitter(results) {
let started = false;
const emitter = new EventEmitter();
emitter.emit('start');
results.forEach(
function (test) {
if (!started) {
emitter.emit('start');
started = true;
}

emitter.emit('test end', test);

if (test.result.pass) {
Expand Down
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@
"test": "node_modules/.bin/tape test/test.js"
},
"dependencies": {
"async": "^2.0.0-rc.6",
"eshost": "^3.0.0",
"glob": "~4.0.3",
"glob": "^7.0.5",
"rx": "^4.1.0",
"test262-compiler": "^1.0.0",
"yargs": "^4.7.1"
Expand All @@ -28,6 +27,6 @@
],
"devDependencies": {
"rimraf": "^2.5.3",
"tape": "^3.0.3"
"tape": "^3.6.1"
}
}
11 changes: 7 additions & 4 deletions test/collateral/async.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
/*---
description: Async test
note: Will only work in hosts with setTimeout...
expected:
pass: true
---*/

process.nextTick(function() {
$DONE()
})
var p = new Promise(function(resolve) {
resolve();
});

p.then($DONE, $DONE);
2 changes: 2 additions & 0 deletions test/collateral/asyncNegative.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/*---
description: Async test
negative: RangeError
expected:
pass: true
---*/

process.nextTick(function() {
Expand Down
2 changes: 2 additions & 0 deletions test/collateral/bothStrict.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/*---
description: Should test in both modes
negative: ReferenceError
expected:
pass: true
---*/
var strict;
try { x = 1; strict = false;} catch(e) { strict = true }
Expand Down
3 changes: 3 additions & 0 deletions test/collateral/error.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
/*---
description: Fails by calling $ERROR
expected:
pass: false
message: failure message
---*/

$ERROR('failure message');
2 changes: 2 additions & 0 deletions test/collateral/negativeMessage.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
/*---
description: Should report the expected error indicated by the "negative" frontmatter
negative: ExpectedError
expected:
pass: false
---*/
2 changes: 2 additions & 0 deletions test/collateral/noStrict.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/*---
description: Should not test in strict mode
flags: [noStrict]
expected:
pass: true
---*/
x = 5;
2 changes: 2 additions & 0 deletions test/collateral/rawNoStrict.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/*---
description: Should not test in strict mode
flags: [raw]
expected:
pass: true
---*/
var seemsStrict;
try {
Expand Down
2 changes: 2 additions & 0 deletions test/collateral/rawStrict.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/*---
description: Should not test in strict mode
flags: [raw]
expected:
pass: true
---*/
'use strict';
var seemsStrict;
Expand Down
2 changes: 2 additions & 0 deletions test/collateral/strict.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
description: Should not test in sloppy mode
flags: [onlyStrict]
negative: ReferenceError
expected:
pass: true
---*/
x = 5;
$ERROR('Not in strict mode');
3 changes: 3 additions & 0 deletions test/collateral/thrownError.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
/*---
description: Fails by throwing an error
expected:
pass: false
message: "Expected no error, got Error: failure message"
---*/

function foo() {
Expand Down
6 changes: 0 additions & 6 deletions test/excludeConfig.js

This file was deleted.

35 changes: 0 additions & 35 deletions test/expected.js

This file was deleted.

7 changes: 0 additions & 7 deletions test/nodeConfig.js

This file was deleted.

83 changes: 83 additions & 0 deletions test/test-includes/Date_constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
//Date_constants.js
// Copyright 2009 the Sputnik authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

var HoursPerDay = 24;
var MinutesPerHour = 60;
var SecondsPerMinute = 60;

var msPerDay = 86400000;
var msPerSecond = 1000;
var msPerMinute = 60000;
var msPerHour = 3600000;

var date_1899_end = -2208988800001;
var date_1900_start = -2208988800000;
var date_1969_end = -1;
var date_1970_start = 0;
var date_1999_end = 946684799999;
var date_2000_start = 946684800000;
var date_2099_end = 4102444799999;
var date_2100_start = 4102444800000;

// Copyright 2009 the Sputnik authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

//the following values are normally generated by the sputnik.py driver
var $LocalTZ,
$DST_start_month,
$DST_start_sunday,
$DST_start_hour,
$DST_start_minutes,
$DST_end_month,
$DST_end_sunday,
$DST_end_hour,
$DST_end_minutes;

(function () {
/**
* Finds the first date, starting from |start|, where |predicate|
* holds.
*/
var findNearestDateBefore = function(start, predicate) {
var current = start;
var month = 1000 * 60 * 60 * 24 * 30;
for (var step = month; step > 0; step = Math.floor(step / 3)) {
if (!predicate(current)) {
while (!predicate(current))
current = new Date(current.getTime() + step);
current = new Date(current.getTime() - step);
}
}
while (!predicate(current)) {
current = new Date(current.getTime() + 1);
}
return current;
};

var juneDate = new Date(2000, 5, 20, 0, 0, 0, 0);
var decemberDate = new Date(2000, 11, 20, 0, 0, 0, 0);
var juneOffset = juneDate.getTimezoneOffset();
var decemberOffset = decemberDate.getTimezoneOffset();
var isSouthernHemisphere = (juneOffset > decemberOffset);
var winterTime = isSouthernHemisphere ? juneDate : decemberDate;
var summerTime = isSouthernHemisphere ? decemberDate : juneDate;

var dstStart = findNearestDateBefore(winterTime, function (date) {
return date.getTimezoneOffset() == summerTime.getTimezoneOffset();
});
$DST_start_month = dstStart.getMonth();
$DST_start_sunday = dstStart.getDate() > 15 ? '"last"' : '"first"';
$DST_start_hour = dstStart.getHours();
$DST_start_minutes = dstStart.getMinutes();

var dstEnd = findNearestDateBefore(summerTime, function (date) {
return date.getTimezoneOffset() == winterTime.getTimezoneOffset();
});
$DST_end_month = dstEnd.getMonth();
$DST_end_sunday = dstEnd.getDate() > 15 ? '"last"' : '"first"';
$DST_end_hour = dstEnd.getHours();
$DST_end_minutes = dstEnd.getMinutes();

return;
})();
Loading

0 comments on commit b07680b

Please sign in to comment.