|
| 1 | +import type { TestModule } from 'vitest/node' |
| 2 | +import { expect, test } from 'vitest' |
| 3 | +import { instances, runInlineBrowserTests } from './utils' |
| 4 | + |
| 5 | +test('prepareDuration does not include the time of previous files', async () => { |
| 6 | + const testFile = ` |
| 7 | + import { test } from 'vitest' |
| 8 | + test('waits', async () => { |
| 9 | + await new Promise((resolve) => setTimeout(resolve, 1000)) |
| 10 | + }) |
| 11 | + ` |
| 12 | + const modulesByProject = new Map<string, TestModule[]>() |
| 13 | + |
| 14 | + const { stderr } = await runInlineBrowserTests( |
| 15 | + { |
| 16 | + 'first.test.ts': testFile, |
| 17 | + 'second.test.ts': testFile, |
| 18 | + }, |
| 19 | + { |
| 20 | + reporters: [ |
| 21 | + { |
| 22 | + onTestModuleEnd(module) { |
| 23 | + const modules = modulesByProject.get(module.project.name) ?? [] |
| 24 | + modules.push(module) |
| 25 | + modulesByProject.set(module.project.name, modules) |
| 26 | + }, |
| 27 | + }, |
| 28 | + ], |
| 29 | + }, |
| 30 | + ) |
| 31 | + |
| 32 | + expect(stderr).toBe('') |
| 33 | + expect(modulesByProject.size).toBe(instances.length) |
| 34 | + |
| 35 | + for (const [project, modules] of modulesByProject) { |
| 36 | + expect.soft(modules, project).toHaveLength(2) |
| 37 | + const [previous, next] = modules.map((module) => module.diagnostic()) |
| 38 | + |
| 39 | + expect.soft(previous.prepareDuration, project).toBeGreaterThan(0) |
| 40 | + expect.soft(next.prepareDuration, project).toBeGreaterThan(0) |
| 41 | + expect.soft(next.prepareDuration, project).toBeLessThan(previous.duration) |
| 42 | + } |
| 43 | +}) |
0 commit comments