Skip to content

Commit 79c84f2

Browse files
committedJan 24, 2025··
feat(testFixtures): support concurrent mode
1 parent 44978cd commit 79c84f2

File tree

6 files changed

+36
-19
lines changed

6 files changed

+36
-19
lines changed
 

‎src/fixture.ts

+8-9
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,7 @@ import path from 'node:path'
22
import process from 'node:process'
33
import { normalizePath } from '@rollup/pluginutils'
44
import { glob, type GlobOptions } from 'tinyglobby'
5-
import {
6-
describe,
7-
expect as globalExpect,
8-
test,
9-
type ExpectStatic,
10-
} from 'vitest'
5+
import { describe, test } from 'vitest'
116

127
type SkipFn = (testName: string) => boolean | Promise<boolean>
138
let isSkip: SkipFn | undefined
@@ -18,7 +13,7 @@ export function testFixturesSkip(fn: SkipFn): void {
1813
export interface FixtureOptions {
1914
params?: [name: string, values?: any[]][]
2015
promise?: boolean
21-
expect?: ExpectStatic
16+
concurrent?: boolean
2217
}
2318

2419
export async function testFixtures(
@@ -37,7 +32,7 @@ export async function testFixtures(
3732
{
3833
params,
3934
promise,
40-
expect = globalExpect,
35+
concurrent,
4136
...globOptions
4237
}: GlobOptions & FixtureOptions = {},
4338
) {
@@ -78,7 +73,11 @@ export async function testFixtures(
7873
return () => {
7974
for (const value of values) {
8075
const testName = getName(name, value)
81-
test.skipIf(isSkip?.(testName))(testName, async () => {
76+
let testFn = test.skipIf(isSkip?.(testName))
77+
if (concurrent) {
78+
testFn = testFn.concurrent
79+
}
80+
testFn(testName, async ({ expect }) => {
8281
const currArgs = { ...args, [name]: value }
8382
const execute = () =>
8483
cb(

‎tests/__snapshots__/expectFilesSnapshot.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## bar.js
2+
3+
```js
4+
export const bar = 2
5+
6+
```
17
## main.js
28

39
```js

‎tests/__snapshots__/index.test.ts.snap

+2
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,6 @@ export { foo };
88
"
99
`;
1010

11+
exports[`testFixtures > tests/fixtures/bar.js 1`] = `"ok"`;
12+
1113
exports[`testFixtures > tests/fixtures/main.js 1`] = `"ok"`;

‎tests/fixtures/bar.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const bar = 2

‎tests/index.test.ts

+16-8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { normalizePath } from '@rollup/pluginutils'
21
import { describe, expect, test } from 'vitest'
32
import { rollupBuild, testFixtures } from '../src'
43

@@ -8,11 +7,20 @@ test('rollupBuild', async () => {
87
})
98

109
describe('testFixtures', async () => {
11-
await testFixtures('tests/fixtures/*.js', (args, id) => {
12-
expect(args).toEqual({
13-
'tests/fixtures/main.js': undefined,
14-
})
15-
expect(normalizePath(id)).contain('tests/fixtures/main.js')
16-
return 'ok'
17-
})
10+
await testFixtures(
11+
'tests/fixtures/*.js',
12+
(args, id) => {
13+
if (id.endsWith('bar.js')) {
14+
expect(args).toEqual({
15+
'tests/fixtures/bar.js': undefined,
16+
})
17+
} else {
18+
expect(args).toEqual({
19+
'tests/fixtures/main.js': undefined,
20+
})
21+
}
22+
return 'ok'
23+
},
24+
{ concurrent: true },
25+
)
1826
})

‎tests/snapshot.test.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import process from 'node:process'
33
import { expect, test } from 'vitest'
44
import { expectFilesSnapshot, outputToSnapshot } from '../src'
55

6-
test('outputToSnapshot', () => {
6+
test.concurrent('outputToSnapshot', () => {
77
const result = outputToSnapshot([
88
{
99
type: 'chunk',
@@ -14,9 +14,10 @@ test('outputToSnapshot', () => {
1414
expect(result).contain('[CWD]')
1515
})
1616

17-
test('expectFilesSnapshot', async () => {
17+
test.concurrent('expectFilesSnapshot', async ({ expect }) => {
1818
await expectFilesSnapshot(
1919
path.resolve(__dirname, 'fixtures'),
2020
path.resolve(__dirname, '__snapshots__/expectFilesSnapshot.md'),
21+
{ expect },
2122
)
2223
})

0 commit comments

Comments
 (0)
Please sign in to comment.