1- import { JestAssertionError } from 'expect'
21import runners , { type RunnerTypes } from '../sourceRunner'
32import { Chapter , type ExecutionMethod , Variant } from '../../types'
43import type { Runner } from '../types'
@@ -98,10 +97,7 @@ const sourceCases: FullTestCase[] = [
9897
9998// These JS cases never evaluate a prelude,
10099// 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 } ]
105101
106102// The alt langs never evaluate a prelude,
107103// always use fullJS regardless of variant,
@@ -126,14 +122,18 @@ function expectCalls(count: number, expected: RunnerTypes) {
126122
127123 switch ( unexpectedRunner ) {
128124 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+ )
130128 case expected : {
131129 expect ( runners [ expected ] ) . toHaveBeenCalledTimes ( count )
132130 return asMockedFunc ( runners [ expected ] ) . mock . calls
133131 }
134132 default : {
135133 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+ )
137137 }
138138 }
139139}
@@ -217,31 +217,30 @@ describe('Ensure that the correct runner is used for the given evaluation contex
217217 testCases ( 'Test regular source cases' , sourceCases )
218218 testCases (
219219 '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+ } ) )
227225 )
228226
229227 testCases (
230228 '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+ } ) )
238234 )
239235
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+ )
245244
246245 testCases (
247246 'Test FullJS cases' ,
@@ -278,57 +277,63 @@ describe('Ensure that the correct runner is used for the given evaluation contex
278277 )
279278 )
280279
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+ } ) )
334339} )
0 commit comments