1
1
#!/usr/bin/env -S npx ts-node -P ci/tsconfig.json
2
2
3
- import * as https from "https"
3
+ import cp from "child_process"
4
+ import * as events from "events"
5
+ import * as readline from "readline"
4
6
import replaceInFile from "replace-in-file"
5
- import { exec , main , selectCtx , spawn } from "./lib"
7
+ import { exec , main , selectCtx , spawn , wasmEnv } from "./lib"
6
8
7
- if ( process . argv [ 1 ] === __filename ) {
9
+ if ( require . main === module ) {
8
10
main ( test )
9
11
}
10
12
@@ -26,32 +28,67 @@ export async function test(ctx: Promise<unknown>) {
26
28
args . push ( "./..." )
27
29
}
28
30
29
- await spawn ( ctx , "go" , [ "test" , ...args ] , {
30
- timeout : 60_000 ,
31
+ const p1 = spawn ( ctx , "go" , [ "test" , ...args ] , {
31
32
stdio : "inherit" ,
32
33
} )
34
+ const p2 = wasmTest ( ctx )
35
+ await Promise . all ( [ p1 , p2 ] )
33
36
34
37
// Depending on the code tested, we may not have replaced anything so we do not
35
38
// check whether anything was replaced.
36
39
await selectCtx ( ctx , replaceInFile ( {
37
40
files : "./ci/out/coverage.prof" ,
38
41
from : [
39
- / .+ f r a m e _ s t r i n g e r .g o : .+ \n / g,
40
- / .+ w s j s t e s t : .+ \n / g,
41
- / .+ w s e c h o : .+ \n / g,
42
+ / .+ f r a m e _ s t r i n g e r .g o .+ \n / g,
43
+ / .+ w s j s t e s t .+ \n / g,
44
+ / .+ w s e c h o .+ \n / g,
42
45
] ,
43
46
to : "" ,
44
47
} ) )
45
48
46
49
let p : Promise < unknown > = exec ( ctx , "go tool cover -html=ci/out/coverage.prof -o=ci/out/coverage.html" )
47
50
48
51
if ( process . env . CI ) {
49
- const script = https . get ( "https://codecov.io/bash" )
50
- const p2 = spawn ( ctx , "bash -Z -R . -f ci/out/coverage.prof" , [ ] , {
51
- stdio : [ script ] ,
52
- } )
53
- p = Promise . all ( [ p , p2 ] )
52
+ p = Promise . all ( [ p , codecov ( ctx ) ] )
54
53
}
55
54
56
55
await p
57
56
}
57
+
58
+
59
+ async function wasmTest ( ctx : Promise < unknown > ) {
60
+ await Promise . all ( [
61
+ exec ( ctx , "go install ./internal/wsjstest" ) ,
62
+ exec ( ctx , "go install github.com/agnivade/wasmbrowsertest" ) ,
63
+ ] )
64
+
65
+ const url = await startWasmTestServer ( ctx )
66
+
67
+ await exec ( ctx , "go test -exec=wasmbrowsertest ./..." , {
68
+ env : {
69
+ ...wasmEnv ,
70
+ WS_ECHO_SERVER_URL : url ,
71
+ } ,
72
+ } )
73
+ }
74
+
75
+ async function startWasmTestServer ( ctx : Promise < unknown > ) : Promise < string > {
76
+ const wsjstest = cp . spawn ( "wsjstest" )
77
+ ctx . finally ( wsjstest . kill . bind ( wsjstest ) )
78
+
79
+ const rl = readline . createInterface ( {
80
+ input : wsjstest . stdout ! ,
81
+ } )
82
+
83
+ try {
84
+ const p = events . once ( rl , "line" )
85
+ const a = await selectCtx ( ctx , p )
86
+ return a [ 0 ]
87
+ } finally {
88
+ rl . close ( )
89
+ }
90
+ }
91
+
92
+ function codecov ( ctx : Promise < unknown > ) {
93
+ return exec ( ctx , "curl -s https://codecov.io/bash | bash -s -- -Z -f ci/out/coverage.prof" )
94
+ }
0 commit comments