@@ -31,57 +31,57 @@ import Viceroy from './src/viceroy.js';
31
31
import UpstreamServer from './src/upstream-server.js' ;
32
32
import compareUpstreamRequest from './src/compare-upstream-request.js' ;
33
33
import compareDownstreamResponse from './src/compare-downstream-response.js' ;
34
+ import tests from './src/test-suite.js' ;
34
35
35
- // Get our config from the Github Action
36
- const integrationTestBase = `./integration-tests/js-compute` ;
37
- const fixtureBase = `${ integrationTestBase } /fixtures` ;
38
36
39
- async function spawnViceroy ( testName , viceroyAddr ) {
40
- const wasmPath = `${ fixtureBase } /${ testName } /${ testName } .wasm` ;
41
- const fastlyTomlPath = `${ fixtureBase } /${ testName } /fastly.toml` ;
37
+ async function spawnViceroy ( config , testName , viceroyAddr ) {
38
+ console . info ( `Spawning a viceroy instance for ${ testName } on ${ viceroyAddr } ` ) ;
42
39
43
40
let viceroy = new Viceroy ( ) ;
44
- await viceroy . spawn ( wasmPath , {
45
- config : fastlyTomlPath ,
41
+
42
+ await viceroy . spawn ( config . wasmPath ( testName ) , {
43
+ config : config . fastlyTomlPath ( testName ) ,
46
44
addr : viceroyAddr
47
45
} ) ;
48
46
49
47
return viceroy ;
50
48
}
51
49
52
- function buildTest ( testName , backendAddr ) {
50
+ function buildTest ( config , testName , backendAddr ) {
53
51
console . info ( `Compiling the fixture for: ${ testName } ...` ) ;
54
52
55
53
try {
56
- childProcess . execSync ( `./integration-tests/js-compute/build-one.sh ${ testName } ` ) ;
54
+ childProcess . execSync ( `${ config . buildScript } ${ testName } ` ) ;
57
55
} catch ( e ) {
58
56
console . error ( `Failed to compile ${ testName } ` ) ;
59
- console . log ( e . stdout . toString ( "utf-8" ) ) ;
57
+ console . info ( e . stdout . toString ( "utf-8" ) ) ;
60
58
process . exit ( 1 ) ;
61
59
}
62
60
63
61
try {
64
- childProcess . execSync ( `./integration-tests/js-compute/replace-host.sh ${ testName } http://${ backendAddr } ` ) ;
62
+ childProcess . execSync ( `${ config . replaceHostScript } ${ testName } http://${ backendAddr } ` ) ;
65
63
} catch ( e ) {
66
64
console . error ( `Failed to compile ${ testName } ` ) ;
67
- console . log ( e . stdout . toString ( "utf-8" ) ) ;
65
+ console . info ( e . stdout . toString ( "utf-8" ) ) ;
68
66
process . exit ( 1 ) ;
69
67
}
70
68
}
71
69
72
- async function discoverTests ( fixturesPath ) {
70
+ async function discoverTests ( config ) {
71
+ console . info ( `Looking for tests in ${ config . fixtureBase } ` ) ;
72
+
73
73
let tests = { } ;
74
74
75
75
// discover all of our test cases
76
- let fixtures = await fsPromises . readdir ( fixturesPath , { withFileTypes : true } ) ;
76
+ let fixtures = await fsPromises . readdir ( config . fixtureBase , { withFileTypes : true } ) ;
77
77
for ( const ent of fixtures ) {
78
78
if ( ! ent . isDirectory ( ) ) {
79
79
continue ;
80
80
}
81
81
82
82
let jsonText ;
83
83
try {
84
- jsonText = await fsPromises . readFile ( ` ${ fixturesPath } / ${ ent . name } /tests.json` ) ;
84
+ jsonText = await fsPromises . readFile ( config . testJsonPath ( ent . name ) ) ;
85
85
} catch ( err ) {
86
86
continue ;
87
87
}
@@ -96,18 +96,21 @@ async function discoverTests(fixturesPath) {
96
96
// Our main task, in which we compile and run tests
97
97
const mainAsyncTask = async ( ) => {
98
98
99
+ // Get our config from the Github Action
100
+ const config = new tests . TestConfig ( './integration-tests/js-compute' ) ;
101
+
99
102
const backendAddr = '127.0.0.1:8082' ;
100
103
101
- const testCases = await discoverTests ( fixtureBase ) ;
104
+ const testCases = await discoverTests ( config ) ;
102
105
const testNames = Object . keys ( testCases ) ;
103
106
104
107
// build all the tests
105
- testNames . forEach ( testName => buildTest ( testName , backendAddr ) ) ;
106
- buildTest ( 'backend' , backendAddr ) ;
108
+ testNames . forEach ( testName => buildTest ( config , testName , backendAddr ) ) ;
109
+ buildTest ( config , 'backend' , backendAddr ) ;
107
110
108
111
// Start up the local backend
109
112
console . info ( `Starting the generic backend on ${ backendAddr } ` ) ;
110
- let backend = await spawnViceroy ( 'backend' , backendAddr ) ;
113
+ let backend = await spawnViceroy ( config , 'backend' , backendAddr ) ;
111
114
112
115
console . info ( `Running the Viceroy environment tests ...` ) ;
113
116
@@ -135,23 +138,13 @@ const mainAsyncTask = async () => {
135
138
136
139
// Iterate through the module tests, and run the Viceroy tests
137
140
for ( const testName of testNames ) {
138
- const testBase = `${ fixtureBase } /${ testName } ` ;
139
-
140
- // created/used by ./integration-tests/js-compute/build-one.sh
141
- const fastlyTomlPath = `${ testBase } /fastly.toml` ;
142
- const wasmPath = `${ testBase } /${ testName } .wasm` ;
143
-
144
141
const tests = testCases [ testName ] ;
145
142
const moduleTestKeys = Object . keys ( tests ) ;
146
143
console . info ( `Running tests for the module: ${ testName } ...` ) ;
147
144
148
145
// Spawn a new viceroy instance for the module
149
- viceroy = new Viceroy ( ) ;
150
146
const viceroyAddr = '127.0.0.1:8080' ;
151
- await viceroy . spawn ( wasmPath , {
152
- config : fastlyTomlPath ,
153
- addr : viceroyAddr
154
- } )
147
+ viceroy = await spawnViceroy ( config , testName , viceroyAddr ) ;
155
148
156
149
for ( const testKey of moduleTestKeys ) {
157
150
const test = tests [ testKey ] ;
@@ -161,7 +154,7 @@ const mainAsyncTask = async () => {
161
154
continue ;
162
155
}
163
156
164
- console . log ( `Running the test ${ testKey } ...` ) ;
157
+ console . info ( `Running the test ${ testKey } ...` ) ;
165
158
166
159
// Prepare our upstream server for this specific test
167
160
isDownstreamResponseHandled = false ;
0 commit comments