Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: generate inline snapshot test instead of using one
- Loading branch information
1 parent
f28591c
commit 73a722f
Showing
7 changed files
with
48 additions
and
18 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,25 @@ | ||
import { describe, expect, test } from 'vitest' | ||
import { validateNoSnapshots } from './validate-inline-js' | ||
|
||
// when snapshots are generated Vitest reruns `toMatchInlineSnapshot` checks | ||
// please, don't commit generated snapshots | ||
describe('snapshots are generated in correct order', async () => { | ||
await validateNoSnapshots(__filename) | ||
|
||
test('first snaphot', () => { | ||
expect({ foo: ['bar'] }).toMatchInlineSnapshot() | ||
expect({ foo: ['bar'] }).toMatchInlineSnapshot(` | ||
Object { | ||
"foo": Array [ | ||
"bar", | ||
], | ||
} | ||
`) | ||
}) | ||
|
||
test('second snapshot', () => { | ||
expect({ foo: ['zed'] }).toMatchInlineSnapshot() | ||
expect({ foo: ['zed'] }).toMatchInlineSnapshot(` | ||
Object { | ||
"foo": Array [ | ||
"zed", | ||
], | ||
} | ||
`) | ||
}) | ||
}) |
This file was deleted.
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
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,18 @@ | ||
import fs from 'fs/promises' | ||
import { fileURLToPath } from 'url' | ||
import pathe from 'pathe' | ||
|
||
const dirname = pathe.dirname(fileURLToPath(import.meta.url)) | ||
|
||
export async function generateInlineTest(templatePath, testpath) { | ||
const template = await fs.readFile(templatePath, 'utf8') | ||
await fs.writeFile(testpath, template) | ||
console.log(`Generated ${testpath}`) | ||
} | ||
|
||
const filepath = pathe.resolve(dirname, '../test-update/shapshots-inline-js.test.js') | ||
const template = pathe.resolve(dirname, './inline-test-template.js'); | ||
|
||
(async () => { | ||
await generateInlineTest(template, filepath) | ||
})() |
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,13 @@ | ||
import { describe, expect, test } from 'vitest' | ||
|
||
// when snapshots are generated Vitest reruns `toMatchInlineSnapshot` checks | ||
// please, don't commit generated snapshots | ||
describe('snapshots are generated in correct order', async () => { | ||
test('first snaphot', () => { | ||
expect({ foo: ['bar'] }).toMatchInlineSnapshot() | ||
}) | ||
|
||
test('second snapshot', () => { | ||
expect({ foo: ['zed'] }).toMatchInlineSnapshot() | ||
}) | ||
}) |