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

feat!: move config from vitest/node to vitest/config #799

Merged
merged 2 commits into from Feb 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 6 additions & 6 deletions docs/config/index.md
Expand Up @@ -8,10 +8,10 @@
- Pass `--config` option to CLI, e.g. `vitest --config ./path/to/vitest.config.ts`
- Use `process.env.VITEST` or `mode` property on `defineConfig` (will be set to `test` if not overridden) to conditionally apply different configuration in `vite.config.ts`

To configure `vitest` itself, add `test` property in your Vite config. You'll also need to add a reference to Vitest types using a [triple slash command](https://www.typescriptlang.org/docs/handbook/triple-slash-directives.html#-reference-types-) at the top of your config file.
To configure `vitest` itself, add `test` property in your Vite config. You'll also need to add a reference to Vitest types using a [triple slash command](https://www.typescriptlang.org/docs/handbook/triple-slash-directives.html#-reference-types-) at the top of your config file, if you are importing `defineConfig` from `vite` itself.

```ts
import { defineConfig } from 'vitest/node'
import { defineConfig } from 'vitest/config'

export default defineConfig({
test: {
Expand All @@ -23,7 +23,7 @@ export default defineConfig({
You can retrieve Vitest's default options to expand them if needed:

```ts
import { defineConfig, configDefaults } from 'vitest/node'
import { defineConfig, configDefaults } from 'vitest/config'

export default defineConfig({
test: {
Expand Down Expand Up @@ -77,7 +77,7 @@ By default, `vitest` does not provide global APIs for explicitness. If you prefe

```ts
// vite.config.ts
import { defineConfig } from 'vitest/node'
import { defineConfig } from 'vitest/config'

export default defineConfig({
test: {
Expand All @@ -101,7 +101,7 @@ If you are already using [`unplugin-auto-import`](https://github.com/antfu/unplu

```ts
// vite.config.ts
import { defineConfig } from 'vitest/node'
import { defineConfig } from 'vitest/config'
import AutoImport from 'unplugin-auto-import/vite'

export default defineConfig({
Expand Down Expand Up @@ -350,7 +350,7 @@ Vite plugins will receive `ssr: false` flag when processing those files.
When you use JSX as component models other than React (e.g. Vue JSX or SolidJS), you might want to config as following to make `.tsx` / `.jsx` transformed as client-side components:

```ts
import { defineConfig } from 'vitest/node'
import { defineConfig } from 'vitest/config'

export default defineConfig({
test: {
Expand Down
4 changes: 2 additions & 2 deletions docs/guide/features.md
Expand Up @@ -212,7 +212,7 @@ After that, change the `environment` option in your config file:

```ts
// vite.config.ts
import { defineConfig } from 'vitest/node'
import { defineConfig } from 'vitest/config'

export default defineConfig({
test: {
Expand All @@ -238,7 +238,7 @@ To configure it, set `test.coverage` options in your config file:

```ts
// vite.config.ts
import { defineConfig } from 'vitest/node'
import { defineConfig } from 'vitest/config'

export default defineConfig({
test: {
Expand Down
5 changes: 2 additions & 3 deletions docs/guide/index.md
Expand Up @@ -37,11 +37,10 @@ One of the main advantages of Vitest is its unified configuration with Vite. If
- Pass `--config` option to CLI, e.g. `vitest --config ./path/to/vitest.config.ts`
- Use `process.env.VITEST` or `mode` property on `defineConfig` (will be set to `test` if not overridden) to conditionally apply different configuration in `vite.config.ts`

To configure `vitest` itself, add `test` property in your Vite config. You'll also need to add a reference to Vitest types using a [triple slash command](https://www.typescriptlang.org/docs/handbook/triple-slash-directives.html#-reference-types-) at the top of your config file.
To configure `vitest` itself, add `test` property in your Vite config. You'll also need to add a reference to Vitest types using a [triple slash command](https://www.typescriptlang.org/docs/handbook/triple-slash-directives.html#-reference-types-) at the top of your config file, if you are importing `defineConfig` from `vite` itself.

```ts
/// <reference types="vitest" />
import { defineConfig } from 'vitest/node'
import { defineConfig } from 'vitest/config'

export default defineConfig({
test: {
Expand Down
7 changes: 6 additions & 1 deletion packages/vitest/package.json
Expand Up @@ -35,6 +35,11 @@
"./node": {
"import": "./dist/node.js",
"types": "./dist/node.d.ts"
},
"./config": {
"import": "./dist/config.js",
"require": "./dist/config.cjs",
"types": "./dist/config.d.ts"
}
},
"main": "./dist/index.js",
Expand Down Expand Up @@ -127,4 +132,4 @@
"engines": {
"node": ">=14.14.0"
}
}
}
52 changes: 36 additions & 16 deletions packages/vitest/rollup.config.js
Expand Up @@ -24,6 +24,7 @@ const entries = [
const dtsEntries = [
'src/index.ts',
'src/node.ts',
'src/config.ts',
]

const external = [
Expand All @@ -34,6 +35,25 @@ const external = [
'c8',
]

const plugins = [
alias({
entries: [
{ find: /^node:(.+)$/, replacement: '$1' },
{ find: 'vite-node/server', replacement: path.resolve(__dirname, '../vite-node/src/server.ts') },
{ find: 'vite-node/client', replacement: path.resolve(__dirname, '../vite-node/src/client.ts') },
{ find: 'vite-node/utils', replacement: path.resolve(__dirname, '../vite-node/src/utils.ts') },
],
}),
resolve({
preferBuiltins: true,
}),
json(),
commonjs(),
esbuild({
target: 'node14',
}),
]

export default ({ watch }) => [
{
input: entries,
Expand All @@ -44,22 +64,7 @@ export default ({ watch }) => [
},
external,
plugins: [
alias({
entries: [
{ find: /^node:(.+)$/, replacement: '$1' },
{ find: 'vite-node/server', replacement: path.resolve(__dirname, '../vite-node/src/server.ts') },
{ find: 'vite-node/client', replacement: path.resolve(__dirname, '../vite-node/src/client.ts') },
{ find: 'vite-node/utils', replacement: path.resolve(__dirname, '../vite-node/src/utils.ts') },
],
}),
resolve({
preferBuiltins: true,
}),
json(),
commonjs(),
esbuild({
target: 'node14',
}),
...plugins,
!watch && licensePlugin(),
],
onwarn(message) {
Expand All @@ -68,6 +73,21 @@ export default ({ watch }) => [
console.error(message)
},
},
{
input: 'src/config.ts',
output: [
{
file: 'dist/config.cjs',
format: 'cjs',
},
{
file: 'dist/config.js',
format: 'esm',
},
],
external,
plugins,
},
...dtsEntries.map(input => ({
input,
output: {
Expand Down
6 changes: 6 additions & 0 deletions packages/vitest/src/config.ts
@@ -0,0 +1,6 @@
import type { UserConfig } from 'vite'

export { configDefaults } from './defaults'
export function defineConfig(config: UserConfig) {
return config
}
7 changes: 0 additions & 7 deletions packages/vitest/src/node/index.ts
@@ -1,10 +1,3 @@
import type { UserConfig } from 'vite'

export { configDefaults } from '../defaults'
export function defineConfig(config: UserConfig) {
return config
}

export type { Vitest } from './core'
export { createVitest } from './create'
export { VitestPlugin } from './plugins'
1 change: 1 addition & 0 deletions tsconfig.json
Expand Up @@ -22,6 +22,7 @@
"vitest/global": ["./packages/vitest/global.d.ts"],
"vitest/globals": ["./packages/vitest/globals.d.ts"],
"vitest/node": ["./packages/vitest/src/node/index.ts"],
"vitest/config": ["./packages/vitest/src/config.ts"],
"vite-node": ["./packages/vite-node/src/index.ts"],
"vite-node/client": ["./packages/vite-node/src/client.ts"],
"vite-node/server": ["./packages/vite-node/src/server.ts"],
Expand Down