Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Root option ignored if vite config also has root option #2050

Closed
6 tasks done
kleinfreund opened this issue Sep 16, 2022 · 2 comments · Fixed by #2637
Closed
6 tasks done

Root option ignored if vite config also has root option #2050

kleinfreund opened this issue Sep 16, 2022 · 2 comments · Fixed by #2637

Comments

@kleinfreund
Copy link
Contributor

kleinfreund commented Sep 16, 2022

Describe the bug

It seems that vitest completely ignores a root option under the test property in a Vite configuration file if said file also has a root option at its root.

export default defineConfig({
	root: './docs',

	test: {
		root: '.',
	},
})

No matter what I set options.test.root to, vitest will always try and find test files in options.root rather than options.test.root. In my project, this fails because options.root and options.test.root are sibling directories.

This can be considered a bit of an edge case. I'm a Vue plugin developer and want to have a basic demo website in ./docs (i.e. that's where my index.html is) and my plugin source code in ./src. I don't want to maintain two separate Vite projects (one for docs; one for the plugin source) because Vue's architecture makes it impossible to test locally in this setup using npm link.

This was possibly introduced in #1164:

const server = await createServer(mergeConfig(config, mergeConfig(viteOverrides, { root: options.root })))

Workaround: Move the Vite entry points (in my case, the index.html file) into the project root. I don't like this because in my particular case, it makes for a weird project structure.

Reproduction

I'm happy to provide a minimal reproduction, but I think that the existence of #1158 and the following code serve as sufficient explanation for the behavior that I'm seeing.

const server = await createServer(mergeConfig(config, mergeConfig(viteOverrides, { root: options.root })))

Should Vitest behave this way? I think this not desirable. I think it prevents developers from locating their tests outside their general source directory (I don't do this personally, but I've seen it).

System Info

System:
    OS: Windows 10 10.0.22000
  Binaries:
    Node: 16.17.0 - C:\Program Files\nodejs\node.EXE
    npm: 8.19.2 - ~\dev\vue-accessible-color-picker\node_modules\.bin\npm.CMD
  npmPackages:
    @vitejs/plugin-vue: ^3.1.0 => 3.1.0
    vite: ^3.1.1 => 3.1.1
    vitest: ^0.23.2 => 0.23.2

Used Package Manager

npm

Validations

@kleinfreund
Copy link
Contributor Author

I was wrong in identifying which piece of code is responsible for what I'm describing.

It's this:

const resolved = {
...configDefaults,
...options,
root: viteConfig.root,
mode,
} as ResolvedConfig

Changing root: viteConfig.root, to root: options.root || viteConfig.root, fixes my issue.

@galvez
Copy link

galvez commented Jan 10, 2023

I have the same issue.

@github-actions github-actions bot locked and limited conversation to collaborators Jun 8, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants