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

Commit

Permalink
fix(ui): wait for Vitest UI to initiate
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed Jan 28, 2023
1 parent 3d567df commit 3090ccf
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 71 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"@nuxt/schema": "3.1.1",
"@release-it-plugins/workspaces": "^3.2.0",
"@release-it/conventional-changelog": "5.1.1",
"@vitest/coverage-c8": "0.28.2",
"@vitest/coverage-c8": "0.28.3",
"conventional-changelog-conventionalcommits": "5.0.0",
"eslint": "8.32.0",
"eslint-config-prettier": "8.6.0",
Expand All @@ -33,7 +33,7 @@
"prettier": "2.8.3",
"release-it": "15.6.0",
"unbuild": "1.1.1",
"vitest": "0.28.2",
"vitest": "0.28.3",
"vue": "3.2.45"
},
"pnpm": {
Expand Down
5 changes: 3 additions & 2 deletions packages/nuxt-vitest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,11 @@
},
"dependencies": {
"@nuxt/kit": "^3.1.1",
"@vitest/ui": "^0.28.2",
"@vitest/ui": "^0.28.3",
"get-port-please": "^3.0.1",
"perfect-debounce": "^0.1.3",
"vitest": "^0.28.2",
"std-env": "^3.3.1",
"vitest": "^0.28.3",
"vitest-environment-nuxt": "0.6.3"
},
"devDependencies": {
Expand Down
22 changes: 13 additions & 9 deletions packages/nuxt-vitest/src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { getVitestConfigFromNuxt } from './config'
import { getPort } from 'get-port-please'
import { h } from 'vue'
import { debounce } from 'perfect-debounce'
import { isCI } from 'std-env'

export interface NuxtVitestOptions {
startOnBoot?: boolean
Expand Down Expand Up @@ -91,13 +92,11 @@ export default defineNuxtModule<NuxtVitestOptions>({
},
}

const watchMode = !process.env.NUXT_VITEST_DEV_TEST && !isCI

// For testing dev mode in CI, maybe expose an option to user later
const vitestConfig: VitestConfig = process.env.NUXT_VITEST_DEV_TEST
const vitestConfig: VitestConfig = watchMode
? {
...options.vitestConfig,
watch: false,
}
: {
passWithNoTests: true,
...options.vitestConfig,
reporters: options.logToConsole
Expand All @@ -113,22 +112,27 @@ export default defineNuxtModule<NuxtVitestOptions>({
port: PORT,
},
}
: {
...options.vitestConfig,
watch: false,
}

// TODO: Investigate segfault when loading config file in Nuxt
viteConfig.configFile = false

// Start Vitest
const promise = startVitest('test', [], vitestConfig, viteConfig)
promise.catch(() => process.exit(1))

if (process.env.NUXT_VITEST_DEV_TEST) {
if (watchMode) {
logger.info(`Vitest UI starting on ${URL}`)
await new Promise(resolve => setTimeout(resolve, 1000))
} else {
promise.then(v => v?.close()).then(() => process.exit())
promise.catch(() => process.exit(1))
}

logger.info(`Vitest UI starting on ${URL}`)

loaded = true
promise.catch(() => process.exit(1))
}

// @ts-ignore
Expand Down
2 changes: 1 addition & 1 deletion packages/vitest-environment-nuxt/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"@vue/test-utils": "^2.2.8",
"estree-walker": "^3.0.3",
"h3": "^1.1.0",
"happy-dom": "^8.1.5",
"happy-dom": "^8.2.0",
"magic-string": "^0.27.0",
"ofetch": "^1.0.0",
"unenv": "^1.0.2"
Expand Down
4 changes: 2 additions & 2 deletions playground/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
"test": "pnpm test:unit --run && pnpm test:dev"
},
"devDependencies": {
"@nuxt/devtools-edge": "0.0.0-27913555.91bd93a",
"@nuxt/devtools-edge": "0.0.0-27915216.4d09244",
"nuxt": "3.1.1",
"nuxt-vitest": "0.6.3",
"vitest": "0.28.2",
"vitest": "0.28.3",
"vitest-environment-nuxt": "0.6.3"
},
"version": "0.6.3"
Expand Down
112 changes: 57 additions & 55 deletions pnpm-lock.yaml

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

0 comments on commit 3090ccf

Please sign in to comment.