Skip to content

Commit 44978cd

Browse files
committedJan 24, 2025··
feat: can pass expect function
1 parent 03d4e47 commit 44978cd

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed
 

‎src/fixture.ts

+13-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@ 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 { describe, expect, test } from 'vitest'
5+
import {
6+
describe,
7+
expect as globalExpect,
8+
test,
9+
type ExpectStatic,
10+
} from 'vitest'
611

712
type SkipFn = (testName: string) => boolean | Promise<boolean>
813
let isSkip: SkipFn | undefined
@@ -13,6 +18,7 @@ export function testFixturesSkip(fn: SkipFn): void {
1318
export interface FixtureOptions {
1419
params?: [name: string, values?: any[]][]
1520
promise?: boolean
21+
expect?: ExpectStatic
1622
}
1723

1824
export async function testFixtures(
@@ -28,7 +34,12 @@ export async function testFixtures(
2834
export async function testFixtures(
2935
globsOrFiles: string | string[] | Record<string, string>,
3036
cb: (args: Record<string, any>, id: string, code: string) => any,
31-
{ params, promise, ...globOptions }: GlobOptions & FixtureOptions = {},
37+
{
38+
params,
39+
promise,
40+
expect = globalExpect,
41+
...globOptions
42+
}: GlobOptions & FixtureOptions = {},
3243
) {
3344
let files: Record<string, string | undefined>
3445

‎src/snapshot.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { readFile } from 'node:fs/promises'
22
import path from 'node:path'
33
import process from 'node:process'
44
import { glob } from 'tinyglobby'
5-
import { expect } from 'vitest'
5+
import { expect as globalExpect, type ExpectStatic } from 'vitest'
66
import type { OutputFile } from 'esbuild'
77
import type { RolldownOutputAsset, RolldownOutputChunk } from 'rolldown'
88
import type { OutputAsset, OutputChunk } from 'rollup'
@@ -41,7 +41,10 @@ export function outputToSnapshot(
4141
export async function expectFilesSnapshot(
4242
sourceDir: string,
4343
snapshotFile: string,
44-
pattern: string = '**/*',
44+
{
45+
pattern = '**/*',
46+
expect = globalExpect,
47+
}: { pattern?: string; expect?: ExpectStatic } = {},
4548
): Promise<{
4649
files: string[]
4750
fileMap: any

0 commit comments

Comments
 (0)
Please sign in to comment.