xref: /third_party/node/test/wpt/test-streams.js (revision 1cb0ef41)
1'use strict';
2
3const { WPTRunner } = require('../common/wpt');
4
5const runner = new WPTRunner('streams');
6
7// Set a script that will be executed in the worker before running the tests.
8runner.pretendGlobalThisAs('Window');
9runner.setInitScript(`
10  // Simulate global postMessage for enqueue-with-detached-buffer.window.js
11  function postMessage(value, origin, transferList) {
12    const mc = new MessageChannel();
13    mc.port1.postMessage(value, transferList);
14    mc.port2.close();
15  }
16
17  // TODO(@jasnell): This is a bit of a hack to get the idl harness test
18  // working. Later we should investigate a better approach.
19  // See: https://github.com/nodejs/node/pull/39062#discussion_r659383373
20  Object.defineProperties(global, {
21    DedicatedWorkerGlobalScope: {
22      get() {
23        // Pretend that we're a DedicatedWorker, but *only* for the
24        // IDL harness. For everything else, keep the JavaScript shell
25        // environment.
26        if (new Error().stack.includes('idlharness.js'))
27          return global.constructor;
28        else
29          return function() {};
30      }
31    }
32  });
33`);
34
35runner.runJsTests();
36