Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Meta: fix realm issues in reference implementation testing setup #957

Merged
merged 1 commit into from
Oct 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions reference-implementation/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,20 @@
"root": true,
"env": {
"node": true,
"browser": true,
"es6": true
},
"parserOptions": {
"ecmaVersion": 6
"ecmaVersion": 2018
},
"globals": {
"ReadableStream": false,
"WritableStream": false,
"TransformStream": false,
"ByteLengthQueuingStrategy": false,
"CountQueuingStrategy": false,
"GCController": false
"GCController": false,
"gc": false
},
"rules": {
// Possible errors
Expand Down
16 changes: 16 additions & 0 deletions reference-implementation/lib/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
'use strict';
// This file is used as the entry point for browserifying the reference implementation to allow it
// to run inside the wpt-runner "browser like" context.

const { ReadableStream } = require('./readable-stream.js');
const { WritableStream } = require('./writable-stream.js');
const { TransformStream } = require('./transform-stream.js');
const ByteLengthQueuingStrategy = require('./byte-length-queuing-strategy.js');
const CountQueuingStrategy = require('./count-queuing-strategy.js');

window.ReadableStream = ReadableStream;
window.WritableStream = WritableStream;
window.TransformStream = TransformStream;
window.ByteLengthQueuingStrategy = ByteLengthQueuingStrategy;
window.CountQueuingStrategy = CountQueuingStrategy;
window.gc = gc;
7 changes: 4 additions & 3 deletions reference-implementation/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@
"license": "(CC0-1.0 OR MIT)",
"devDependencies": {
"better-assert": "^1.0.2",
"debug": "^3.1.0",
"browserify": "^16.2.3",
"debug": "^4.1.0",
"eslint": "^3.2.2",
"minimatch": "^3.0.4",
"nyc": "^11.2.1",
"opener": "^1.4.2",
"nyc": "^13.0.1",
"opener": "^1.5.1",
"wpt-runner": "^2.2.0"
},
"nyc": {
Expand Down
79 changes: 40 additions & 39 deletions reference-implementation/run-web-platform-tests.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,13 @@
// This runs the web platform tests against the reference implementation, in Node.js using jsdom, for easier rapid
// development of the reference implementation and the web platform tests.
/* eslint-disable no-console*/
/* eslint-disable no-console */
'use strict';
const path = require('path');
const { promisify } = require('util');
const browserify = require('browserify');
const wptRunner = require('wpt-runner');
const minimatch = require('minimatch');

const { ReadableStream } = require('./lib/readable-stream.js');
const { WritableStream } = require('./lib/writable-stream.js');
const { TransformStream } = require('./lib/transform-stream.js');
const ByteLengthQueuingStrategy = require('./lib/byte-length-queuing-strategy.js');
const CountQueuingStrategy = require('./lib/count-queuing-strategy.js');

const testsPath = path.resolve(__dirname, 'web-platform-tests/streams');

const filterGlobs = process.argv.length >= 3 ? process.argv.slice(2) : ['**/*.html'];
const workerTestPattern = /\.(?:dedicated|shared|service)worker(?:\.https)?\.html$/;
function filter(testPath) {
return !workerTestPattern.test(testPath) && // ignore the worker versions
filterGlobs.some(glob => minimatch(testPath, glob));
}

// wpt-runner does not yet support unhandled rejection tracking a la
// https://github.com/w3c/testharness.js/commit/7716e2581a86dfd9405a9c00547a7504f0c7fe94
// So we emulate it with Node.js events
Expand All @@ -33,32 +20,46 @@ process.on('rejectionHandled', promise => {
rejections.delete(promise);
});

wptRunner(testsPath, { rootURL: 'streams/', setup, filter })
.then(failures => {
process.exitCode = failures;
main().catch(e => {
console.error(e.stack);
process.exitCode = 1;
});

async function main() {
const entryPath = path.resolve(__dirname, 'lib/index.js');
const testsPath = path.resolve(__dirname, 'web-platform-tests/streams');

const filterGlobs = process.argv.length >= 3 ? process.argv.slice(2) : ['**/*.html'];
const workerTestPattern = /\.(?:dedicated|shared|service)worker(?:\.https)?\.html$/;

const bundledJS = await bundle(entryPath);

if (rejections.size > 0) {
if (failures === 0) {
process.exitCode = 1;
}
const failures = await wptRunner(testsPath, {
rootURL: 'streams/',
setup(window) {
window.eval(bundledJS);
},
filter(testPath) {
return !workerTestPattern.test(testPath) && // ignore the worker versions
filterGlobs.some(glob => minimatch(testPath, glob));
}
});

for (const reason of rejections.values()) {
console.error('Unhandled promise rejection: ', reason.stack);
}
}
})
.catch(e => {
console.error(e.stack);
process.exitCode = failures;

if (rejections.size > 0) {
if (failures === 0) {
process.exitCode = 1;
});
}

function setup(window) {
// Necessary so that we can send test-realm promises to the jsdom-realm implementation without causing assimilation.
window.Promise = Promise;
for (const reason of rejections.values()) {
console.error('Unhandled promise rejection: ', reason.stack);
}
}
}

window.ReadableStream = ReadableStream;
window.WritableStream = WritableStream;
window.TransformStream = TransformStream;
window.ByteLengthQueuingStrategy = ByteLengthQueuingStrategy;
window.CountQueuingStrategy = CountQueuingStrategy;
async function bundle(entryPath) {
const b = browserify([entryPath]);
const buffer = await promisify(b.bundle.bind(b))();
return buffer.toString();
}