Skip to content

Commit

Permalink
test: move some snapshot test
Browse files Browse the repository at this point in the history
  • Loading branch information
hi-ogawa committed Oct 31, 2024
1 parent de9b88e commit 620e2ce
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 34 deletions.
6 changes: 4 additions & 2 deletions test/snapshots/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
"type": "module",
"private": true,
"scripts": {
"test": "pnpm run test:generate && pnpm run test:update && pnpm run test:snaps",
"test:generate": "node tools/generate-inline-test.mjs",
"test": "pnpm run test:generate && pnpm run test:update && pnpm test:update-new && pnpm test:update-none && pnpm run test:snaps",
"test:generate": "rm -rf ./test-update && cp -r ./test/fixtures/test-update ./test-update",
"test:snaps": "vitest run --dir test",
"test:update": "vitest run -u --dir test-update",
"test:update-none": "CI=true vitest run --dir test-update",
"test:update-new": "CI=false vitest run --dir test-update",
"coverage": "vitest run --coverage"
},
"dependencies": {
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,23 +1,6 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`concurrent snapshot update 1`] = `
"import { it } from 'vitest'
it.concurrent('1st', ({ expect }) => {
expect('hi1').toMatchInlineSnapshot(\`"hi1"\`)
})
it.concurrent('2nd', ({ expect }) => {
expect('hi2').toMatchInlineSnapshot(\`"hi2"\`)
})
it.concurrent('3rd', ({ expect }) => {
expect('hi3').toMatchInlineSnapshot(\`"hi3"\`)
})
"
`;
exports[`js snapshots generated correctly 1`] = `
exports[`inline.test.js 1`] = `
"import { describe, expect, test } from 'vitest'
// when snapshots are generated Vitest reruns \`toMatchInlineSnapshot\` checks
Expand Down Expand Up @@ -89,3 +72,20 @@ describe('snapshots with properties', () => {
})
"
`;
exports[`inline-concurrent.test.js 1`] = `
"import { it } from 'vitest'
it.concurrent('1st', ({ expect }) => {
expect('hi1').toMatchInlineSnapshot(\`"hi1"\`)
})
it.concurrent('2nd', ({ expect }) => {
expect('hi2').toMatchInlineSnapshot(\`"hi2"\`)
})
it.concurrent('3rd', ({ expect }) => {
expect('hi3').toMatchInlineSnapshot(\`"hi3"\`)
})
"
`;
14 changes: 0 additions & 14 deletions test/snapshots/test/snapshots.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import fs from 'node:fs/promises'
import pathe from 'pathe'
import { expect, test } from 'vitest'

import { editFile, runVitest } from '../../test-utils'
Expand All @@ -14,18 +12,6 @@ test('non default snapshot format', () => {
`)
})

test('js snapshots generated correctly', async () => {
const path = pathe.resolve(__dirname, '../test-update/snapshots-inline-js.test.js')
const content = await fs.readFile(path, 'utf8')
expect(content).toMatchSnapshot()
})

test('concurrent snapshot update', async () => {
const path = pathe.resolve(__dirname, '../test-update/inline-test-template-concurrent.test.js')
const content = await fs.readFile(path, 'utf8')
expect(content).toMatchSnapshot()
})

test('--update works for workspace project', async () => {
// setup wrong snapshot value
editFile(
Expand Down
9 changes: 9 additions & 0 deletions test/snapshots/test/test-update.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import fs from 'node:fs/promises'
import { join } from 'node:path'
import { expect, test } from 'vitest'

const files = await fs.readdir(join(import.meta.dirname, '../test-update'))
test.for(files)("%s", async (file) => {

Check failure on line 6 in test/snapshots/test/test-update.test.ts

View workflow job for this annotation

GitHub Actions / Lint: node-latest, ubuntu-latest

Strings must use singlequote
const content = await fs.readFile(join(import.meta.dirname, '../test-update', file), 'utf8')
expect(content).toMatchSnapshot()
})

0 comments on commit 620e2ce

Please sign in to comment.