From 26c470d0880f4a4a2cbeef873e9faf2c9bb595d5 Mon Sep 17 00:00:00 2001 From: Hiroshi Ogawa Date: Thu, 8 Aug 2024 09:46:57 +0900 Subject: [PATCH 1/3] test: test importing a file generated during test --- .../fixtures/fs-cached-check/basic.test.ts | 14 ++++++++++ test/config/test/fs-cached-check.test.ts | 27 +++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 test/config/fixtures/fs-cached-check/basic.test.ts create mode 100644 test/config/test/fs-cached-check.test.ts diff --git a/test/config/fixtures/fs-cached-check/basic.test.ts b/test/config/fixtures/fs-cached-check/basic.test.ts new file mode 100644 index 000000000000..a4502a5f8dab --- /dev/null +++ b/test/config/fixtures/fs-cached-check/basic.test.ts @@ -0,0 +1,14 @@ +import { expect, test } from "vitest" +import fs from "node:fs" +import path from "node:path" + +test("import a generated file", async () => { + const dist = path.join(import.meta.dirname, "dist"); + await fs.promises.mkdir(dist, { recursive: true }); + await fs.promises.writeFile(path.join(dist, "generated.js"), `export default 'ok'`); + + // @ts-ignore generated + const mod = await import("./dist/generated.js") + + expect(mod.default).toBe("ok"); +}) diff --git a/test/config/test/fs-cached-check.test.ts b/test/config/test/fs-cached-check.test.ts new file mode 100644 index 000000000000..94dc7414bb14 --- /dev/null +++ b/test/config/test/fs-cached-check.test.ts @@ -0,0 +1,27 @@ +import { expect, test } from "vitest"; +import { runVitest } from "../../test-utils"; +import fs from "node:fs" +import path from "node:path" + +test("fs cache", async () => { + // ensure removed + const root = path.resolve("fixtures/fs-cached-check") + await fs.promises.rm(path.join(root, "dist"), { recursive: true, force: true }) + + const { stderr, exitCode } = await runVitest( + { + root, + }, + undefined, + undefined, + { + server: { + fs: { + cachedChecks: false, + }, + }, + }, + ); + expect(stderr).toBe('') + expect(exitCode).toBe(0) +}); From 0c197f5b84e030a8000c207a84c4c00f9d6540bb Mon Sep 17 00:00:00 2001 From: Hiroshi Ogawa Date: Thu, 8 Aug 2024 09:52:05 +0900 Subject: [PATCH 2/3] chore: lint --- test/config/test/fs-cached-check.test.ts | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/test/config/test/fs-cached-check.test.ts b/test/config/test/fs-cached-check.test.ts index 94dc7414bb14..d9e0a7b8f9d4 100644 --- a/test/config/test/fs-cached-check.test.ts +++ b/test/config/test/fs-cached-check.test.ts @@ -1,12 +1,12 @@ -import { expect, test } from "vitest"; -import { runVitest } from "../../test-utils"; -import fs from "node:fs" -import path from "node:path" +import fs from 'node:fs' +import path from 'node:path' +import { expect, test } from 'vitest' +import { runVitest } from '../../test-utils' -test("fs cache", async () => { - // ensure removed - const root = path.resolve("fixtures/fs-cached-check") - await fs.promises.rm(path.join(root, "dist"), { recursive: true, force: true }) +test('import a generated file', async () => { + // ensure removed first + const root = path.resolve('fixtures/fs-cached-check') + await fs.promises.rm(path.join(root, 'dist'), { recursive: true, force: true }) const { stderr, exitCode } = await runVitest( { @@ -21,7 +21,7 @@ test("fs cache", async () => { }, }, }, - ); + ) expect(stderr).toBe('') expect(exitCode).toBe(0) -}); +}) From 80b3afca155481c429fb8c6b7066bed395da4214 Mon Sep 17 00:00:00 2001 From: Vladimir Sheremet Date: Tue, 13 Aug 2024 13:04:06 +0200 Subject: [PATCH 3/3] chore: remove manual fs.cachedChecks: false --- test/config/test/fs-cached-check.test.ts | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/test/config/test/fs-cached-check.test.ts b/test/config/test/fs-cached-check.test.ts index d9e0a7b8f9d4..cfc05e20f45b 100644 --- a/test/config/test/fs-cached-check.test.ts +++ b/test/config/test/fs-cached-check.test.ts @@ -8,20 +8,7 @@ test('import a generated file', async () => { const root = path.resolve('fixtures/fs-cached-check') await fs.promises.rm(path.join(root, 'dist'), { recursive: true, force: true }) - const { stderr, exitCode } = await runVitest( - { - root, - }, - undefined, - undefined, - { - server: { - fs: { - cachedChecks: false, - }, - }, - }, - ) + const { stderr, exitCode } = await runVitest({ root }) expect(stderr).toBe('') expect(exitCode).toBe(0) })