From 4a69ec17b6375dcb282d018291d26d59642f0fbc Mon Sep 17 00:00:00 2001 From: Hiroshi Ogawa Date: Thu, 31 Oct 2024 16:53:39 +0900 Subject: [PATCH] test: move some snapshot test --- test/snapshots/package.json | 6 ++-- ...rent.test.js => inline-concurrent.test.js} | 0 ...shots-inline-js.test.js => inline.test.js} | 0 ....test.ts.snap => test-update.test.ts.snap} | 36 +++++++++---------- .../test-update/inline-concurrent.test.js} | 0 .../fixtures/test-update/inline.test.js} | 0 test/snapshots/test/snapshots.test.ts | 14 -------- test/snapshots/test/test-update.test.ts | 10 ++++++ 8 files changed, 32 insertions(+), 34 deletions(-) rename test/snapshots/test-update/{inline-test-template-concurrent.test.js => inline-concurrent.test.js} (100%) rename test/snapshots/test-update/{snapshots-inline-js.test.js => inline.test.js} (100%) rename test/snapshots/test/__snapshots__/{snapshots.test.ts.snap => test-update.test.ts.snap} (95%) rename test/snapshots/{tools/inline-test-template-concurrent.js => test/fixtures/test-update/inline-concurrent.test.js} (100%) rename test/snapshots/{tools/inline-test-template.js => test/fixtures/test-update/inline.test.js} (100%) create mode 100644 test/snapshots/test/test-update.test.ts diff --git a/test/snapshots/package.json b/test/snapshots/package.json index 2e062a10cd7f..6b19ad617fcf 100644 --- a/test/snapshots/package.json +++ b/test/snapshots/package.json @@ -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": { diff --git a/test/snapshots/test-update/inline-test-template-concurrent.test.js b/test/snapshots/test-update/inline-concurrent.test.js similarity index 100% rename from test/snapshots/test-update/inline-test-template-concurrent.test.js rename to test/snapshots/test-update/inline-concurrent.test.js diff --git a/test/snapshots/test-update/snapshots-inline-js.test.js b/test/snapshots/test-update/inline.test.js similarity index 100% rename from test/snapshots/test-update/snapshots-inline-js.test.js rename to test/snapshots/test-update/inline.test.js diff --git a/test/snapshots/test/__snapshots__/snapshots.test.ts.snap b/test/snapshots/test/__snapshots__/test-update.test.ts.snap similarity index 95% rename from test/snapshots/test/__snapshots__/snapshots.test.ts.snap rename to test/snapshots/test/__snapshots__/test-update.test.ts.snap index d42ea091ab42..e03790dd1aed 100644 --- a/test/snapshots/test/__snapshots__/snapshots.test.ts.snap +++ b/test/snapshots/test/__snapshots__/test-update.test.ts.snap @@ -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 @@ -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"\`) +}) +" +`; diff --git a/test/snapshots/tools/inline-test-template-concurrent.js b/test/snapshots/test/fixtures/test-update/inline-concurrent.test.js similarity index 100% rename from test/snapshots/tools/inline-test-template-concurrent.js rename to test/snapshots/test/fixtures/test-update/inline-concurrent.test.js diff --git a/test/snapshots/tools/inline-test-template.js b/test/snapshots/test/fixtures/test-update/inline.test.js similarity index 100% rename from test/snapshots/tools/inline-test-template.js rename to test/snapshots/test/fixtures/test-update/inline.test.js diff --git a/test/snapshots/test/snapshots.test.ts b/test/snapshots/test/snapshots.test.ts index 13556156b4c2..1f07adf0d2ec 100644 --- a/test/snapshots/test/snapshots.test.ts +++ b/test/snapshots/test/snapshots.test.ts @@ -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' @@ -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( diff --git a/test/snapshots/test/test-update.test.ts b/test/snapshots/test/test-update.test.ts new file mode 100644 index 000000000000..487a3846285c --- /dev/null +++ b/test/snapshots/test/test-update.test.ts @@ -0,0 +1,10 @@ +import fs from 'node:fs/promises' +import { join } from 'node:path' +import { expect, test } from 'vitest' + +const dir = join(import.meta.dirname, '../test-update') +const files = await fs.readdir(dir) +test.for(files)('%s', async (file) => { + const content = await fs.readFile(join(dir, file), 'utf8') + expect(content).toMatchSnapshot() +})