mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-22 05:35:13 +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:docs": "./node_modules/.bin/markdownlint ./",
|
||||
"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: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"
|
||||
},
|
||||
"resolutions": {
|
||||
@ -37,13 +37,10 @@
|
||||
"@nuxt/ui": "^0.0.0-alpha.5",
|
||||
"@nuxtjs/eslint-config": "^7.0.0",
|
||||
"@nuxtjs/eslint-config-typescript": "^7.0.2",
|
||||
"@types/chai": "^4.3.0",
|
||||
"@types/jsdom": "^16",
|
||||
"@types/mocha": "^9.0.0",
|
||||
"@types/node": "^16.11.19",
|
||||
"@types/object-hash": "^2",
|
||||
"@unocss/reset": "^0.22.2",
|
||||
"chai": "^4.3.4",
|
||||
"esbuild": "^0.14.11",
|
||||
"eslint": "^8.6.0",
|
||||
"eslint-plugin-jsdoc": "^37.6.1",
|
||||
@ -53,11 +50,11 @@
|
||||
"lerna": "^4.0.0",
|
||||
"markdownlint-cli": "^0.30.0",
|
||||
"miniflare": "^1.4.1",
|
||||
"mocha": "^9.1.3",
|
||||
"object-hash": "^2.2.0",
|
||||
"pathe": "^0.2.0",
|
||||
"typescript": "^4.5.4",
|
||||
"unbuild": "^0.6.7",
|
||||
"vitest": "^0.1.0",
|
||||
"vue-router": "next"
|
||||
},
|
||||
"packageManager": "yarn@3.1.1",
|
||||
|
@ -1,5 +1,5 @@
|
||||
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'
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { readFileSync } from 'fs'
|
||||
import type { AutoImport } from '@nuxt/schema'
|
||||
import { expect } from 'chai'
|
||||
import { expect, describe, it } from 'vitest'
|
||||
import { join } from 'pathe'
|
||||
import { createCommonJS, findExports } from 'mlly'
|
||||
import * as VueFunctions from 'vue'
|
||||
@ -73,6 +73,8 @@ describe('auto-imports:nuxt3', () => {
|
||||
})
|
||||
|
||||
const excludedVueHelpers = [
|
||||
'__esModule',
|
||||
'devtools',
|
||||
'EffectScope',
|
||||
'ReactiveEffect',
|
||||
'stop',
|
||||
@ -166,7 +168,7 @@ describe('auto-imports:vue', () => {
|
||||
continue
|
||||
}
|
||||
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'
|
||||
|
||||
describe('pages:generateRoutesFromFiles', () => {
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { resolve } from 'path'
|
||||
import { ComponentsDir } from '@nuxt/schema'
|
||||
import { expect } from 'chai'
|
||||
import { expect, it } from 'vitest'
|
||||
import { scanComponents } from '../src/components/scan'
|
||||
|
||||
const fixtureDir = resolve(__dirname, 'fixture')
|
||||
|
@ -1,14 +1,21 @@
|
||||
import { pathToFileURL } from 'url'
|
||||
import { resolve } from 'pathe'
|
||||
import destr from 'destr'
|
||||
import { listen } from 'listhen'
|
||||
import { listen, Listener } from 'listhen'
|
||||
import { $fetch } from 'ohmyfetch'
|
||||
import { execa } from 'execa'
|
||||
import { expect } from 'chai'
|
||||
import { fixtureDir, resolveWorkspace } from '../utils.mjs'
|
||||
import { expect, it, beforeAll, afterAll } from 'vitest'
|
||||
import { fixtureDir, resolveWorkspace } from '../utils'
|
||||
|
||||
const isBridge = Boolean(process.env.TEST_BRIDGE)
|
||||
|
||||
interface Context {
|
||||
rootDir: string
|
||||
outDir: string
|
||||
fetch: (url:string) => Promise<any>
|
||||
server?: Listener
|
||||
}
|
||||
|
||||
export function importModule (path) {
|
||||
return import(pathToFileURL(path).href)
|
||||
}
|
||||
@ -18,14 +25,13 @@ export function setupTest (preset) {
|
||||
const rootDir = fixtureDir(fixture)
|
||||
const buildDir = resolve(rootDir, '.nuxt-' + preset)
|
||||
|
||||
const ctx = {
|
||||
const ctx: Context = {
|
||||
rootDir,
|
||||
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 () {
|
||||
this.timeout(60000)
|
||||
beforeAll(async () => {
|
||||
const nuxtCLI = isBridge
|
||||
? resolve(ctx.rootDir, 'node_modules/nuxt-edge/bin/nuxt.js')
|
||||
: resolveWorkspace('packages/nuxi/bin/nuxi.mjs')
|
||||
@ -38,9 +44,9 @@ export function setupTest (preset) {
|
||||
NODE_ENV: 'production'
|
||||
}
|
||||
})
|
||||
})
|
||||
}, (isBridge ? 120 : 60) * 1000)
|
||||
|
||||
after('Cleanup', async () => {
|
||||
afterAll(async () => {
|
||||
if (ctx.server) {
|
||||
await ctx.server.close()
|
||||
}
|
@ -1,8 +1,9 @@
|
||||
import { promises as fsp } from 'fs'
|
||||
import { resolve } from 'pathe'
|
||||
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
|
||||
describe('nitro:preset:cloudflare', () => {
|
@ -1,5 +1,6 @@
|
||||
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', () => {
|
||||
const ctx = setupTest('lambda')
|
@ -1,5 +1,6 @@
|
||||
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', () => {
|
||||
const ctx = setupTest('node')
|
@ -1,5 +1,6 @@
|
||||
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', () => {
|
||||
const ctx = setupTest('vercel')
|
@ -3,25 +3,25 @@ import { execSync } from 'child_process'
|
||||
import { resolve, dirname } from 'pathe'
|
||||
import defu from 'defu'
|
||||
import hash from 'object-hash'
|
||||
import { execa } from 'execa'
|
||||
import { execa, Options as ExecaOptions } from 'execa'
|
||||
import { createCommonJS } from 'mlly'
|
||||
|
||||
const cjs = createCommonJS(import.meta.url)
|
||||
|
||||
export function resolveWorkspace (name) {
|
||||
export function resolveWorkspace (name: string) {
|
||||
return resolve(cjs.__dirname, '../', name)
|
||||
}
|
||||
|
||||
export function fixtureDir (name) {
|
||||
export function fixtureDir (name: string) {
|
||||
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')
|
||||
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 buildDir = resolve(opts.rootDir, '.nuxt', buildId)
|
||||
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)) {
|
||||
mkdirpSync(dirname(dir))
|
||||
mkdirSync(dir)
|
@ -11,9 +11,7 @@
|
||||
"noUnusedLocals": true,
|
||||
"resolveJsonModule": true,
|
||||
"types": [
|
||||
"node",
|
||||
"mocha",
|
||||
"chai"
|
||||
"node"
|
||||
],
|
||||
"paths": {
|
||||
"#app": [
|
||||
|
Loading…
Reference in New Issue
Block a user