1
1
/* eslint-env serviceworker */
2
+ /* global add_completion_callback setup done */
3
+ import { enableDebugLogging , setDefaultBackend , setBaseURL } from "fastly:experimental" ;
2
4
3
- fastly . enableDebugLogging ( true ) ;
4
- fastly . defaultBackend = "wpt" ;
5
+ enableDebugLogging ( true ) ;
6
+ setDefaultBackend ( "wpt" ) ;
5
7
6
- let completionPromise = new Promise ( ( resolve , reject ) => {
8
+ let completionPromise = new Promise ( ( resolve ) => {
7
9
add_completion_callback ( function ( tests , harness_status , asserts ) {
8
10
resolve ( { tests, harness_status, asserts} ) ;
9
11
} ) ;
@@ -14,15 +16,17 @@ setup({ explicit_done: true });
14
16
async function handleRequest ( event ) {
15
17
let url = new URL ( event . request . url ) ;
16
18
let input = `http://web-platform.test:8000${ url . pathname } ${ url . search } ` ;
17
- fastly . baseURL = new URL ( input ) ;
18
- globalThis . location = fastly . baseURL ;
19
+ let baseURL = new URL ( input ) ;
20
+ setBaseURL ( baseURL ) ;
21
+ globalThis . location = baseURL ;
19
22
try {
20
23
let response = await fetch ( input ) ;
21
24
let testSource = await response . text ( ) ;
22
25
testSource += "\n//# sourceURL=" + url . pathname ;
23
26
24
27
let scripts = [ ] ;
25
28
29
+ // eslint-disable-next-line no-unused-vars
26
30
for ( let [ _ , path ] of testSource . matchAll ( / M E T A : * s c r i p t = ( .+ ) / g) ) {
27
31
let metaSource = await loadMetaScript ( path , input ) ;
28
32
scripts . push ( metaSource ) ;
@@ -32,7 +36,7 @@ async function handleRequest(event) {
32
36
evalAllScripts ( scripts ) ;
33
37
done ( ) ;
34
38
35
- let { tests, harness_status , asserts } = await completionPromise ;
39
+ let { tests} = await completionPromise ;
36
40
37
41
return new Response ( JSON . stringify ( tests , null , 2 ) , { headers : { "content-encoding" : "application/json" } } ) ;
38
42
} catch ( e ) {
@@ -44,15 +48,15 @@ async function handleRequest(event) {
44
48
}
45
49
}` , { status : 500 } ) ;
46
50
}
47
- } ;
51
+ }
48
52
49
53
function evalAllScripts ( wpt_test_scripts ) {
50
54
for ( let wpt_test_script of wpt_test_scripts ) {
51
55
eval ( wpt_test_script ) ;
52
56
}
53
57
}
54
58
55
- async function loadMetaScript ( path , base ) {
59
+ async function loadMetaScript ( path ) {
56
60
let response = await fetch ( path ) ;
57
61
let metaSource = await response . text ( ) ;
58
62
// Somewhat annoyingly, the WPT harness includes META scripts as <script src=[path]> tags,
0 commit comments