1
- import { JestAssertionError } from 'expect'
2
1
import runners , { type RunnerTypes } from '../sourceRunner'
3
2
import { Chapter , type ExecutionMethod , Variant } from '../../types'
4
3
import type { Runner } from '../types'
@@ -98,10 +97,7 @@ const sourceCases: FullTestCase[] = [
98
97
99
98
// These JS cases never evaluate a prelude,
100
99
// nor ever have verbose errors enabled
101
- const fullJSCases : TestCase [ ] = [
102
- { chapter : Chapter . FULL_JS } ,
103
- { chapter : Chapter . FULL_TS }
104
- ]
100
+ const fullJSCases : TestCase [ ] = [ { chapter : Chapter . FULL_JS } , { chapter : Chapter . FULL_TS } ]
105
101
106
102
// The alt langs never evaluate a prelude,
107
103
// always use fullJS regardless of variant,
@@ -126,14 +122,18 @@ function expectCalls(count: number, expected: RunnerTypes) {
126
122
127
123
switch ( unexpectedRunner ) {
128
124
case undefined :
129
- throw new JestAssertionError ( `Expected ${ expected } to be called ${ count } times, but no runners were called` )
125
+ throw new Error (
126
+ `Expected ${ expected } to be called ${ count } times, but no runners were called`
127
+ )
130
128
case expected : {
131
129
expect ( runners [ expected ] ) . toHaveBeenCalledTimes ( count )
132
130
return asMockedFunc ( runners [ expected ] ) . mock . calls
133
131
}
134
132
default : {
135
133
const callCount = asMockedFunc ( runners [ unexpectedRunner ] ) . mock . calls . length
136
- throw new JestAssertionError ( `Expected ${ expected } to be called ${ count } times, but ${ unexpectedRunner } was called ${ callCount } times` )
134
+ throw new Error (
135
+ `Expected ${ expected } to be called ${ count } times, but ${ unexpectedRunner } was called ${ callCount } times`
136
+ )
137
137
}
138
138
}
139
139
}
@@ -217,31 +217,30 @@ describe('Ensure that the correct runner is used for the given evaluation contex
217
217
testCases ( 'Test regular source cases' , sourceCases )
218
218
testCases (
219
219
'Test source verbose error cases' ,
220
- sourceCases . map (
221
- tc => ( {
222
- ...tc ,
223
- verboseErrors : true ,
224
- expectedRunner : 'cse-machine'
225
- } )
226
- )
220
+ sourceCases . map ( tc => ( {
221
+ ...tc ,
222
+ verboseErrors : true ,
223
+ expectedRunner : 'cse-machine'
224
+ } ) )
227
225
)
228
226
229
227
testCases (
230
228
'Test source cases with debugger statements' ,
231
- sourceCases . map (
232
- tc => ( {
233
- ...tc ,
234
- code : 'debugger;\n' + ( tc . code ?? '' ) ,
235
- expectedRunner : 'cse-machine'
236
- } )
237
- )
229
+ sourceCases . map ( tc => ( {
230
+ ...tc ,
231
+ code : 'debugger;\n' + ( tc . code ?? '' ) ,
232
+ expectedRunner : 'cse-machine'
233
+ } ) )
238
234
)
239
235
240
- testCases ( 'Test explicit control variant' , sourceCases . map ( tc => ( {
241
- ...tc ,
242
- variant : Variant . EXPLICIT_CONTROL ,
243
- expectedRunner : 'cse-machine'
244
- } ) ) )
236
+ testCases (
237
+ 'Test explicit control variant' ,
238
+ sourceCases . map ( tc => ( {
239
+ ...tc ,
240
+ variant : Variant . EXPLICIT_CONTROL ,
241
+ expectedRunner : 'cse-machine'
242
+ } ) )
243
+ )
245
244
246
245
testCases (
247
246
'Test FullJS cases' ,
@@ -278,57 +277,63 @@ describe('Ensure that the correct runner is used for the given evaluation contex
278
277
)
279
278
)
280
279
281
- test ( 'if optionMethod is specified, verbose errors is ignored' , ( ) => testCase ( {
282
- code : '"enable verbose"; 0;' ,
283
- optionMethod : 'native' ,
284
- chapter : Chapter . SOURCE_4 ,
285
- variant : Variant . DEFAULT ,
286
- expectedPrelude : true ,
287
- expectedRunner : 'native'
288
- } ) )
289
-
290
- test ( 'if optionMethod is specified, debubger statements are ignored' , ( ) => testCase ( {
291
- code : 'debugger; 0;' ,
292
- optionMethod : 'native' ,
293
- chapter : Chapter . SOURCE_4 ,
294
- variant : Variant . DEFAULT ,
295
- expectedPrelude : true ,
296
- expectedRunner : 'native'
297
- } ) )
298
-
299
- test ( 'if contextMethod is specified, verbose errors is ignored' , ( ) => testCase ( {
300
- code : '"enable verbose"; 0;' ,
301
- contextMethod : 'native' ,
302
- chapter : Chapter . SOURCE_4 ,
303
- variant : Variant . DEFAULT ,
304
- expectedPrelude : true ,
305
- expectedRunner : 'native'
306
- } ) )
307
-
308
- test ( 'if contextMethod is specified, debugger statements are ignored' , ( ) => testCase ( {
309
- code : 'debugger; 0;' ,
310
- contextMethod : 'native' ,
311
- chapter : Chapter . SOURCE_4 ,
312
- variant : Variant . DEFAULT ,
313
- expectedPrelude : true ,
314
- expectedRunner : 'native'
315
- } ) )
316
-
317
- test ( 'optionMethod takes precedence over contextMethod' , ( ) => testCase ( {
318
- code : '0;' ,
319
- contextMethod : 'native' ,
320
- optionMethod : 'cse-machine' ,
321
- chapter : Chapter . SOURCE_4 ,
322
- variant : Variant . DEFAULT ,
323
- expectedPrelude : true ,
324
- expectedRunner : 'cse-machine'
325
- } ) )
326
-
327
- test ( 'debugger statements require cse-machine' , ( ) => testCase ( {
328
- code : 'debugger; 0;' ,
329
- chapter : Chapter . SOURCE_4 ,
330
- variant : Variant . DEFAULT ,
331
- expectedPrelude : true ,
332
- expectedRunner : 'cse-machine'
333
- } ) )
280
+ test ( 'if optionMethod is specified, verbose errors is ignored' , ( ) =>
281
+ testCase ( {
282
+ code : '"enable verbose"; 0;' ,
283
+ optionMethod : 'native' ,
284
+ chapter : Chapter . SOURCE_4 ,
285
+ variant : Variant . DEFAULT ,
286
+ expectedPrelude : true ,
287
+ expectedRunner : 'native'
288
+ } ) )
289
+
290
+ test ( 'if optionMethod is specified, debubger statements are ignored' , ( ) =>
291
+ testCase ( {
292
+ code : 'debugger; 0;' ,
293
+ optionMethod : 'native' ,
294
+ chapter : Chapter . SOURCE_4 ,
295
+ variant : Variant . DEFAULT ,
296
+ expectedPrelude : true ,
297
+ expectedRunner : 'native'
298
+ } ) )
299
+
300
+ test ( 'if contextMethod is specified, verbose errors is ignored' , ( ) =>
301
+ testCase ( {
302
+ code : '"enable verbose"; 0;' ,
303
+ contextMethod : 'native' ,
304
+ chapter : Chapter . SOURCE_4 ,
305
+ variant : Variant . DEFAULT ,
306
+ expectedPrelude : true ,
307
+ expectedRunner : 'native'
308
+ } ) )
309
+
310
+ test ( 'if contextMethod is specified, debugger statements are ignored' , ( ) =>
311
+ testCase ( {
312
+ code : 'debugger; 0;' ,
313
+ contextMethod : 'native' ,
314
+ chapter : Chapter . SOURCE_4 ,
315
+ variant : Variant . DEFAULT ,
316
+ expectedPrelude : true ,
317
+ expectedRunner : 'native'
318
+ } ) )
319
+
320
+ test ( 'optionMethod takes precedence over contextMethod' , ( ) =>
321
+ testCase ( {
322
+ code : '0;' ,
323
+ contextMethod : 'native' ,
324
+ optionMethod : 'cse-machine' ,
325
+ chapter : Chapter . SOURCE_4 ,
326
+ variant : Variant . DEFAULT ,
327
+ expectedPrelude : true ,
328
+ expectedRunner : 'cse-machine'
329
+ } ) )
330
+
331
+ test ( 'debugger statements require cse-machine' , ( ) =>
332
+ testCase ( {
333
+ code : 'debugger; 0;' ,
334
+ chapter : Chapter . SOURCE_4 ,
335
+ variant : Variant . DEFAULT ,
336
+ expectedPrelude : true ,
337
+ expectedRunner : 'cse-machine'
338
+ } ) )
334
339
} )
0 commit comments