|
1 | 1 | import { beforeEach, describe, expect, test, vi } from 'vitest' |
2 | | -import runners, { type RunnerTypes } from '../sourceRunner' |
3 | | -import type { ExecutionMethod } from '../../types' |
4 | | -import { Chapter, Variant } from '../../langs' |
5 | | -import type { Runner } from '../types' |
6 | 2 | import { runCodeInSource } from '..' |
7 | | -import { mockContext } from '../../utils/testing/mocks' |
8 | | -import { getChapterName, objectKeys } from '../../utils/misc' |
9 | 3 | import { parseError } from '../..' |
10 | | -import * as validator from '../../validator/validator' |
| 4 | +import { Chapter, Variant } from '../../langs' |
| 5 | +import type { ExecutionMethod } from '../../types' |
| 6 | +import { getChapterName, objectKeys } from '../../utils/misc' |
11 | 7 | import { wrapWithSkipAndOnly } from '../../utils/testing/misc' |
| 8 | +import { mockContext } from '../../utils/testing/mocks' |
| 9 | +import * as validator from '../../validator/validator' |
| 10 | +import runners, { type RunnerTypes } from '../sourceRunner' |
| 11 | +import type { Runner } from '../types' |
12 | 12 |
|
13 | 13 | vi.spyOn(validator, 'validateAndAnnotate') |
14 | 14 |
|
@@ -73,6 +73,7 @@ interface TestCase { |
73 | 73 | expectedValidate: boolean |
74 | 74 |
|
75 | 75 | verboseErrors?: boolean |
| 76 | + timeout?: number |
76 | 77 | } |
77 | 78 |
|
78 | 79 | const sourceCases: TestCase[] = [ |
@@ -217,30 +218,37 @@ async function caseTester({ |
217 | 218 | } |
218 | 219 | } |
219 | 220 |
|
220 | | -const testCases = wrapWithSkipAndOnly('describe', function (desc: string, cases: TestCase[]) { |
221 | | - this(desc, () => |
222 | | - test.each( |
223 | | - cases.map(({ code, verboseErrors, contextMethod, chapter, variant, ...tc }, i) => { |
224 | | - chapter = chapter ?? Chapter.SOURCE_1 |
225 | | - variant = variant ?? Variant.DEFAULT |
226 | | - const context = mockContext(chapter, variant) |
227 | | - if (contextMethod !== undefined) { |
228 | | - context.executionMethod = contextMethod |
229 | | - } |
230 | | - |
231 | | - const chapterName = getChapterName(chapter) |
232 | | - let desc = `${i + 1}. Testing ${chapterName}, Variant: ${variant}, expected ${tc.expectedRunner} runner` |
233 | | - code = code ?? '' |
234 | | - if (verboseErrors) { |
235 | | - code = `"enable verbose";\n${code}` |
236 | | - desc += ' (verbose errors)' |
237 | | - } |
238 | | - |
239 | | - return [desc, { code, chapter, variant, ...tc }] |
240 | | - }) |
241 | | - )('%s', async (_, to) => caseTester(to)) |
242 | | - ) |
243 | | -}) |
| 221 | +const testCases = wrapWithSkipAndOnly( |
| 222 | + 'describe', |
| 223 | + function (desc: string, cases: TestCase[], timeout?: number) { |
| 224 | + this(desc, () => { |
| 225 | + const testEach = test.each( |
| 226 | + cases.map(({ code, verboseErrors, contextMethod, chapter, variant, ...tc }, i) => { |
| 227 | + chapter = chapter ?? Chapter.SOURCE_1 |
| 228 | + variant = variant ?? Variant.DEFAULT |
| 229 | + const context = mockContext(chapter, variant) |
| 230 | + if (contextMethod !== undefined) { |
| 231 | + context.executionMethod = contextMethod |
| 232 | + } |
| 233 | + |
| 234 | + const chapterName = getChapterName(chapter) |
| 235 | + let desc = `${i + 1}. Testing ${chapterName}, Variant: ${variant}, expected ${tc.expectedRunner} runner` |
| 236 | + code = code ?? '' |
| 237 | + if (verboseErrors) { |
| 238 | + code = `"enable verbose";\n${code}` |
| 239 | + desc += ' (verbose errors)' |
| 240 | + } |
| 241 | + |
| 242 | + return [desc, { code, chapter, variant, ...tc }] |
| 243 | + }) |
| 244 | + ) |
| 245 | + if (timeout !== undefined) { |
| 246 | + return testEach('%s', { timeout }, async (_, to) => caseTester(to)) |
| 247 | + } |
| 248 | + return testEach('%s', async (_, to) => caseTester(to)) |
| 249 | + }) |
| 250 | + } |
| 251 | +) |
244 | 252 |
|
245 | 253 | describe('Ensure that the correct runner is used for the given evaluation context and settings', () => { |
246 | 254 | testCases('Test regular source cases', sourceCases) |
@@ -300,7 +308,8 @@ describe('Ensure that the correct runner is used for the given evaluation contex |
300 | 308 | ) |
301 | 309 |
|
302 | 310 | return [fullCase, verboseErrorCase, ...variantCases] |
303 | | - }) |
| 311 | + }), |
| 312 | + 10_000 |
304 | 313 | ) |
305 | 314 |
|
306 | 315 | testCases( |
|
0 commit comments