File tree Expand file tree Collapse file tree 2 files changed +28
-0
lines changed Expand file tree Collapse file tree 2 files changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ import * as nodeWebAudioAPI from '../index.mjs';
7
7
8
8
// mocks
9
9
import createXMLHttpRequest from './wpt-mock/XMLHttpRequest.js' ;
10
+ import createFetch from './wpt-mock/fetch.js' ;
10
11
import { DOMException } from '../js/lib/errors.js' ;
11
12
12
13
program
@@ -31,6 +32,7 @@ function indent(string, times) {
31
32
// -------------------------------------------------------
32
33
// WPT Runner configuration options
33
34
// -------------------------------------------------------
35
+ const wptRootPath = path . join ( 'wpt' ) ;
34
36
const testsPath = path . join ( 'wpt' , 'webaudio' ) ;
35
37
const rootURL = 'webaudio' ;
36
38
@@ -47,6 +49,7 @@ const setup = window => {
47
49
48
50
// e.g. 'resources/audiobuffersource-multi-channels-expected.wav'
49
51
window . XMLHttpRequest = createXMLHttpRequest ( testsPath ) ;
52
+ window . fetch = createFetch ( wptRootPath ) ;
50
53
// window.requestAnimationFrame = func => setInterval(func, 16);
51
54
// errors
52
55
window . TypeError = TypeError ;
Original file line number Diff line number Diff line change
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
+ } ;
You can’t perform that action at this time.
0 commit comments