-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: compat for jest-image-snapshot (#7390)
- Loading branch information
Showing
8 changed files
with
176 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,5 +14,8 @@ | |
}, | ||
"dependencies": { | ||
"vitest": "workspace:*" | ||
}, | ||
"devDependencies": { | ||
"jest-image-snapshot": "^6.4.0" | ||
} | ||
} |
Binary file added
BIN
+840 Bytes
...e-snapshot/__image_snapshots__/basic-test-ts-to-match-image-snapshot-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 19 additions & 0 deletions
19
test/snapshots/test/fixtures/jest-image-snapshot/basic.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { expect, it } from "vitest"; | ||
import fs from "fs"; | ||
|
||
// @ts-expect-error no type | ||
import { toMatchImageSnapshot } from "jest-image-snapshot"; | ||
expect.extend({ toMatchImageSnapshot }); | ||
|
||
declare module 'vitest' { | ||
interface Assertion<T = any> { | ||
toMatchImageSnapshot(): void | ||
} | ||
} | ||
|
||
// pnpm -C test/snapshots test:fixtures --root test/fixtures/jest-image-snapshot | ||
|
||
it("toMatchImageSnapshot", async () => { | ||
const file = new URL("./test.png", import.meta.url) | ||
expect(fs.readFileSync(file)).toMatchImageSnapshot(); | ||
}); |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import fs from 'node:fs' | ||
import { join } from 'node:path' | ||
import { expect, test } from 'vitest' | ||
import { runVitest } from '../../test-utils' | ||
|
||
test('jest-image-sapshot', async () => { | ||
// cleanup snapshot | ||
const root = join(import.meta.dirname, 'fixtures/jest-image-snapshot') | ||
fs.rmSync(join(root, '__image_snapshots__'), { recursive: true, force: true }) | ||
|
||
// write snapshot | ||
let vitest = await runVitest({ | ||
root, | ||
update: true, | ||
}) | ||
expect(vitest.stderr).toBe('') | ||
expect(vitest.ctx?.snapshot.summary).toMatchInlineSnapshot(` | ||
Object { | ||
"added": 1, | ||
"didUpdate": true, | ||
"failure": false, | ||
"filesAdded": 1, | ||
"filesRemoved": 0, | ||
"filesRemovedList": Array [], | ||
"filesUnmatched": 0, | ||
"filesUpdated": 0, | ||
"matched": 0, | ||
"total": 1, | ||
"unchecked": 0, | ||
"uncheckedKeysByFile": Array [], | ||
"unmatched": 0, | ||
"updated": 0, | ||
} | ||
`) | ||
expect(fs.existsSync(join(root, '__image_snapshots__/basic-test-ts-to-match-image-snapshot-1-snap.png'))).toBe(true) | ||
|
||
// match existing snapshot | ||
vitest = await runVitest({ | ||
root, | ||
update: false, | ||
}) | ||
expect(vitest.stderr).toBe('') | ||
expect(vitest.ctx?.snapshot.summary).toMatchInlineSnapshot(` | ||
Object { | ||
"added": 0, | ||
"didUpdate": false, | ||
"failure": false, | ||
"filesAdded": 0, | ||
"filesRemoved": 0, | ||
"filesRemovedList": Array [], | ||
"filesUnmatched": 0, | ||
"filesUpdated": 0, | ||
"matched": 1, | ||
"total": 1, | ||
"unchecked": 0, | ||
"uncheckedKeysByFile": Array [], | ||
"unmatched": 0, | ||
"updated": 0, | ||
} | ||
`) | ||
expect(fs.existsSync(join(root, '__image_snapshots__/basic-test-ts-to-match-image-snapshot-1-snap.png'))).toBe(true) | ||
}) |