From ed8060640c6adccb8049ab38d77edd0f3e32c71b Mon Sep 17 00:00:00 2001 From: b-ma Date: Mon, 1 Apr 2024 19:57:37 +0200 Subject: [PATCH 1/2] feat: run idlharness from wpt --- .scripts/wpt-harness.mjs | 3 +++ .scripts/wpt-mock/fetch.js | 26 ++++++++++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 .scripts/wpt-mock/fetch.js diff --git a/.scripts/wpt-harness.mjs b/.scripts/wpt-harness.mjs index 88bd246f..b0ae4261 100644 --- a/.scripts/wpt-harness.mjs +++ b/.scripts/wpt-harness.mjs @@ -7,6 +7,7 @@ import * as nodeWebAudioAPI from '../index.mjs'; // mocks import createXMLHttpRequest from './wpt-mock/XMLHttpRequest.js'; +import createFetch from './wpt-mock/fetch.js'; import { DOMException } from '../js/lib/errors.js'; program @@ -31,6 +32,7 @@ function indent(string, times) { // ------------------------------------------------------- // WPT Runner configuration options // ------------------------------------------------------- +const wptRootPath = path.join('wpt'); const testsPath = path.join('wpt','webaudio'); const rootURL = 'webaudio'; @@ -47,6 +49,7 @@ const setup = window => { // e.g. 'resources/audiobuffersource-multi-channels-expected.wav' window.XMLHttpRequest = createXMLHttpRequest(testsPath); + window.fetch = createFetch(wptRootPath); // window.requestAnimationFrame = func => setInterval(func, 16); // errors window.TypeError = TypeError; diff --git a/.scripts/wpt-mock/fetch.js b/.scripts/wpt-mock/fetch.js new file mode 100644 index 00000000..022fa82a --- /dev/null +++ b/.scripts/wpt-mock/fetch.js @@ -0,0 +1,26 @@ +// require in node_modules/wpt_runner/testharness/idlharness.js, cf `fetch_spec` + +const fs = require('node:fs'); +const path = require('node:path'); + +module.exports = function createFetch(basePath) { + return function fetch(pathname) { + pathname = path.join(basePath, pathname); + + return new Promise(resolve => { + if (!fs.existsSync(pathname)) { + resolve({ + ok: false, + msg: `file ${pathname} not found`, + }); + } else { + const buffer = fs.readFileSync(pathname); + + resolve({ + ok: true, + text: () => buffer.toString(), + }); + } + }); + } +}; From 9f4ef83de9e23d231073a8f09984b0951676cde2 Mon Sep 17 00:00:00 2001 From: b-ma Date: Mon, 1 Apr 2024 20:07:08 +0200 Subject: [PATCH 2/2] cleaning --- .scripts/wpt-mock/fetch.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.scripts/wpt-mock/fetch.js b/.scripts/wpt-mock/fetch.js index 022fa82a..717636cf 100644 --- a/.scripts/wpt-mock/fetch.js +++ b/.scripts/wpt-mock/fetch.js @@ -1,5 +1,4 @@ -// require in node_modules/wpt_runner/testharness/idlharness.js, cf `fetch_spec` - +// required in node_modules/wpt_runner/testharness/idlharness.js, cf `fetch_spec` const fs = require('node:fs'); const path = require('node:path');