From d8e0493e269811a3aa6506dab7f9e47d084216c3 Mon Sep 17 00:00:00 2001 From: Tmk Date: Tue, 19 Apr 2022 11:38:02 +0800 Subject: [PATCH] fix: config.root priority (#1164) * fix: config.root priority * test: add vite config root test --- packages/vitest/src/node/create.ts | 3 +-- pnpm-lock.yaml | 8 ++++++++ test/vite-config/package.json | 12 ++++++++++++ test/vite-config/src/index.html | 1 + test/vite-config/src/test/root.test.ts | 5 +++++ test/vite-config/vite.config.ts | 19 +++++++++++++++++++ 6 files changed, 46 insertions(+), 2 deletions(-) create mode 100644 test/vite-config/package.json create mode 100644 test/vite-config/src/index.html create mode 100644 test/vite-config/src/test/root.test.ts create mode 100644 test/vite-config/vite.config.ts diff --git a/packages/vitest/src/node/create.ts b/packages/vitest/src/node/create.ts index f8adeded7ed8..8f18080f7c3c 100644 --- a/packages/vitest/src/node/create.ts +++ b/packages/vitest/src/node/create.ts @@ -16,7 +16,6 @@ export async function createVitest(options: UserConfig, viteOverrides: ViteUserC : await findUp(configFiles, { cwd: root } as any) const config: ViteInlineConfig = { - root, logLevel: 'error', configFile: configPath, // this will make "mode" = "test" inside defineConfig @@ -24,7 +23,7 @@ export async function createVitest(options: UserConfig, viteOverrides: ViteUserC plugins: await VitestPlugin(options, ctx), } - const server = await createServer(mergeConfig(config, viteOverrides)) + const server = await createServer(mergeConfig(config, mergeConfig(viteOverrides, { root: options.root }))) if (ctx.config.api?.port) await server.listen() diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index f0b5dd139f18..4186a999714e 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -811,6 +811,14 @@ importers: test/snapshots: specifiers: {} + test/vite-config: + specifiers: + pathe: ^0.2.0 + vitest: workspace:* + devDependencies: + pathe: 0.2.0 + vitest: link:../../packages/vitest + test/web-worker: specifiers: '@vitest/web-worker': workspace:* diff --git a/test/vite-config/package.json b/test/vite-config/package.json new file mode 100644 index 000000000000..f635dace48a5 --- /dev/null +++ b/test/vite-config/package.json @@ -0,0 +1,12 @@ +{ + "name": "@vitest/test-vite-config", + "private": true, + "scripts": { + "test": "vitest", + "coverage": "vitest run --coverage" + }, + "devDependencies": { + "pathe": "^0.2.0", + "vitest": "workspace:*" + } +} diff --git a/test/vite-config/src/index.html b/test/vite-config/src/index.html new file mode 100644 index 000000000000..4676e1058a0e --- /dev/null +++ b/test/vite-config/src/index.html @@ -0,0 +1 @@ +Hello Vitest diff --git a/test/vite-config/src/test/root.test.ts b/test/vite-config/src/test/root.test.ts new file mode 100644 index 000000000000..eabf33a1e79e --- /dev/null +++ b/test/vite-config/src/test/root.test.ts @@ -0,0 +1,5 @@ +import { it } from 'vitest' + +it('should work', () => { + // +}) diff --git a/test/vite-config/vite.config.ts b/test/vite-config/vite.config.ts new file mode 100644 index 000000000000..2335424a572b --- /dev/null +++ b/test/vite-config/vite.config.ts @@ -0,0 +1,19 @@ +/// + +import assert from 'assert' +import { join } from 'pathe' +import { defineConfig } from 'vite' + +const configRoot = join(__dirname, 'src') + +export default defineConfig({ + root: configRoot, + plugins: [ + { + name: 'root-checker', + configResolved(config) { + assert.equal(config.root, configRoot) + }, + }, + ], +})