Skip to content

Commit 680a612

Browse files
authored
perf(pool): sort test files by project by default (#8914)
1 parent fdb2e79 commit 680a612

File tree

3 files changed

+21
-7
lines changed

3 files changed

+21
-7
lines changed

packages/vitest/src/node/sequencers/BaseSequencer.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,25 @@ export class BaseSequencer implements TestSequencer {
3535
public async sort(files: TestSpecification[]): Promise<TestSpecification[]> {
3636
const cache = this.ctx.cache
3737
return [...files].sort((a, b) => {
38+
// "sequence.groupOrder" is higher priority
39+
const groupOrderDiff = a.project.config.sequence.groupOrder - b.project.config.sequence.groupOrder
40+
if (groupOrderDiff !== 0) {
41+
return groupOrderDiff
42+
}
43+
44+
// Projects run sequential
45+
if (a.project.name !== b.project.name) {
46+
return a.project.name < b.project.name ? -1 : 1
47+
}
48+
49+
// Isolated run first
50+
if (a.project.config.isolate && !b.project.config.isolate) {
51+
return -1
52+
}
53+
if (!a.project.config.isolate && b.project.config.isolate) {
54+
return 1
55+
}
56+
3857
const keyA = `${a.project.name}:${relative(this.ctx.config.root, a.moduleId)}`
3958
const keyB = `${b.project.name}:${relative(this.ctx.config.root, b.moduleId)}`
4059

test/core/test/sequencers.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { TestSpecification } from '../../../packages/vitest/src/node/spec'
77
function buildCtx(config?: Partial<Vitest['config']>) {
88
return {
99
config: {
10-
sequence: {},
10+
sequence: { groupOrder: 0 },
1111
...config,
1212
},
1313
cache: {
@@ -22,6 +22,7 @@ function buildWorkspace() {
2222
name: 'test',
2323
config: {
2424
root: import.meta.dirname,
25+
sequence: { groupOrder: 0 },
2526
},
2627
} as any as TestProject
2728
}

test/coverage-test/vitest.config.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ export default defineConfig({
1919
extends: true,
2020
test: {
2121
name: { label: 'v8', color: 'green' },
22-
sequence: { groupOrder: 1 },
2322
env: { COVERAGE_PROVIDER: 'v8' },
2423
include: [GENERIC_TESTS, V8_TESTS],
2524
exclude: [
@@ -37,7 +36,6 @@ export default defineConfig({
3736
extends: true,
3837
test: {
3938
name: { label: 'istanbul', color: 'magenta' },
40-
sequence: { groupOrder: 2 },
4139
env: { COVERAGE_PROVIDER: 'istanbul' },
4240
include: [GENERIC_TESTS, ISTANBUL_TESTS],
4341
exclude: [
@@ -55,7 +53,6 @@ export default defineConfig({
5553
extends: true,
5654
test: {
5755
name: { label: 'custom', color: 'yellow' },
58-
sequence: { groupOrder: 3 },
5956
env: { COVERAGE_PROVIDER: 'custom' },
6057
include: [CUSTOM_TESTS],
6158
exclude: [FIXTURES],
@@ -67,7 +64,6 @@ export default defineConfig({
6764
extends: true,
6865
test: {
6966
name: { label: 'istanbul-browser', color: 'blue' },
70-
sequence: { groupOrder: 4 },
7167
env: { COVERAGE_PROVIDER: 'istanbul', COVERAGE_BROWSER: 'true' },
7268
testTimeout: 15_000,
7369
include: [
@@ -99,7 +95,6 @@ export default defineConfig({
9995
extends: true,
10096
test: {
10197
name: { label: 'v8-browser', color: 'red' },
102-
sequence: { groupOrder: 5 },
10398
env: { COVERAGE_PROVIDER: 'v8', COVERAGE_BROWSER: 'true' },
10499
testTimeout: 15_000,
105100
include: [
@@ -133,7 +128,6 @@ export default defineConfig({
133128
extends: true,
134129
test: {
135130
name: { label: 'unit', color: 'cyan' },
136-
sequence: { groupOrder: 6 },
137131
include: [UNIT_TESTS],
138132
typecheck: {
139133
enabled: true,

0 commit comments

Comments
 (0)