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

Commit

Permalink
feat: adopt new tab interface
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed Jan 26, 2023
1 parent af33fa0 commit 074dde9
Show file tree
Hide file tree
Showing 7 changed files with 198 additions and 219 deletions.
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,35 @@
"build": "pnpm run --filter=./packages/* -r build",
"stub": "pnpm run --filter=./packages/* -r stub",
"dev:prepare": "pnpm nuxi prepare playground",
"dev": "pnpm run build && pnpm -C playground test:nuxt",
"dev": "pnpm run build && pnpm -C playground test:unit",
"lint": "pnpm lint:all:eslint && pnpm lint:all:prettier",
"lint:all:eslint": "pnpm lint:eslint --ext .ts,.js,.mjs,.cjs .",
"lint:all:prettier": "pnpm lint:prettier \"**/*.{js,json,ts}\"",
"lint:eslint": "eslint --fix",
"play": "pnpm run stub && pnpm -C playground dev",
"lint:prettier": "prettier --write --loglevel warn",
"play": "pnpm run stub && pnpm -C playground dev",
"prepare": "husky install",
"test": "pnpm -C playground test",
"release": "release-it"
},
"devDependencies": {
"@nuxt/eslint-config": "^0.1.1",
"@nuxt/schema": "3.1.0",
"@nuxt/schema": "3.1.1",
"@release-it-plugins/workspaces": "^3.2.0",
"@release-it/conventional-changelog": "5.1.1",
"@vitest/coverage-c8": "0.28.1",
"@vitest/coverage-c8": "0.28.2",
"conventional-changelog-conventionalcommits": "5.0.0",
"eslint": "8.32.0",
"eslint-config-prettier": "8.6.0",
"eslint-plugin-prettier": "4.2.1",
"husky": "8.0.3",
"lint-staged": "13.1.0",
"nuxt": "3.1.0",
"nuxt": "3.1.1",
"pinst": "3.0.0",
"prettier": "2.8.3",
"release-it": "15.6.0",
"unbuild": "1.1.1",
"vitest": "0.28.1",
"vitest": "0.28.2",
"vue": "3.2.45"
},
"pnpm": {
Expand Down
10 changes: 5 additions & 5 deletions packages/nuxt-vitest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@
"vite": "*"
},
"dependencies": {
"@nuxt/kit": "^3.1.0",
"@vitest/ui": "^0.28.1",
"@nuxt/kit": "^3.1.1",
"@vitest/ui": "^0.28.2",
"get-port-please": "^3.0.1",
"vitest": "^0.28.1",
"vitest": "^0.28.2",
"vitest-environment-nuxt": "0.6.1"
},
"devDependencies": {
"@nuxt/module-builder": "^0.2.1",
"@nuxt/schema": "^3.1.0",
"nuxt": "3.1.0"
"@nuxt/schema": "^3.1.1",
"nuxt": "3.1.1"
}
}
45 changes: 29 additions & 16 deletions packages/nuxt-vitest/src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ export default defineNuxtModule<NuxtVitestOptions>({

const PORT = await getPort({ port: 15555 })
const URL = `http://localhost:${PORT}/__vitest__/`
let loaded = false
let promise: Promise<any> | undefined

async function start() {
const rawViteConfig = mergeConfig({}, await rawViteConfigPromise)
Expand Down Expand Up @@ -95,33 +97,44 @@ export default defineNuxtModule<NuxtVitestOptions>({

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

return await promise
loaded = true
promise
}

let promise: Promise<any> | undefined

// @ts-ignore
nuxt.hook('devtools:customTabs', iframeTabs => {
iframeTabs.push({
nuxt.hook('devtools:customTabs', tabs => {
tabs.push({
title: 'Vitest',
name: 'vitest',
icon: 'logos-vitest',
view: {
type: 'iframe',
src: URL,
},
lazy: {
onLoad: async () => {
promise = promise || start()
await promise
},
description: 'Start tests along with Nuxt',
},
view: loaded
? {
type: 'iframe',
src: URL,
}
: {
type: 'launch',
description: 'Start tests along with Nuxt',
actions: [
{
label: promise ? 'Starting...' : 'Start Vitest',
pending: !!promise,
handle: () => {
promise = promise || start()
return promise
},
},
],
},
})
})

if (options.startOnBoot) {
promise = promise || start()
promise.then(() => {
// @ts-expect-error
nuxt.callHook('devtools:customTabs:refresh')
})
}
},
})
6 changes: 3 additions & 3 deletions packages/vitest-environment-nuxt/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@
"*.d.ts"
],
"dependencies": {
"@nuxt/kit": "^3.1.0",
"@nuxt/kit": "^3.1.1",
"@vue/test-utils": "^2.2.7",
"estree-walker": "^3.0.3",
"h3": "^1.0.2",
"h3": "^1.1.0",
"happy-dom": "^8.1.5",
"magic-string": "^0.27.0",
"ofetch": "^1.0.0",
"unenv": "^1.0.1"
"unenv": "^1.0.2"
},
"peerDependencies": {
"vitest": "^0.24.5 || ^0.26.0 || ^0.27.0 || ^0.28.0",
Expand Down
1 change: 1 addition & 0 deletions playground/nuxt.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// https://v3.nuxtjs.org/api/configuration/nuxt.config
export default defineNuxtConfig({
modules: ['nuxt-vitest', '@nuxt/devtools-edge', '~/modules/custom'],
ssr: false,
vitest: {
startOnBoot: true,
logToConsole: true,
Expand Down
6 changes: 3 additions & 3 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-27909847.46d1bc3",
"nuxt": "3.1.0",
"@nuxt/devtools-edge": "0.0.0-27912280.546e2ef",
"nuxt": "3.1.1",
"nuxt-vitest": "0.6.1",
"vitest": "0.28.1",
"vitest": "0.28.2",
"vitest-environment-nuxt": "0.6.1"
},
"version": "0.6.1"
Expand Down
Loading

0 comments on commit 074dde9

Please sign in to comment.