Skip to content
This repository has been archived by the owner on Dec 19, 2023. It is now read-only.

feat!: rename defineConfigWithNuxt to defineVitestConfig #45

Merged
merged 2 commits into from
Jan 25, 2023
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ export default defineNuxtConfig({
3. Then create a `vitest.config.mjs` with the following content:

```js
import { defineConfigWithNuxt } from 'nuxt-vitest/config'
import { defineVitestConfig } from 'nuxt-vitest/config'

export default defineConfigWithNuxt({
export default defineVitestConfig({
// any custom vitest config you require
})
```
Expand All @@ -55,22 +55,22 @@ Or you can add `@vitest-environment nuxt` in your test file as a comment to opt-

```js
// @vitest-environment nuxt
import { test } from 'nuxt-vitest'
import { test } from 'vitest'

test('my test', () => {
// ... test with Nuxt environment!
})
```

Finally, you can set `envoironment: 'nuxt'`, to enable Nuxt environment for **all tests**.
Finally, you can set `environment: 'nuxt'`, to enable Nuxt environment for **all tests**.

```js
// vitest.config.ts
import { defineConfigWithNuxt } from 'nuxt-vitest'
import { defineVitestConfig } from 'nuxt-vitest/config'

export default defineConfigWithNuxt({
export default defineVitestConfig({
test: {
envoironment: 'nuxt'
environment: 'nuxt'
}
})
```
Expand Down
12 changes: 6 additions & 6 deletions packages/nuxt-vitest/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ interface GetVitestConfigOptions {
}

// https://github.com/nuxt/framework/issues/6496
async function getNuxtAndViteConfig(rootDir = process.cwd()) {
async function startNuxtAndGetViteConfig(rootDir = process.cwd()) {
const { loadNuxt, buildNuxt } = await import('@nuxt/kit')
const nuxt = await loadNuxt({
cwd: rootDir,
Expand Down Expand Up @@ -46,10 +46,10 @@ async function getNuxtAndViteConfig(rootDir = process.cwd()) {
return promise
}

export async function getVitestConfig(
export async function getVitestConfigFromNuxt(
options?: GetVitestConfigOptions
): Promise<InlineConfig & { test: VitestConfig }> {
if (!options) options = await getNuxtAndViteConfig()
if (!options) options = await startNuxtAndGetViteConfig()

return {
...options.viteConfig,
Expand Down Expand Up @@ -88,10 +88,10 @@ export async function getVitestConfig(
}
}

export function defineConfigWithNuxt(config: InlineConfig = {}) {
export function defineVitestConfig(config: InlineConfig = {}) {
return defineConfig(async () => {
// When Nuxt module calls `startVitest`, we don't need to call `getVitestConfig` again
// When Nuxt module calls `startVitest`, we don't need to call `getVitestConfigFromNuxt` again
if (process.env.__NUXT_VITEST_RESOLVED__) return config
return mergeConfig(await getVitestConfig(), config)
return mergeConfig(await getVitestConfigFromNuxt(), config)
})
}
2 changes: 1 addition & 1 deletion packages/nuxt-vitest/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export { defineConfigWithNuxt as defineConfigWithNuxtEnv } from './config'
export { defineVitestConfig } from './config'
export { default } from './module'
4 changes: 2 additions & 2 deletions packages/nuxt-vitest/src/module.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { defineNuxtModule, installModule, logger, resolvePath } from '@nuxt/kit'
import type { UserConfig as VitestConfig } from 'vitest'
import { mergeConfig, InlineConfig as ViteConfig } from 'vite'
import { getVitestConfig } from './config'
import { getVitestConfigFromNuxt } from './config'
import { getPort } from 'get-port-please'

export interface NuxtVitestOptions {
Expand Down Expand Up @@ -49,7 +49,7 @@ export default defineNuxtModule<NuxtVitestOptions>({
const rawViteConfig = mergeConfig({}, await rawViteConfigPromise)

const viteConfig = mergeConfig(
await getVitestConfig({ nuxt, viteConfig: rawViteConfig }),
await getVitestConfigFromNuxt({ nuxt, viteConfig: rawViteConfig }),
<ViteConfig>{
server: {
middlewareMode: false,
Expand Down
4 changes: 2 additions & 2 deletions playground/vitest.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { defineConfigWithNuxt } from 'nuxt-vitest/config'
import { defineVitestConfig } from 'nuxt-vitest/config'

export default defineConfigWithNuxt({
export default defineVitestConfig({
test: {
dir: 'tests',
coverage: {
Expand Down
74 changes: 0 additions & 74 deletions src/config.ts

This file was deleted.