@@ -54,6 +54,17 @@ impl TestMode {
54
54
| Self :: ServiceWorker { no_modules } => no_modules,
55
55
}
56
56
}
57
+
58
+ fn env ( self ) -> & ' static str {
59
+ match self {
60
+ TestMode :: Node { .. } => "WASM_BINDGEN_USE_NODE_EXPERIMENTAL" ,
61
+ TestMode :: Deno => "WASM_BINDGEN_USE_DENO" ,
62
+ TestMode :: Browser { .. } => "WASM_BINDGEN_USE_BROWSER" ,
63
+ TestMode :: DedicatedWorker { .. } => "WASM_BINDGEN_USE_DEDICATED_WORKER" ,
64
+ TestMode :: SharedWorker { .. } => "WASM_BINDGEN_USE_SHARED_WORKER" ,
65
+ TestMode :: ServiceWorker { .. } => "WASM_BINDGEN_USE_SERVICE_WORKER" ,
66
+ }
67
+ }
57
68
}
58
69
59
70
struct TmpDirDeleteGuard ( PathBuf ) ;
@@ -138,25 +149,40 @@ fn main() -> anyhow::Result<()> {
138
149
// to read later on.
139
150
140
151
let custom_section = wasm. customs . remove_raw ( "__wasm_bindgen_test_unstable" ) ;
152
+ let no_modules = std:: env:: var ( "WASM_BINDGEN_USE_NO_MODULE" ) . is_ok ( ) ;
141
153
let test_mode = match custom_section {
142
- Some ( section) if section. data . contains ( & 0x01 ) => TestMode :: Browser {
143
- no_modules : std:: env:: var ( "WASM_BINDGEN_USE_NO_MODULE" ) . is_ok ( ) ,
144
- } ,
145
- Some ( section) if section. data . contains ( & 0x02 ) => TestMode :: DedicatedWorker {
146
- no_modules : std:: env:: var ( "WASM_BINDGEN_USE_NO_MODULE" ) . is_ok ( ) ,
147
- } ,
148
- Some ( section) if section. data . contains ( & 0x03 ) => TestMode :: SharedWorker {
149
- no_modules : std:: env:: var ( "WASM_BINDGEN_USE_NO_MODULE" ) . is_ok ( ) ,
150
- } ,
151
- Some ( section) if section. data . contains ( & 0x04 ) => TestMode :: ServiceWorker {
152
- no_modules : std:: env:: var ( "WASM_BINDGEN_USE_NO_MODULE" ) . is_ok ( ) ,
153
- } ,
154
- Some ( section) if section. data . contains ( & 0x05 ) => TestMode :: Node {
155
- no_modules : std:: env:: var ( "WASM_BINDGEN_USE_NO_MODULE" ) . is_ok ( ) ,
156
- } ,
154
+ Some ( section) if section. data . contains ( & 0x01 ) => TestMode :: Browser { no_modules } ,
155
+ Some ( section) if section. data . contains ( & 0x02 ) => TestMode :: DedicatedWorker { no_modules } ,
156
+ Some ( section) if section. data . contains ( & 0x03 ) => TestMode :: SharedWorker { no_modules } ,
157
+ Some ( section) if section. data . contains ( & 0x04 ) => TestMode :: ServiceWorker { no_modules } ,
158
+ Some ( section) if section. data . contains ( & 0x05 ) => TestMode :: Node { no_modules } ,
157
159
Some ( _) => bail ! ( "invalid __wasm_bingen_test_unstable value" ) ,
158
- None if std:: env:: var ( "WASM_BINDGEN_USE_DENO" ) . is_ok ( ) => TestMode :: Deno ,
159
- None => TestMode :: Node { no_modules : true } ,
160
+ None => {
161
+ let mut modes = Vec :: new ( ) ;
162
+ let mut add_mode =
163
+ |mode : TestMode | std:: env:: var ( mode. env ( ) ) . is_ok ( ) . then ( || modes. push ( mode) ) ;
164
+ add_mode ( TestMode :: Deno ) ;
165
+ add_mode ( TestMode :: Browser { no_modules } ) ;
166
+ add_mode ( TestMode :: DedicatedWorker { no_modules } ) ;
167
+ add_mode ( TestMode :: SharedWorker { no_modules } ) ;
168
+ add_mode ( TestMode :: ServiceWorker { no_modules } ) ;
169
+ add_mode ( TestMode :: Node { no_modules } ) ;
170
+
171
+ match modes. len ( ) {
172
+ 0 => TestMode :: Node { no_modules : true } ,
173
+ 1 => modes[ 0 ] ,
174
+ _ => {
175
+ bail ! (
176
+ "only one test mode must be set, found: `{}`" ,
177
+ modes
178
+ . into_iter( )
179
+ . map( TestMode :: env)
180
+ . collect:: <Vec <_>>( )
181
+ . join( "`, `" )
182
+ )
183
+ }
184
+ }
185
+ }
160
186
} ;
161
187
162
188
let headless = env:: var ( "NO_HEADLESS" ) . is_err ( ) ;
0 commit comments