Skip to content

Commit ecbd8f9

Browse files
authored
Merge pull request #103 from ircam-ismm/feat/run-idlharness
Feat: run idlharness from wpt
2 parents 956c43d + 9f4ef83 commit ecbd8f9

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

.scripts/wpt-harness.mjs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import * as nodeWebAudioAPI from '../index.mjs';
77

88
// mocks
99
import createXMLHttpRequest from './wpt-mock/XMLHttpRequest.js';
10+
import createFetch from './wpt-mock/fetch.js';
1011
import { DOMException } from '../js/lib/errors.js';
1112

1213
program
@@ -31,6 +32,7 @@ function indent(string, times) {
3132
// -------------------------------------------------------
3233
// WPT Runner configuration options
3334
// -------------------------------------------------------
35+
const wptRootPath = path.join('wpt');
3436
const testsPath = path.join('wpt','webaudio');
3537
const rootURL = 'webaudio';
3638

@@ -47,6 +49,7 @@ const setup = window => {
4749

4850
// e.g. 'resources/audiobuffersource-multi-channels-expected.wav'
4951
window.XMLHttpRequest = createXMLHttpRequest(testsPath);
52+
window.fetch = createFetch(wptRootPath);
5053
// window.requestAnimationFrame = func => setInterval(func, 16);
5154
// errors
5255
window.TypeError = TypeError;

.scripts/wpt-mock/fetch.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// required in node_modules/wpt_runner/testharness/idlharness.js, cf `fetch_spec`
2+
const fs = require('node:fs');
3+
const path = require('node:path');
4+
5+
module.exports = function createFetch(basePath) {
6+
return function fetch(pathname) {
7+
pathname = path.join(basePath, pathname);
8+
9+
return new Promise(resolve => {
10+
if (!fs.existsSync(pathname)) {
11+
resolve({
12+
ok: false,
13+
msg: `file ${pathname} not found`,
14+
});
15+
} else {
16+
const buffer = fs.readFileSync(pathname);
17+
18+
resolve({
19+
ok: true,
20+
text: () => buffer.toString(),
21+
});
22+
}
23+
});
24+
}
25+
};

0 commit comments

Comments
 (0)