From 2742f3869a540b01ed51ca91075af9215c13bd54 Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Sat, 17 Nov 2018 05:30:06 +0800 Subject: [PATCH] test: use Worker scope in WPT Previously, we use the Window scope by default in our WPT test runner. When one of the test fails, the WPT harness would try to use document.getElementsByTagName() etc. to display the failure, which is not going to work for us. This patch switches the scope to DedicatedWorker and use our Worker implementation as a global - this does not test the Worker implementation per se, just tells the WPT harness to pass the results back to us via the callbacks we installed and not try to access a document. We may still need to use a Window scope when we try to run .window.js tests in the future, but for now we only run .any.js tests so it's fine to use a worker scope by default. PR-URL: https://github.com/nodejs/node/pull/24410 Reviewed-By: Gus Caplan Reviewed-By: Anna Henningsen --- test/common/wpt.js | 4 +++- test/wpt/test-whatwg-console.js | 2 +- test/wpt/test-whatwg-url.js | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/test/common/wpt.js b/test/common/wpt.js index 59dbe26d2abdcb..4f2f39c8e595d2 100644 --- a/test/common/wpt.js +++ b/test/common/wpt.js @@ -280,7 +280,9 @@ class WPTRunner { sandbox.self = sandbox; // TODO(joyeecheung): we are not a window - work with the upstream to // add a new scope for us. - sandbox.document = {}; // Pretend we are Window + + const { Worker } = require('worker_threads'); + sandbox.DedicatedWorker = Worker; // Pretend we are a Worker return context; } diff --git a/test/wpt/test-whatwg-console.js b/test/wpt/test-whatwg-console.js index 7b23fe8d3e619d..15fb80fc962a63 100644 --- a/test/wpt/test-whatwg-console.js +++ b/test/wpt/test-whatwg-console.js @@ -1,6 +1,6 @@ 'use strict'; -// Flags: --expose-internals +// Flags: --expose-internals --experimental-worker require('../common'); const { WPTRunner } = require('../common/wpt'); diff --git a/test/wpt/test-whatwg-url.js b/test/wpt/test-whatwg-url.js index 8734452940e84e..fbbea2453203c3 100644 --- a/test/wpt/test-whatwg-url.js +++ b/test/wpt/test-whatwg-url.js @@ -1,6 +1,6 @@ 'use strict'; -// Flags: --expose-internals +// Flags: --expose-internals --experimental-worker require('../common'); const { WPTRunner } = require('../common/wpt');