(specs: string[] | FileSpecification[], runner: VitestRunner)
| 1042 | } |
| 1043 | |
| 1044 | export async function startTests(specs: string[] | FileSpecification[], runner: VitestRunner): Promise<File[]> { |
| 1045 | runner.trace ??= defaultTrace |
| 1046 | const cancel = runner.cancel?.bind(runner) |
| 1047 | // Ideally, we need to have an event listener for this, but only have a runner here. |
| 1048 | // Adding another onCancel felt wrong (maybe it needs to be refactored) |
| 1049 | runner.cancel = (reason) => { |
| 1050 | // We intentionally create only one error since there is only one test run that can be cancelled |
| 1051 | const error = new TestRunAbortError('The test run was aborted by the user.', reason) |
| 1052 | getRunningTests().forEach((test) => { |
| 1053 | abortContextSignal(test.context, error) |
| 1054 | markPendingTasksAsSkipped(test.file, runner, error.message) |
| 1055 | }, |
| 1056 | ) |
| 1057 | return cancel?.(reason) |
| 1058 | } |
| 1059 | |
| 1060 | if (!workerRunners.has(runner)) { |
| 1061 | runner.onCleanupWorkerContext?.(async () => { |
| 1062 | await Promise.all( |
| 1063 | [...TestFixtures.getWorkerContexts()].map(context => callFixtureCleanup(context)), |
| 1064 | ).finally(() => { |
| 1065 | TestFixtures.clearDefinitions() |
| 1066 | }) |
| 1067 | }) |
| 1068 | workerRunners.add(runner) |
| 1069 | } |
| 1070 | |
| 1071 | try { |
| 1072 | const paths = specs.map(f => typeof f === 'string' ? f : f.filepath) |
| 1073 | await runner.onBeforeCollect?.(paths) |
| 1074 | |
| 1075 | const files = await collectTests(specs, runner) |
| 1076 | |
| 1077 | await runner.onCollected?.(files) |
| 1078 | await runner.onBeforeRunFiles?.(files) |
| 1079 | |
| 1080 | await runFiles(files, runner) |
| 1081 | |
| 1082 | await runner.onAfterRunFiles?.(files) |
| 1083 | |
| 1084 | await finishSendTasksUpdate(runner) |
| 1085 | |
| 1086 | return files |
| 1087 | } |
| 1088 | finally { |
| 1089 | runner.cancel = cancel |
| 1090 | } |
| 1091 | } |
| 1092 | |
| 1093 | async function publicCollect(specs: string[] | FileSpecification[], runner: VitestRunner): Promise<File[]> { |
| 1094 | runner.trace ??= defaultTrace |
no test coverage detected