mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-25 23:22:02 +00:00
chore: migrate to vitest from mocha (#2694)
This commit is contained in:
parent
303b5bd220
commit
a787c2f04c
@ -20,10 +20,10 @@
|
|||||||
"lint": "eslint --ext .vue,.ts,.js,.mjs .",
|
"lint": "eslint --ext .vue,.ts,.js,.mjs .",
|
||||||
"lint:docs": "./node_modules/.bin/markdownlint ./",
|
"lint:docs": "./node_modules/.bin/markdownlint ./",
|
||||||
"test": "yarn lint && yarn test:presets",
|
"test": "yarn lint && yarn test:presets",
|
||||||
"test:presets": "mocha test/presets/*.mjs",
|
"test:presets": "vitest test/presets",
|
||||||
"test:bridge:webpack": "TEST_BRIDGE=1 yarn test:presets",
|
"test:bridge:webpack": "TEST_BRIDGE=1 yarn test:presets",
|
||||||
"test:bridge:vite": "TEST_BRIDGE_VITE=1 TEST_BRIDGE=1 yarn test:presets",
|
"test:bridge:vite": "TEST_BRIDGE_VITE=1 TEST_BRIDGE=1 yarn test:presets",
|
||||||
"test:unit": "mocha -r jiti/register packages/*/test/*.test.*",
|
"test:unit": "vitest packages",
|
||||||
"version": "yarn && git add yarn.lock"
|
"version": "yarn && git add yarn.lock"
|
||||||
},
|
},
|
||||||
"resolutions": {
|
"resolutions": {
|
||||||
@ -37,13 +37,10 @@
|
|||||||
"@nuxt/ui": "^0.0.0-alpha.5",
|
"@nuxt/ui": "^0.0.0-alpha.5",
|
||||||
"@nuxtjs/eslint-config": "^7.0.0",
|
"@nuxtjs/eslint-config": "^7.0.0",
|
||||||
"@nuxtjs/eslint-config-typescript": "^7.0.2",
|
"@nuxtjs/eslint-config-typescript": "^7.0.2",
|
||||||
"@types/chai": "^4.3.0",
|
|
||||||
"@types/jsdom": "^16",
|
"@types/jsdom": "^16",
|
||||||
"@types/mocha": "^9.0.0",
|
|
||||||
"@types/node": "^16.11.19",
|
"@types/node": "^16.11.19",
|
||||||
"@types/object-hash": "^2",
|
"@types/object-hash": "^2",
|
||||||
"@unocss/reset": "^0.22.2",
|
"@unocss/reset": "^0.22.2",
|
||||||
"chai": "^4.3.4",
|
|
||||||
"esbuild": "^0.14.11",
|
"esbuild": "^0.14.11",
|
||||||
"eslint": "^8.6.0",
|
"eslint": "^8.6.0",
|
||||||
"eslint-plugin-jsdoc": "^37.6.1",
|
"eslint-plugin-jsdoc": "^37.6.1",
|
||||||
@ -53,11 +50,11 @@
|
|||||||
"lerna": "^4.0.0",
|
"lerna": "^4.0.0",
|
||||||
"markdownlint-cli": "^0.30.0",
|
"markdownlint-cli": "^0.30.0",
|
||||||
"miniflare": "^1.4.1",
|
"miniflare": "^1.4.1",
|
||||||
"mocha": "^9.1.3",
|
|
||||||
"object-hash": "^2.2.0",
|
"object-hash": "^2.2.0",
|
||||||
"pathe": "^0.2.0",
|
"pathe": "^0.2.0",
|
||||||
"typescript": "^4.5.4",
|
"typescript": "^4.5.4",
|
||||||
"unbuild": "^0.6.7",
|
"unbuild": "^0.6.7",
|
||||||
|
"vitest": "^0.1.0",
|
||||||
"vue-router": "next"
|
"vue-router": "next"
|
||||||
},
|
},
|
||||||
"packageManager": "yarn@3.1.1",
|
"packageManager": "yarn@3.1.1",
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import * as CompositionApi from '@vue/composition-api'
|
import * as CompositionApi from '@vue/composition-api'
|
||||||
import { expect } from 'chai'
|
import { expect, describe, it } from 'vitest'
|
||||||
|
|
||||||
import { Nuxt3AutoImports } from '../../nuxt3/src/auto-imports/imports'
|
import { Nuxt3AutoImports } from '../../nuxt3/src/auto-imports/imports'
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { readFileSync } from 'fs'
|
import { readFileSync } from 'fs'
|
||||||
import type { AutoImport } from '@nuxt/schema'
|
import type { AutoImport } from '@nuxt/schema'
|
||||||
import { expect } from 'chai'
|
import { expect, describe, it } from 'vitest'
|
||||||
import { join } from 'pathe'
|
import { join } from 'pathe'
|
||||||
import { createCommonJS, findExports } from 'mlly'
|
import { createCommonJS, findExports } from 'mlly'
|
||||||
import * as VueFunctions from 'vue'
|
import * as VueFunctions from 'vue'
|
||||||
@ -73,6 +73,8 @@ describe('auto-imports:nuxt3', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
const excludedVueHelpers = [
|
const excludedVueHelpers = [
|
||||||
|
'__esModule',
|
||||||
|
'devtools',
|
||||||
'EffectScope',
|
'EffectScope',
|
||||||
'ReactiveEffect',
|
'ReactiveEffect',
|
||||||
'stop',
|
'stop',
|
||||||
@ -166,7 +168,7 @@ describe('auto-imports:vue', () => {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
it(`should register ${name} globally`, () => {
|
it(`should register ${name} globally`, () => {
|
||||||
expect(Nuxt3AutoImports.find(a => a.from === 'vue').names).to.include(name)
|
expect(Nuxt3AutoImports.find(a => a.from === 'vue').names).toContain(name)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { expect } from 'chai'
|
import { expect, describe, it } from 'vitest'
|
||||||
import { generateRoutesFromFiles } from '../src/pages/utils'
|
import { generateRoutesFromFiles } from '../src/pages/utils'
|
||||||
|
|
||||||
describe('pages:generateRoutesFromFiles', () => {
|
describe('pages:generateRoutesFromFiles', () => {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { resolve } from 'path'
|
import { resolve } from 'path'
|
||||||
import { ComponentsDir } from '@nuxt/schema'
|
import { ComponentsDir } from '@nuxt/schema'
|
||||||
import { expect } from 'chai'
|
import { expect, it } from 'vitest'
|
||||||
import { scanComponents } from '../src/components/scan'
|
import { scanComponents } from '../src/components/scan'
|
||||||
|
|
||||||
const fixtureDir = resolve(__dirname, 'fixture')
|
const fixtureDir = resolve(__dirname, 'fixture')
|
||||||
|
@ -1,14 +1,21 @@
|
|||||||
import { pathToFileURL } from 'url'
|
import { pathToFileURL } from 'url'
|
||||||
import { resolve } from 'pathe'
|
import { resolve } from 'pathe'
|
||||||
import destr from 'destr'
|
import destr from 'destr'
|
||||||
import { listen } from 'listhen'
|
import { listen, Listener } from 'listhen'
|
||||||
import { $fetch } from 'ohmyfetch'
|
import { $fetch } from 'ohmyfetch'
|
||||||
import { execa } from 'execa'
|
import { execa } from 'execa'
|
||||||
import { expect } from 'chai'
|
import { expect, it, beforeAll, afterAll } from 'vitest'
|
||||||
import { fixtureDir, resolveWorkspace } from '../utils.mjs'
|
import { fixtureDir, resolveWorkspace } from '../utils'
|
||||||
|
|
||||||
const isBridge = Boolean(process.env.TEST_BRIDGE)
|
const isBridge = Boolean(process.env.TEST_BRIDGE)
|
||||||
|
|
||||||
|
interface Context {
|
||||||
|
rootDir: string
|
||||||
|
outDir: string
|
||||||
|
fetch: (url:string) => Promise<any>
|
||||||
|
server?: Listener
|
||||||
|
}
|
||||||
|
|
||||||
export function importModule (path) {
|
export function importModule (path) {
|
||||||
return import(pathToFileURL(path).href)
|
return import(pathToFileURL(path).href)
|
||||||
}
|
}
|
||||||
@ -18,14 +25,13 @@ export function setupTest (preset) {
|
|||||||
const rootDir = fixtureDir(fixture)
|
const rootDir = fixtureDir(fixture)
|
||||||
const buildDir = resolve(rootDir, '.nuxt-' + preset)
|
const buildDir = resolve(rootDir, '.nuxt-' + preset)
|
||||||
|
|
||||||
const ctx = {
|
const ctx: Context = {
|
||||||
rootDir,
|
rootDir,
|
||||||
outDir: resolve(buildDir, 'output'),
|
outDir: resolve(buildDir, 'output'),
|
||||||
fetch: url => $fetch(url, { baseURL: ctx.server.url })
|
fetch: url => $fetch(url, { baseURL: ctx.server!.url })
|
||||||
}
|
}
|
||||||
|
|
||||||
before('nitro build', async function () {
|
beforeAll(async () => {
|
||||||
this.timeout(60000)
|
|
||||||
const nuxtCLI = isBridge
|
const nuxtCLI = isBridge
|
||||||
? resolve(ctx.rootDir, 'node_modules/nuxt-edge/bin/nuxt.js')
|
? resolve(ctx.rootDir, 'node_modules/nuxt-edge/bin/nuxt.js')
|
||||||
: resolveWorkspace('packages/nuxi/bin/nuxi.mjs')
|
: resolveWorkspace('packages/nuxi/bin/nuxi.mjs')
|
||||||
@ -38,9 +44,9 @@ export function setupTest (preset) {
|
|||||||
NODE_ENV: 'production'
|
NODE_ENV: 'production'
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
})
|
}, (isBridge ? 120 : 60) * 1000)
|
||||||
|
|
||||||
after('Cleanup', async () => {
|
afterAll(async () => {
|
||||||
if (ctx.server) {
|
if (ctx.server) {
|
||||||
await ctx.server.close()
|
await ctx.server.close()
|
||||||
}
|
}
|
@ -1,8 +1,9 @@
|
|||||||
import { promises as fsp } from 'fs'
|
import { promises as fsp } from 'fs'
|
||||||
import { resolve } from 'pathe'
|
import { resolve } from 'pathe'
|
||||||
import { Miniflare } from 'miniflare'
|
import { Miniflare } from 'miniflare'
|
||||||
|
import { describe } from 'vitest'
|
||||||
|
|
||||||
import { setupTest, testNitroBehavior } from './_tests.mjs'
|
import { setupTest, testNitroBehavior } from './_tests'
|
||||||
|
|
||||||
// TODO: fix SyntaxError: Unexpected end of input on script executation
|
// TODO: fix SyntaxError: Unexpected end of input on script executation
|
||||||
describe('nitro:preset:cloudflare', () => {
|
describe('nitro:preset:cloudflare', () => {
|
@ -1,5 +1,6 @@
|
|||||||
import { resolve } from 'pathe'
|
import { resolve } from 'pathe'
|
||||||
import { setupTest, testNitroBehavior, importModule } from './_tests.mjs'
|
import { describe } from 'vitest'
|
||||||
|
import { setupTest, testNitroBehavior, importModule } from './_tests'
|
||||||
|
|
||||||
describe('nitro:preset:lambda', () => {
|
describe('nitro:preset:lambda', () => {
|
||||||
const ctx = setupTest('lambda')
|
const ctx = setupTest('lambda')
|
@ -1,5 +1,6 @@
|
|||||||
import { resolve } from 'pathe'
|
import { resolve } from 'pathe'
|
||||||
import { startServer, setupTest, testNitroBehavior, importModule } from './_tests.mjs'
|
import { describe } from 'vitest'
|
||||||
|
import { startServer, setupTest, testNitroBehavior, importModule } from './_tests.js'
|
||||||
|
|
||||||
describe('nitro:preset:node', () => {
|
describe('nitro:preset:node', () => {
|
||||||
const ctx = setupTest('node')
|
const ctx = setupTest('node')
|
@ -1,5 +1,6 @@
|
|||||||
import { resolve } from 'pathe'
|
import { resolve } from 'pathe'
|
||||||
import { setupTest, startServer, testNitroBehavior, importModule } from './_tests.mjs'
|
import { describe } from 'vitest'
|
||||||
|
import { setupTest, startServer, testNitroBehavior, importModule } from './_tests'
|
||||||
|
|
||||||
describe('nitro:preset:vercel', () => {
|
describe('nitro:preset:vercel', () => {
|
||||||
const ctx = setupTest('vercel')
|
const ctx = setupTest('vercel')
|
@ -3,25 +3,25 @@ import { execSync } from 'child_process'
|
|||||||
import { resolve, dirname } from 'pathe'
|
import { resolve, dirname } from 'pathe'
|
||||||
import defu from 'defu'
|
import defu from 'defu'
|
||||||
import hash from 'object-hash'
|
import hash from 'object-hash'
|
||||||
import { execa } from 'execa'
|
import { execa, Options as ExecaOptions } from 'execa'
|
||||||
import { createCommonJS } from 'mlly'
|
import { createCommonJS } from 'mlly'
|
||||||
|
|
||||||
const cjs = createCommonJS(import.meta.url)
|
const cjs = createCommonJS(import.meta.url)
|
||||||
|
|
||||||
export function resolveWorkspace (name) {
|
export function resolveWorkspace (name: string) {
|
||||||
return resolve(cjs.__dirname, '../', name)
|
return resolve(cjs.__dirname, '../', name)
|
||||||
}
|
}
|
||||||
|
|
||||||
export function fixtureDir (name) {
|
export function fixtureDir (name: string) {
|
||||||
return resolve(cjs.__dirname, 'fixtures', name)
|
return resolve(cjs.__dirname, 'fixtures', name)
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function execNuxtCLI (args, opts) {
|
export async function execNuxtCLI (args: string[], opts: ExecaOptions) {
|
||||||
const nuxtCLI = resolveWorkspace('packages/nuxi/bin/nuxi.mjs')
|
const nuxtCLI = resolveWorkspace('packages/nuxi/bin/nuxi.mjs')
|
||||||
await execa('node', [nuxtCLI, ...args], opts)
|
await execa('node', [nuxtCLI, ...args], opts)
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function loadFixture (opts, unhashedConfig) {
|
export async function loadFixture (opts: any, unhashedConfig?: any) {
|
||||||
const buildId = hash(opts)
|
const buildId = hash(opts)
|
||||||
const buildDir = resolve(opts.rootDir, '.nuxt', buildId)
|
const buildDir = resolve(opts.rootDir, '.nuxt', buildId)
|
||||||
const { loadNuxt } = await import('@nuxt/kit')
|
const { loadNuxt } = await import('@nuxt/kit')
|
||||||
@ -54,7 +54,7 @@ export async function buildFixture (opts) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function mkdirpSync (dir) {
|
function mkdirpSync (dir: string) {
|
||||||
if (!existsSync(dir)) {
|
if (!existsSync(dir)) {
|
||||||
mkdirpSync(dirname(dir))
|
mkdirpSync(dirname(dir))
|
||||||
mkdirSync(dir)
|
mkdirSync(dir)
|
@ -11,9 +11,7 @@
|
|||||||
"noUnusedLocals": true,
|
"noUnusedLocals": true,
|
||||||
"resolveJsonModule": true,
|
"resolveJsonModule": true,
|
||||||
"types": [
|
"types": [
|
||||||
"node",
|
"node"
|
||||||
"mocha",
|
|
||||||
"chai"
|
|
||||||
],
|
],
|
||||||
"paths": {
|
"paths": {
|
||||||
"#app": [
|
"#app": [
|
||||||
|
Loading…
Reference in New Issue
Block a user