-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(config): add
snapshotSerializers
option (#5092)
- Loading branch information
Showing
16 changed files
with
166 additions
and
8 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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
export { startTests, processError } from '@vitest/runner' | ||
export { setupCommonEnv, loadDiffConfig } from './runtime/setup-common' | ||
export { setupCommonEnv, loadDiffConfig, loadSnapshotSerializers } from './runtime/setup-common' | ||
export { takeCoverageInsideWorker, stopCoverageInsideWorker, getCoverageProvider, startCoverageInsideWorker } from './integrations/coverage' |
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
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
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 |
---|---|---|
|
@@ -6,4 +6,5 @@ export type { | |
SnapshotResult, | ||
UncheckedSnapshot, | ||
SnapshotSummary, | ||
SnapshotSerializer, | ||
} from '@vitest/snapshot' |
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,11 @@ | ||
import { expect, test } from 'vitest' | ||
import { runVitest } from '../../test-utils' | ||
|
||
test('it should pass', async () => { | ||
const { stdout, stderr } = await runVitest({ | ||
root: 'test/fixtures/custom-serializers', | ||
}) | ||
|
||
expect(stdout).toContain('✓ custom-serializers.test.ts >') | ||
expect(stderr).toBe('') | ||
}) |
23 changes: 23 additions & 0 deletions
23
test/snapshots/test/fixtures/custom-serializers/custom-serializers.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,23 @@ | ||
import { test, expect } from "vitest"; | ||
|
||
test("", () => { | ||
expect({foo: { | ||
a: 1, | ||
b: 2 | ||
}}).toMatchInlineSnapshot(` | ||
Pretty foo: { | ||
"a": 1, | ||
"b": 2, | ||
} | ||
`); | ||
|
||
expect({bar: { | ||
a: 1, | ||
b: 2 | ||
}}).toMatchInlineSnapshot(` | ||
Pretty bar: { | ||
"a": 1, | ||
"b": 2, | ||
} | ||
`); | ||
}) |
14 changes: 14 additions & 0 deletions
14
test/snapshots/test/fixtures/custom-serializers/serializer-1.js
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,14 @@ | ||
export default { | ||
serialize(val, config, indentation, depth, refs, printer) { | ||
return `Pretty foo: ${printer( | ||
val.foo, | ||
config, | ||
indentation, | ||
depth, | ||
refs, | ||
)}` | ||
}, | ||
test(val) { | ||
return val && Object.prototype.hasOwnProperty.call(val, 'foo') | ||
}, | ||
} |
16 changes: 16 additions & 0 deletions
16
test/snapshots/test/fixtures/custom-serializers/serializer-2.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,16 @@ | ||
import { SnapshotSerializer } from 'vitest' | ||
|
||
export default { | ||
serialize(val, config, indentation, depth, refs, printer) { | ||
return `Pretty bar: ${printer( | ||
val.bar, | ||
config, | ||
indentation, | ||
depth, | ||
refs, | ||
)}` | ||
}, | ||
test(val) { | ||
return val && Object.prototype.hasOwnProperty.call(val, 'bar') | ||
}, | ||
} satisfies SnapshotSerializer |
7 changes: 7 additions & 0 deletions
7
test/snapshots/test/fixtures/custom-serializers/vitest.config.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,7 @@ | ||
import { defineConfig } from "vitest/config"; | ||
|
||
export default defineConfig({ | ||
test: { | ||
snapshotSerializers: ['./serializer-1.js', './serializer-2.ts'] | ||
} | ||
}) |