Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: test for concurrent test suite not updating inline snapshots (WIP) #4783

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 19 additions & 0 deletions test/snapshots/test-update/snapshots-inline-concurrent-js.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { describe, it } from 'vitest'

describe.concurrent('suite name', () => {
it('snapshot 1', ({ expect }) => {
expect({ foo: 'foo' }).toMatchInlineSnapshot()
})

it('snapshot 2', ({ expect }) => {
expect({ foo: 'bar' }).toMatchInlineSnapshot()
})

it('snapshot 3', ({ expect }) => {
expect({ foo: 'qux' }).toMatchInlineSnapshot(`
Object {
"foo": "qux",
}
`)
})
})
31 changes: 31 additions & 0 deletions test/snapshots/test/__snapshots__/shapshots.test.ts.snap
Original file line number Diff line number Diff line change
@@ -1,5 +1,36 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`js inline concurrent snapshots generated correctly 1`] = `
"import { describe, it } from 'vitest'

describe('suite name', () => {
it('snapshot 1', ({ expect }) => {
expect({ foo: 'foo' }).toMatchInlineSnapshot(\`
Object {
"foo": "foo",
}
\`)
})

it('snapshot 2', ({ expect }) => {
expect({ foo: 'bar' }).toMatchInlineSnapshot(\`
Object {
"foo": "bar",
}
\`)
})

it('snapshot 3', ({ expect }) => {
expect({ foo: 'qux' }).toMatchInlineSnapshot(\`
Object {
"foo": "qux",
}
\`)
})
})
"
`;

exports[`js snapshots generated correctly 1`] = `
"import { describe, expect, test } from 'vitest'

Expand Down
6 changes: 6 additions & 0 deletions test/snapshots/test/shapshots.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,9 @@ test('js snapshots generated correctly', async () => {
const content = await fs.readFile(path, 'utf8')
expect(content).toMatchSnapshot()
})

test('js inline concurrent snapshots generated correctly', async () => {
const path = pathe.resolve(__dirname, '../test-update/snapshots-inline-concurrent-js.test.js')
const content = await fs.readFile(path, 'utf8')
expect(content).toMatchSnapshot()
})
11 changes: 8 additions & 3 deletions test/snapshots/tools/generate-inline-test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,14 @@ export async function generateInlineTest(templatePath, testPath) {
console.warn(`Generated ${testPath}`)
}

const filepath = resolve(dir, '../test-update/snapshots-inline-js.test.js')
const template = resolve(dir, './inline-test-template.js');
const filepath1 = resolve(dir, '../test-update/snapshots-inline-js.test.js')
const template1 = resolve(dir, './inline-test-template.js')
const filepath2 = resolve(dir, '../test-update/snapshots-inline-concurrent-js.test.js')
const template2 = resolve(dir, './inline-test-template-concurrent.js');

(async () => {
await generateInlineTest(template, filepath)
await Promise.all([
generateInlineTest(template1, filepath1),
generateInlineTest(template2, filepath2),
])
})()
19 changes: 19 additions & 0 deletions test/snapshots/tools/inline-test-template-concurrent.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { describe, it } from 'vitest'

describe.concurrent('suite name', () => {
it('snapshot 1', ({ expect }) => {
expect({ foo: 'foo' }).toMatchInlineSnapshot()
})

it('snapshot 2', ({ expect }) => {
expect({ foo: 'bar' }).toMatchInlineSnapshot()
})

it('snapshot 3', ({ expect }) => {
expect({ foo: 'qux' }).toMatchInlineSnapshot(`
{
"foo": "qux",
}
`)
})
})