Skip to content

Commit

Permalink
cleanup test-* files
Browse files Browse the repository at this point in the history
  • Loading branch information
panva committed Feb 21, 2023
1 parent ad4c29c commit 249efbf
Show file tree
Hide file tree
Showing 33 changed files with 89 additions and 126 deletions.
35 changes: 2 additions & 33 deletions test/common/wpt.js
Original file line number Diff line number Diff line change
Expand Up @@ -489,9 +489,7 @@ class WPTRunner {
pretendGlobalThisAs(name) {
switch (name) {
case 'Window': {
this.globalThisInitScripts.push(
`global.Window = Object.getPrototypeOf(globalThis).constructor;
self.GLOBAL.isWorker = () => false;`);
this.globalThisInitScripts.push('globalThis.Window = Object.getPrototypeOf(globalThis).constructor;');
this.loadLazyGlobals();
break;
}
Expand Down Expand Up @@ -531,39 +529,10 @@ class WPTRunner {
this.globalThisInitScripts.push(script);
}

brandCheckGlobalScopeAttribute(name) {
// TODO(legendecas): idlharness GlobalScope attribute receiver validation.
const script = `
const desc = Object.getOwnPropertyDescriptor(globalThis, '${name}');
function getter() {
// Mimic GlobalScope instance brand check.
if (this !== globalThis) {
throw new TypeError('Illegal invocation');
}
return desc.get();
}
Object.defineProperty(getter, 'name', { value: 'get ${name}' });
function setter(value) {
// Mimic GlobalScope instance brand check.
if (this !== globalThis) {
throw new TypeError('Illegal invocation');
}
desc.set(value);
}
Object.defineProperty(setter, 'name', { value: 'set ${name}' });
Object.defineProperty(globalThis, '${name}', {
get: getter,
set: setter,
});
`;
this.globalThisInitScripts.push(script);
}

// TODO(joyeecheung): work with the upstream to port more tests in .html
// to .js.
async runJsTests() {
this.pretendGlobalThisAs('Window');
let queue = [];

// If the tests are run as `node test/wpt/test-something.js subset.any.js`,
Expand Down
3 changes: 3 additions & 0 deletions test/wpt/.eslintrc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
rules:
node-core/required-modules: off
node-core/require-common-first: off
8 changes: 8 additions & 0 deletions test/wpt/status/FileAPI/blob.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"ArrayBuffer elements of the blobParts array should be supported.",
"Passing typed arrays as elements of the blobParts array should work.",
"Passing a Float64Array as element of the blobParts array should work.",
"Passing BigInt typed arrays as elements of the blobParts array should work.",
"Array with two blobs",
"Array with two buffers",
"Array with two bufferviews",
Expand All @@ -43,5 +44,12 @@
},
"Blob-slice.any.js": {
"skip": "Depends on File API"
},
"Blob-stream.any.js": {
"fail": {
"expected": [
"Reading Blob.stream() with BYOB reader"
]
}
}
}
3 changes: 0 additions & 3 deletions test/wpt/status/dom/events.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@
"event-global-set-before-handleEvent-lookup.window.js": {
"skip": "window is not defined"
},
"event-global.worker.js": {
"skip": "importScripts is not defined"
},
"legacy-pre-activation-behavior.window.js": {
"skip": "document is not defined"
},
Expand Down
3 changes: 3 additions & 0 deletions test/wpt/status/encoding.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@
"streams/realms.window.js": {
"skip": "window is not defined"
},
"streams/invalid-realm.window.js": {
"skip": "document is not defined"
},
"streams/decode-attributes.any.js": {
"requires": ["full-icu"]
},
Expand Down
7 changes: 7 additions & 0 deletions test/wpt/status/hr-time.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
{
"idlharness.any.js": {
"fail": {
"expected": [
"Window interface: attribute performance"
]
}
},
"window-worker-timeOrigin.window.js": {
"skip": "depends on URL.createObjectURL(blob)"
}
Expand Down
19 changes: 18 additions & 1 deletion test/wpt/status/html/webappapis/structured-clone.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,24 @@
{
"structured-clone.any.js": {
"fail": {
"expected": ["File basic"]
"expected": [
"File basic",
"Serializing a non-serializable platform object fails",
"A subclass instance will deserialize as its closest serializable superclass",
"Resizable ArrayBuffer",
"Growable SharedArrayBuffer",
"Length-tracking TypedArray",
"Length-tracking DataView",
"Serializing OOB TypedArray throws",
"Serializing OOB DataView throws",
"A detached ArrayBuffer cannot be transferred",
"Transferring a non-transferable platform object fails",
"Resizable ArrayBuffer is transferable",
"Length-tracking TypedArray is transferable",
"Length-tracking DataView is transferable",
"Transferring OOB TypedArray throws",
"Transferring OOB DataView throws"
]
}
}
}
3 changes: 3 additions & 0 deletions test/wpt/status/html/webappapis/timers.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
{
"evil-spec-example.any.js": {
"skip": "Node.js validates setTimeout arguments using its own validators, not WebIDL"
},
"negative-settimeout.any.js": {
"skip": "unreliable in Node.js; Refs: https://github.com/nodejs/node/issues/37672"
}
Expand Down
3 changes: 3 additions & 0 deletions test/wpt/status/performance-timeline.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
]
}
},
"droppedentriescount.any.js": {
"skip": "depends on relative-path fetch()"
},
"webtiming-resolution.any.js": {
"skip": "flaky"
}
Expand Down
11 changes: 11 additions & 0 deletions test/wpt/status/resource-timing.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
{
"idlharness.any.js": {
"fail": {
"expected": [
"PerformanceResourceTiming interface: attribute responseStatus",
"PerformanceResourceTiming interface: attribute renderBlockingStatus",
"PerformanceResourceTiming interface: resource must inherit property \"responseStatus\" with the proper type",
"PerformanceResourceTiming interface: resource must inherit property \"renderBlockingStatus\" with the proper type",
"PerformanceResourceTiming interface: default toJSON operation on resource"
]
}
},
"cors-preflight.any.js": {
"skip": "Browser-specific test"
},
Expand Down
8 changes: 8 additions & 0 deletions test/wpt/status/streams.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
{
"idlharness.any.js": {
"fail": {
"note": "enumerable expected true but got false",
"expected": [
"ReadableStream interface: async iterable<any>"
]
}
},
"queuing-strategies-size-function-per-global.window.js": {
"skip": "Browser-specific test"
},
Expand Down
9 changes: 1 addition & 8 deletions test/wpt/status/user-timing.json
Original file line number Diff line number Diff line change
@@ -1,8 +1 @@
{
"invoke_with_timing_attributes.worker.js": {
"skip": "importScripts not supported"
},
"performance-measure-invalid.worker.js": {
"skip": "importScripts not supported"
}
}
{}
10 changes: 9 additions & 1 deletion test/wpt/status/webidl/ecmascript-binding/es-exceptions.json
Original file line number Diff line number Diff line change
@@ -1 +1,9 @@
{}
{
"DOMException-constructor-and-prototype.any.js": {
"fail": {
"expected": [
"existence and property descriptor of DOMException"
]
}
}
}
2 changes: 1 addition & 1 deletion test/wpt/test-abort.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use strict';
require('../common');

const { WPTRunner } = require('../common/wpt');

const runner = new WPTRunner('dom/abort');
Expand Down
1 change: 0 additions & 1 deletion test/wpt/test-atob.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use strict';

require('../common');
const { WPTRunner } = require('../common/wpt');

const runner = new WPTRunner('html/webappapis/atob');
Expand Down
8 changes: 0 additions & 8 deletions test/wpt/test-blob.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
'use strict';

require('../common');
const { WPTRunner } = require('../common/wpt');

const runner = new WPTRunner('FileAPI/blob');

runner.setInitScript(`
const { Blob } = require('buffer');
const { ReadableStream } = require('stream/web');
global.Blob = Blob;
global.ReadableStream = ReadableStream;
`);

runner.runJsTests();
6 changes: 0 additions & 6 deletions test/wpt/test-broadcastchannel.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
'use strict';

require('../common');
const { WPTRunner } = require('../common/wpt');

const runner = new WPTRunner('webmessaging/broadcastchannel');

runner.setInitScript(`
const { BroadcastChannel } = require('worker_threads');
global.BroadcastChannel = BroadcastChannel;
`);

runner.runJsTests();
2 changes: 1 addition & 1 deletion test/wpt/test-console.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use strict';
require('../common');

const { WPTRunner } = require('../common/wpt');

const runner = new WPTRunner('console');
Expand Down
12 changes: 0 additions & 12 deletions test/wpt/test-domexception.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,7 @@
'use strict';

require('../common');
const { WPTRunner } = require('../common/wpt');

const runner = new WPTRunner('webidl/ecmascript-binding/es-exceptions');

runner.setFlags(['--expose-internals']);
runner.setInitScript(`
const { internalBinding } = require('internal/test/binding');
const { DOMException } = internalBinding('messaging');
Object.defineProperty(global, 'DOMException', {
writable: true,
configurable: true,
value: DOMException,
});
`);

runner.runJsTests();
8 changes: 2 additions & 6 deletions test/wpt/test-encoding.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
'use strict';
require('../common');

const { WPTRunner } = require('../common/wpt');
const runner = new WPTRunner('encoding');

runner.setInitScript(`
const { MessageChannel } = require('worker_threads');
global.MessageChannel = MessageChannel;
`);
const runner = new WPTRunner('encoding');

runner.runJsTests();
2 changes: 1 addition & 1 deletion test/wpt/test-events.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use strict';
require('../common');

const { WPTRunner } = require('../common/wpt');

const runner = new WPTRunner('dom/events');
Expand Down
1 change: 0 additions & 1 deletion test/wpt/test-file.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use strict';

require('../common');
const { WPTRunner } = require('../common/wpt');

const runner = new WPTRunner('FileAPI/file');
Expand Down
6 changes: 3 additions & 3 deletions test/wpt/test-hr-time.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
'use strict';

require('../common');
const { WPTRunner } = require('../common/wpt');

const runner = new WPTRunner('hr-time');

runner.pretendGlobalThisAs('Window');
runner.brandCheckGlobalScopeAttribute('performance');
runner.setInitScript(`
self.GLOBAL.isWorker = () => false;
`);

runner.runJsTests();
1 change: 0 additions & 1 deletion test/wpt/test-microtask-queuing.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use strict';

require('../common');
const { WPTRunner } = require('../common/wpt');

const runner = new WPTRunner('html/webappapis/microtask-queuing');
Expand Down
4 changes: 1 addition & 3 deletions test/wpt/test-performance-timeline.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
'use strict';
require('../common');

const { WPTRunner } = require('../common/wpt');

const runner = new WPTRunner('performance-timeline');

runner.pretendGlobalThisAs('Window');
runner.brandCheckGlobalScopeAttribute('performance');
runner.setInitScript(`
// Create a dummy resource timing entry to mimic how the browser would
// record the initial page load.
Expand Down
3 changes: 1 addition & 2 deletions test/wpt/test-resource-timing.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
'use strict';
require('../common');

const { WPTRunner } = require('../common/wpt');

const runner = new WPTRunner('resource-timing');

runner.pretendGlobalThisAs('Window');
runner.setInitScript(`
global.resource = performance.markResourceTiming({
startTime: 0,
Expand Down
21 changes: 1 addition & 20 deletions test/wpt/test-streams.js
Original file line number Diff line number Diff line change
@@ -1,36 +1,17 @@
'use strict';

require('../common');
const { WPTRunner } = require('../common/wpt');

const runner = new WPTRunner('streams');

// Set a script that will be executed in the worker before running the tests.
runner.pretendGlobalThisAs('Window');
runner.setInitScript(`
// Simulate global postMessage for enqueue-with-detached-buffer.window.js
// Simulate globalThis postMessage for enqueue-with-detached-buffer.window.js
function postMessage(value, origin, transferList) {
const mc = new MessageChannel();
mc.port1.postMessage(value, transferList);
mc.port2.close();
}
// TODO(@jasnell): This is a bit of a hack to get the idl harness test
// working. Later we should investigate a better approach.
// See: https://github.com/nodejs/node/pull/39062#discussion_r659383373
Object.defineProperties(global, {
DedicatedWorkerGlobalScope: {
get() {
// Pretend that we're a DedicatedWorker, but *only* for the
// IDL harness. For everything else, keep the JavaScript shell
// environment.
if (new Error().stack.includes('idlharness.js'))
return global.constructor;
else
return function() {};
}
}
});
`);

runner.runJsTests();
1 change: 0 additions & 1 deletion test/wpt/test-structured-clone.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use strict';

require('../common');
const { WPTRunner } = require('../common/wpt');

const runner = new WPTRunner('html/webappapis/structured-clone');
Expand Down
Loading

0 comments on commit 249efbf

Please sign in to comment.