mirror of
https://github.com/vitest-dev/vitest.git
synced 2025-12-08 18:26:03 +00:00
feat: Export snapshot state to expect.extend. (#1378)
This commit is contained in:
parent
17939379ed
commit
4ec0a76f6d
5
examples/image-snapshot/README.md
Normal file
5
examples/image-snapshot/README.md
Normal file
@ -0,0 +1,5 @@
|
||||
# Vitest Demo
|
||||
|
||||
Run `npm test` and change a test or source code to see HMR in action!
|
||||
|
||||
Learn more at https://vitest.dev
|
||||
21
examples/image-snapshot/package.json
Normal file
21
examples/image-snapshot/package.json
Normal file
@ -0,0 +1,21 @@
|
||||
{
|
||||
"name": "@vitest/example-image-snapshot",
|
||||
"type": "module",
|
||||
"private": true,
|
||||
"license": "MIT",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "vitest",
|
||||
"test:ui": "vitest --ui",
|
||||
"test:run": "vitest run"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@vitest/ui": "latest",
|
||||
"jest-image-snapshot": "^4.5.1",
|
||||
"vite": "^2.9.9",
|
||||
"vitest": "latest"
|
||||
},
|
||||
"stackblitz": {
|
||||
"startCommand": "npm run test:ui"
|
||||
}
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 5.2 KiB |
17
examples/image-snapshot/test/basic.test.ts
Normal file
17
examples/image-snapshot/test/basic.test.ts
Normal file
@ -0,0 +1,17 @@
|
||||
import { readFileSync } from 'fs'
|
||||
import { expect, test } from 'vitest'
|
||||
import { toMatchImageSnapshot } from 'jest-image-snapshot'
|
||||
|
||||
declare global {
|
||||
namespace jest {
|
||||
interface Matchers<R> {
|
||||
toMatchImageSnapshot(): R
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
expect.extend({ toMatchImageSnapshot })
|
||||
|
||||
test('image snapshot', () => {
|
||||
expect(readFileSync('./test/stubs/input-image.png')).toMatchImageSnapshot()
|
||||
})
|
||||
BIN
examples/image-snapshot/test/stubs/input-image.png
Normal file
BIN
examples/image-snapshot/test/stubs/input-image.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 5.2 KiB |
12
examples/image-snapshot/vite.config.ts
Normal file
12
examples/image-snapshot/vite.config.ts
Normal file
@ -0,0 +1,12 @@
|
||||
/// <reference types="vitest" />
|
||||
|
||||
// Configure Vitest (https://vitest.dev/config/)
|
||||
|
||||
import { defineConfig } from 'vite'
|
||||
|
||||
export default defineConfig({
|
||||
test: {
|
||||
/* for example, use global to avoid globals imports (describe, test, expect): */
|
||||
// globals: true,
|
||||
},
|
||||
})
|
||||
@ -5,6 +5,7 @@ import type {
|
||||
MatchersObject,
|
||||
SyncExpectationResult,
|
||||
} from '../../types/chai'
|
||||
import { getSnapshotClient } from '../snapshot/chai'
|
||||
import { AsymmetricMatcher } from './jest-asymmetric-matchers'
|
||||
import { getState } from './jest-expect'
|
||||
|
||||
@ -37,6 +38,7 @@ const getMatcherState = (assertion: Chai.AssertionStatic & Chai.Assertion) => {
|
||||
equals,
|
||||
// needed for built-in jest-snapshots, but we don't use it
|
||||
suppressedErrors: [],
|
||||
snapshotState: getSnapshotClient().snapshotState!,
|
||||
}
|
||||
|
||||
return {
|
||||
|
||||
@ -9,6 +9,7 @@ import type { use as chaiUse } from 'chai'
|
||||
*/
|
||||
|
||||
import type * as jestMatcherUtils from '../integrations/chai/jest-matcher-utils'
|
||||
import type SnapshotState from '../integrations/snapshot/port/state'
|
||||
|
||||
export type FirstFunctionArgument<T> = T extends (arg: infer A) => unknown ? A : never
|
||||
export type ChaiPlugin = FirstFunctionArgument<typeof chaiUse>
|
||||
@ -33,6 +34,7 @@ export interface MatcherState {
|
||||
isExpectingAssertionsError?: Error | null
|
||||
isNot: boolean
|
||||
promise: string
|
||||
snapshotState: SnapshotState
|
||||
suppressedErrors: Array<Error>
|
||||
testPath?: string
|
||||
utils: typeof jestMatcherUtils & {
|
||||
|
||||
1122
pnpm-lock.yaml
generated
1122
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user