Skip to content

Commit 8bdec4b

Browse files
authored
chore: restructure compile.test.json (#22)
1 parent 2e4853f commit 8bdec4b

File tree

4 files changed

+1674
-1609
lines changed

4 files changed

+1674
-1609
lines changed

src/compile.test.ts

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -30,25 +30,31 @@ function go(data: unknown, query: JSONQuery, options?: JSONQueryCompileOptions)
3030
}
3131

3232
const groupByCategory = compile(['groupBy', ['get', 'category']])
33-
const testsByCategory = groupByCategory(suite.tests) as Record<string, CompileTestSuite['tests']>
33+
const testsByCategory = groupByCategory(suite.groups) as Record<string, CompileTestSuite['groups']>
3434

35-
for (const [category, tests] of Object.entries(testsByCategory)) {
35+
for (const [category, testGroups] of Object.entries(testsByCategory)) {
3636
describe(category, () => {
37-
for (const currentTest of tests) {
38-
if (isTestException(currentTest)) {
39-
test(currentTest.description, () => {
40-
const { input, query, throws } = currentTest
41-
42-
expect(() => compile(query)(input)).toThrow(throws)
43-
})
44-
} else {
45-
test(currentTest.description, () => {
46-
const { input, query, output } = currentTest
47-
const actualOutput = compile(query)(input)
48-
49-
expect({ input, query, output: actualOutput }).toEqual({ input, query, output })
50-
})
51-
}
37+
for (const group of testGroups) {
38+
describe(group.description, () => {
39+
for (const currentTest of group.tests) {
40+
const description = `input = '${currentTest.input}'`
41+
42+
if (isTestException(currentTest)) {
43+
test(description, () => {
44+
const { input, query, throws } = currentTest
45+
46+
expect(() => compile(query)(input)).toThrow(throws)
47+
})
48+
} else {
49+
test(description, () => {
50+
const { input, query, output } = currentTest
51+
const actualOutput = compile(query)(input)
52+
53+
expect({ input, query, output: actualOutput }).toEqual({ input, query, output })
54+
})
55+
}
56+
}
57+
})
5258
}
5359
})
5460
}

test-suite/compile.test.d.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
import type { JSONQuery } from '../src/types'
22

33
export interface CompileTestOutput {
4-
category: string
5-
description: string
64
input: unknown
75
query: JSONQuery
86
output: unknown
97
}
108

119
export interface CompileTestException {
12-
category: string
13-
description: string
1410
input: unknown
1511
query: JSONQuery
1612
throws: string
1713
}
1814

19-
export type CompileTest = CompileTestOutput | CompileTestException
15+
export interface CompileTestGroup {
16+
category: string
17+
description: string
18+
tests: Array<CompileTestOutput | CompileTestException>
19+
}
2020

2121
export interface CompileTestSuite {
2222
updated: string
23-
tests: CompileTest[]
23+
groups: CompileTestGroup[]
2424
}

0 commit comments

Comments
 (0)