Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: sxzz/test-utils
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v0.5.3
Choose a base ref
...
head repository: sxzz/test-utils
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v0.5.4
Choose a head ref
  • 2 commits
  • 3 files changed
  • 1 contributor

Commits on Mar 28, 2025

  1. perf: import vitest on-demand

    sxzz committed Mar 28, 2025

    Verified

    This commit was signed with the committer’s verified signature.
    sxzz Kevin Deng 三咲智子
    Copy the full SHA
    924f7ce View commit details
  2. chore: release v0.5.4

    sxzz committed Mar 28, 2025

    Verified

    This commit was signed with the committer’s verified signature.
    sxzz Kevin Deng 三咲智子
    Copy the full SHA
    dbdf1b3 View commit details
Showing with 10 additions and 5 deletions.
  1. +1 −1 package.json
  2. +2 −1 src/fixture.ts
  3. +7 −3 src/snapshot.ts
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@sxzz/test-utils",
"version": "0.5.3",
"version": "0.5.4",
"packageManager": "pnpm@10.7.0",
"description": "Collection of common test utils.",
"type": "module",
3 changes: 2 additions & 1 deletion src/fixture.ts
Original file line number Diff line number Diff line change
@@ -2,7 +2,6 @@ import path from 'node:path'
import process from 'node:process'
import { glob, type GlobOptions } from 'tinyglobby'
import { normalizePath } from 'unplugin-utils'
import { describe, test } from 'vitest'

type SkipFn = (testName: string) => boolean | Promise<boolean>
let isSkip: SkipFn | undefined
@@ -38,6 +37,8 @@ export async function testFixtures(
...globOptions
}: GlobOptions & FixtureOptions = {},
) {
const { describe, test } = await import('vitest')

let files: Record<string, string | undefined>

if (typeof globsOrFiles === 'string' || Array.isArray(globsOrFiles)) {
10 changes: 7 additions & 3 deletions src/snapshot.ts
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@ import { readFile } from 'node:fs/promises'
import path from 'node:path'
import process from 'node:process'
import { glob } from 'tinyglobby'
import { expect as globalExpect, type ExpectStatic } from 'vitest'
import { type ExpectStatic } from 'vitest'

Check failure on line 5 in src/snapshot.ts

GitHub Actions / lint

TypeScript will only remove the inline type specifiers which will leave behind a side effect import at runtime. Convert this to a top-level type qualifier to properly remove the entire import
import type { OutputFile } from 'esbuild'
import type {
OutputAsset as RolldownOutputAsset,
@@ -46,13 +46,17 @@ export async function expectFilesSnapshot(
snapshotFile: string,
{
pattern = '**/*',
expect = globalExpect,
expect,
}: { pattern?: string; expect?: ExpectStatic } = {},
): Promise<{
files: string[]
fileMap: any
snapshot: string
}> {
if (!expect) {
expect = await import('vitest').then((m) => m.expect)
}

const cwd = process.cwd()
const files = (await glob(pattern, { cwd: sourceDir })).sort()
const fileMap = Object.fromEntries(
@@ -77,7 +81,7 @@ ${contents}
\`\`\``
})
.join('\n')
await expect(snapshot).toMatchFileSnapshot(snapshotFile)
await expect!(snapshot).toMatchFileSnapshot(snapshotFile)

return {
files,