Skip to content

Commit

Permalink
fix: config.root priority (#1164)
Browse files Browse the repository at this point in the history
* fix: config.root priority

* test: add vite config root test
  • Loading branch information
tmkx committed Apr 19, 2022
1 parent 0c9137d commit d8e0493
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 2 deletions.
3 changes: 1 addition & 2 deletions packages/vitest/src/node/create.ts
Expand Up @@ -16,15 +16,14 @@ 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
mode: options.mode || process.env.NODE_ENV || 'test',
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()
Expand Down
8 changes: 8 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions 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:*"
}
}
1 change: 1 addition & 0 deletions test/vite-config/src/index.html
@@ -0,0 +1 @@
Hello Vitest
5 changes: 5 additions & 0 deletions test/vite-config/src/test/root.test.ts
@@ -0,0 +1,5 @@
import { it } from 'vitest'

it('should work', () => {
//
})
19 changes: 19 additions & 0 deletions test/vite-config/vite.config.ts
@@ -0,0 +1,19 @@
/// <reference types="vitest" />

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)
},
},
],
})

0 comments on commit d8e0493

Please sign in to comment.