Skip to content

Commit fa9419e

Browse files
committed
Update testing utilities
1 parent 79e6b76 commit fa9419e

File tree

5 files changed

+17
-24
lines changed

5 files changed

+17
-24
lines changed

src/parser/errors.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { SourceLocation } from 'estree'
1+
import type { SourceLocation } from 'estree'
22

33
import { UNKNOWN_LOCATION } from '../constants'
4-
import { ErrorSeverity, ErrorType, Node, SourceError } from '../types'
4+
import { ErrorSeverity, ErrorType, type Node, type SourceError } from '../types'
55
import { stripIndent } from '../utils/formatters'
66

77
export class MissingSemicolonError implements SourceError {

src/parser/types.ts

+5-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
import { ParserOptions } from '@babel/parser'
2-
import { Options } from 'acorn'
3-
import { Program } from 'estree'
1+
import type { Program } from 'estree'
42

53
import { Context, type Chapter, type Node, type SourceError, type Variant } from '../types'
64

7-
export type AcornOptions = Options
8-
export type BabelOptions = ParserOptions
5+
export type { Options as AcornOptions } from 'acorn'
6+
export type { ParserOptions as BabelOptions } from '@babel/parser'
97

108
export interface Parser<TOptions> {
119
parse(
@@ -27,8 +25,9 @@ export interface Rule<T extends Node> {
2725
testSnippets?: (
2826
| [code: string] // Test case with no expected error
2927
| [code: string, errorMsg: string] // Test case with expected error message
28+
// Test both expected error verbose and non-verbose
3029
| [code: string, errorMsg: string, verboseMsg: string]
31-
)[] // Test both expected error verbose and non-verbose
30+
)[]
3231
checkers: {
3332
[name: string]: (node: T, ancestors: Node[]) => SourceError[]
3433
}

src/parser/utils.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
import {
2-
Comment,
2+
type Comment,
33
ecmaVersion,
4-
Node,
4+
type Node,
55
parse as acornParse,
66
parseExpressionAt as acornParseAt,
7-
Position
7+
type Position
88
} from 'acorn'
99
import { parse as acornLooseParse } from 'acorn-loose'
10-
import { Program, SourceLocation } from 'estree'
10+
import type { Program, SourceLocation } from 'estree'
1111

12-
import { Context } from '..'
12+
import type { Context } from '..'
1313
import { DEFAULT_ECMA_VERSION } from '../constants'
14-
import { SourceError } from '../types'
14+
import type { SourceError } from '../types'
1515
import { validateAndAnnotate } from '../validator/validator'
1616
import { MissingSemicolonError, TrailingCommaError } from './errors'
17-
import { AcornOptions, BabelOptions } from './types'
17+
import type { AcornOptions, BabelOptions } from './types'
1818

1919
/**
2020
* Generates options object for acorn parser

src/utils/testing/__tests__/testing.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ describe('Testing createTestContext', () => {
2424
expect(context.variant).toEqual(Variant.DEFAULT)
2525
})
2626

27-
test('Providing a chaper runs default variant and that chapter', () => {
27+
test('Providing a chapter runs default variant and that chapter', () => {
2828
const context = createTestContext(Chapter.SOURCE_3)
2929
expect(context.chapter).toEqual(Chapter.SOURCE_3)
3030
expect(context.variant).toEqual(Variant.DEFAULT)

src/utils/testing/index.ts

+2-8
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,7 @@ import { mockContext } from './mocks'
66
import type { TestContext, TestOptions, TestResults } from './types'
77

88
export function createTestContext(rawOptions: TestOptions = {}): TestContext {
9-
const { chapter, variant, testBuiltins }: Exclude<TestOptions, Chapter> =
10-
typeof rawOptions === 'number'
11-
? {
12-
chapter: rawOptions
13-
}
14-
: rawOptions
9+
const { chapter, variant, testBuiltins } = processTestOptions(rawOptions)
1510

1611
const testContext: TestResults = {
1712
displayResult: [],
@@ -68,8 +63,7 @@ export function testMultipleCases<T extends Array<any>>(
6863
test.each(withIndex)('%s', (_, i, ...args) => tester(args, i), timeout)
6964
}
7065

71-
async function testInContext(code: string, rawOptions: TestOptions) {
72-
const options = processTestOptions(rawOptions)
66+
async function testInContext(code: string, options: TestOptions) {
7367
const context = createTestContext(options)
7468
const result = await runInContext(code, context)
7569
return {

0 commit comments

Comments
 (0)