|
| 1 | +import fs from 'node:fs' |
| 2 | +import { join } from 'node:path' |
| 3 | +import { expect, test } from 'vitest' |
| 4 | +import { runVitest } from '../../test-utils' |
| 5 | + |
| 6 | +test('compareKeys', async () => { |
| 7 | + const root = join(import.meta.dirname, 'fixtures/compare-keys') |
| 8 | + fs.rmSync(join(root, '__snapshots__'), { recursive: true, force: true }) |
| 9 | + |
| 10 | + // compareKeys null |
| 11 | + let vitest = await runVitest({ |
| 12 | + root, |
| 13 | + update: true, |
| 14 | + snapshotFormat: { |
| 15 | + compareKeys: null, |
| 16 | + }, |
| 17 | + }) |
| 18 | + expect(vitest.stderr).toBe('') |
| 19 | + expect(fs.readFileSync(join(root, '__snapshots__/basic.test.ts.snap'), 'utf-8')).toMatchInlineSnapshot(` |
| 20 | + "// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html |
| 21 | +
|
| 22 | + exports[\`compareKeys 1\`] = \` |
| 23 | + { |
| 24 | + "a": 1, |
| 25 | + "b": 2, |
| 26 | + "c": 3, |
| 27 | + } |
| 28 | + \`; |
| 29 | +
|
| 30 | + exports[\`compareKeys 2\`] = \` |
| 31 | + { |
| 32 | + "c": 1, |
| 33 | + "b": 2, |
| 34 | + "a": 3, |
| 35 | + } |
| 36 | + \`; |
| 37 | +
|
| 38 | + exports[\`compareKeys 3\`] = \` |
| 39 | + { |
| 40 | + "b": 1, |
| 41 | + "a": 2, |
| 42 | + "c": 3, |
| 43 | + } |
| 44 | + \`; |
| 45 | + " |
| 46 | + `) |
| 47 | + |
| 48 | + // compareKeys undefined |
| 49 | + vitest = await runVitest({ |
| 50 | + root, |
| 51 | + update: true, |
| 52 | + snapshotFormat: { |
| 53 | + compareKeys: undefined, |
| 54 | + }, |
| 55 | + }) |
| 56 | + expect(vitest.stderr).toBe('') |
| 57 | + expect(fs.readFileSync(join(root, '__snapshots__/basic.test.ts.snap'), 'utf-8')).toMatchInlineSnapshot(` |
| 58 | + "// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html |
| 59 | +
|
| 60 | + exports[\`compareKeys 1\`] = \` |
| 61 | + { |
| 62 | + "a": 1, |
| 63 | + "b": 2, |
| 64 | + "c": 3, |
| 65 | + } |
| 66 | + \`; |
| 67 | +
|
| 68 | + exports[\`compareKeys 2\`] = \` |
| 69 | + { |
| 70 | + "a": 3, |
| 71 | + "b": 2, |
| 72 | + "c": 1, |
| 73 | + } |
| 74 | + \`; |
| 75 | +
|
| 76 | + exports[\`compareKeys 3\`] = \` |
| 77 | + { |
| 78 | + "a": 2, |
| 79 | + "b": 1, |
| 80 | + "c": 3, |
| 81 | + } |
| 82 | + \`; |
| 83 | + " |
| 84 | + `) |
| 85 | +}) |
0 commit comments