Skip to content

Feat: run idlharness from wpt #103

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

Merged
merged 2 commits into from
Apr 1, 2024
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
3 changes: 3 additions & 0 deletions .scripts/wpt-harness.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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';

Expand All @@ -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;
Expand Down
25 changes: 25 additions & 0 deletions .scripts/wpt-mock/fetch.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// required 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(),
});
}
});
}
};