Skip to content

Commit a0c588e

Browse files
committedMar 17, 2025·
Run format
1 parent b4de94d commit a0c588e

File tree

6 files changed

+92
-88
lines changed

6 files changed

+92
-88
lines changed
 

‎src/runner/__tests__/execMethod.ts

+84-79
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { JestAssertionError } from 'expect'
21
import runners, { type RunnerTypes } from '../sourceRunner'
32
import { Chapter, type ExecutionMethod, Variant } from '../../types'
43
import 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
})

‎src/runner/errors.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { NullableMappedPosition, RawSourceMap, SourceMapConsumer } from 'source-map'
1+
import { type NullableMappedPosition, type RawSourceMap, SourceMapConsumer } from 'source-map'
22

33
import { UNKNOWN_LOCATION } from '../constants'
44
import { ConstAssignment, ExceptionError, UndefinedVariable } from '../errors/errors'
5-
import { SourceError } from '../types'
5+
import type { SourceError } from '../types'
66
import { locationDummyNode } from '../utils/ast/astCreator'
77

88
enum BrowserType {

‎src/runner/fullJSRunner.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,4 +87,4 @@ const fullJSRunner: Runner = async (program, context) => {
8787
}
8888
}
8989

90-
export default fullJSRunner
90+
export default fullJSRunner

‎src/runner/htmlRunner.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { IOptions, Result } from '..'
2-
import { Context, RecursivePartial } from '../types'
1+
import type { IOptions, Result } from '..'
2+
import type { Context, RecursivePartial } from '../types'
33

44
const HTML_ERROR_HANDLING_SCRIPT_TEMPLATE = `<script>
55
window.onerror = (msg, url, lineNum) => {
@@ -16,7 +16,7 @@ export const htmlErrorHandlingScript = HTML_ERROR_HANDLING_SCRIPT_TEMPLATE.repla
1616
export async function htmlRunner(
1717
code: string,
1818
context: Context,
19-
options: RecursivePartial<IOptions> = {}
19+
_options: RecursivePartial<IOptions> = {}
2020
): Promise<Result> {
2121
return Promise.resolve({
2222
status: 'finished',

‎src/runner/sourceRunner.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -127,4 +127,4 @@ const runners = {
127127

128128
export default runners
129129

130-
export type RunnerTypes = keyof typeof runners
130+
export type RunnerTypes = keyof typeof runners

‎src/runner/utils.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/* eslint-disable @typescript-eslint/no-unused-vars */
21
import type { DebuggerStatement, Program } from 'estree'
32

43
import type { IOptions, Result } from '..'
@@ -57,7 +56,7 @@ export function determineExecutionMethod(
5756
} else {
5857
let hasDebuggerStatement = false
5958
simple(program, {
60-
DebuggerStatement(node: DebuggerStatement) {
59+
DebuggerStatement() {
6160
hasDebuggerStatement = true
6261
}
6362
})

0 commit comments

Comments
 (0)
Please sign in to comment.