Skip to content

Commit

Permalink
test: rework tests using @nuxt/test-utils (nuxt#3308)
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 authored Feb 18, 2022
1 parent 87eb7d0 commit 12a95ad
Show file tree
Hide file tree
Showing 24 changed files with 111 additions and 379 deletions.
53 changes: 35 additions & 18 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
- name: Lint (docs)
run: yarn lint:docs

test:
test-fixtures:
runs-on: ${{ matrix.os }}

strategy:
Expand All @@ -51,19 +51,16 @@ jobs:
- name: Install dependencies
run: yarn --immutable

- name: Build
run: yarn build
- name: Stub
run: yarn stub

- name: Test (unit)
run: yarn test:unit

- name: Test (presets)
run: yarn test:presets
- name: Test (fixtures)
run: yarn test:fixtures

- name: Test (types)
run: yarn test:types

test-bridge:
test-fixtures-webpack:
runs-on: ${{ matrix.os }}

strategy:
Expand All @@ -77,26 +74,46 @@ jobs:
with:
node-version: ${{ matrix.node }}
cache: 'yarn'
cache-dependency-path: |
yarn.lock

- name: Install dependencies
run: yarn --immutable

- name: Stub
run: yarn stub

- name: Test (fixtures)
run: yarn test:fixtures:webpack

test-types:
runs-on: ${{ matrix.os }}

strategy:
matrix:
os: [ubuntu-latest]
node: [14]

steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node }}
cache: 'yarn'

- name: Install dependencies
run: yarn --immutable

- name: Build
run: yarn build

- name: Test with webpack
run: yarn test:bridge:webpack

- name: Test with vite
run: yarn test:bridge:vite
- name: Test (types)
run: yarn test:types

build-release:
needs:
- test
- test-bridge
- lint
- test-fixtures
- test-fixtures-webpack
- test-types
runs-on: ${{ matrix.os }}

strategy:
Expand Down
2 changes: 1 addition & 1 deletion docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"@docus/theme": "1.2.2",
"@nuxt/typescript-build": "^2.1.0",
"fs-extra": "^10.0.0",
"jiti": "^1.12.15",
"jiti": "^1.13.0",
"pathe": "^0.2.0",
"rimraf": "^3.0.2",
"scule": "^0.2.1",
Expand Down
33 changes: 15 additions & 18 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,30 +10,27 @@
],
"scripts": {
"build": "FORCE_COLOR=1 lerna run prepack --stream --no-prefix",
"stub": "lerna run prepack -- --stub",
"release": "yarn && yarn lint && FORCE_COLOR=1 lerna publish -m \"chore: release\" && yarn stub",
"nuxi": "./node_modules/.bin/nuxi",
"nuxt": "./node_modules/.bin/nuxi",
"play": "yarn run nuxi dev playground",
"example": "yarn workspace example-$0 dev",
"example:build": "yarn workspace example-$0 build",
"lint": "eslint --ext .vue,.ts,.js,.mjs .",
"lint:docs": "./node_modules/.bin/markdownlint ./",
"test": "yarn lint && yarn test:presets",
"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",
"nuxi": "./node_modules/.bin/nuxi",
"nuxt": "./node_modules/.bin/nuxi",
"play": "yarn run nuxi dev playground",
"release": "yarn && yarn lint && FORCE_COLOR=1 lerna publish -m \"chore: release\" && yarn stub",
"stub": "lerna run prepack -- --stub",
"test:fixtures": "JITI_ESM_RESOLVE=1 vitest test",
"test:fixtures:webpack": "TEST_WITH_WEBPACK=1 yarn test:fixtures",
"test:types": "yarn run nuxi prepare test/fixtures/basic && cd test/fixtures/basic && npx vue-tsc --noEmit",
"test:unit": "vitest packages",
"test:utils": "vitest run test/examples",
"test:unit": "JITI_ESM_RESOLVE=1 yarn vitest packages",
"version": "yarn && git add yarn.lock"
},
"resolutions": {
"nuxt3": "workspace:./packages/nuxt3",
"@nuxt/ui": "npm:@nuxt/ui-edge@latest",
"unbuild": "^0.6.9",
"jiti": "^1.13.0",
"nitropack-dev": "link:../nitropack",
"jiti": "^1.12.15"
"nuxt3": "workspace:./packages/nuxt3",
"unbuild": "^0.6.9"
},
"devDependencies": {
"@iconify-json/carbon": "^1.1.1",
Expand All @@ -50,20 +47,20 @@
"execa": "^6.1.0",
"expect-type": "^0.13.0",
"globby": "^13.1.1",
"jiti": "^1.12.15",
"jiti": "^1.13.0",
"lerna": "^4.0.0",
"markdownlint-cli": "^0.31.1",
"miniflare": "^1.4.1",
"object-hash": "^2.2.0",
"pathe": "^0.2.0",
"typescript": "^4.5.5",
"unbuild": "^0.6.9",
"vitest": "^0.3.6",
"vitest": "^0.4.1",
"vue-router": "next",
"vue-tsc": "^0.31.4"
},
"packageManager": "yarn@3.1.1",
"engines": {
"node": "^14.16.0 || ^16.11.0 || ^17.0.0"
}
},
"packageManager": "yarn@3.1.1"
}
2 changes: 1 addition & 1 deletion packages/kit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"defu": "^5.0.1",
"globby": "^13.1.1",
"hash-sum": "^2.0.0",
"jiti": "^1.12.15",
"jiti": "^1.13.0",
"knitwork": "^0.1.0",
"lodash.template": "^4.5.0",
"mlly": "^0.4.3",
Expand Down
2 changes: 1 addition & 1 deletion packages/kit/src/resolve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { fileURLToPath } from 'url'
import { basename, dirname, resolve, join, normalize, isAbsolute } from 'pathe'
import { globby } from 'globby'
import { useNuxt } from './context'
import { tryResolveModule } from '.'
import { tryResolveModule } from './internal/cjs'

export interface ResolvePathOptions {
/** Base for resolving paths from. Default is Nuxt rootDir. */
Expand Down
2 changes: 1 addition & 1 deletion packages/nitro/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"hookable": "^5.1.1",
"http-proxy": "^1.18.1",
"is-primitive": "^3.0.1",
"jiti": "^1.12.15",
"jiti": "^1.13.0",
"knitwork": "^0.1.0",
"listhen": "^0.2.6",
"mime": "^3.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/nuxi/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"destr": "^1.1.0",
"execa": "^6.1.0",
"flat": "^5.0.2",
"jiti": "^1.12.15",
"jiti": "^1.13.0",
"listhen": "^0.2.6",
"mlly": "^0.4.3",
"mri": "^1.2.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/schema/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"c12": "^0.1.3",
"create-require": "^1.1.1",
"defu": "^5.0.1",
"jiti": "^1.12.15",
"jiti": "^1.13.0",
"pathe": "^0.2.0",
"scule": "^0.2.1",
"std-env": "^3.0.1",
Expand Down
4 changes: 2 additions & 2 deletions packages/test-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@
"defu": "^5.0.1",
"execa": "^6.1.0",
"get-port-please": "^2.3.0",
"jiti": "^1.12.15",
"jiti": "^1.13.0",
"ohmyfetch": "^0.4.15"
},
"devDependencies": {
"playwright": "^1.19.1",
"unbuild": "latest",
"vitest": "^0.3.6"
"vitest": "^0.4.1"
},
"peerDependencies": {
"vue": "3.2.31"
Expand Down
2 changes: 1 addition & 1 deletion packages/test-utils/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function checkPort (port: number, host: string): Promise<number|false> {
export async function listen () {
const ctx = useTestContext()
const host = process.env.HOST || '0.0.0.0'
const port = await getPort({ host })
const port = await getPort({ host, random: true })

ctx.url = 'http://localhost:' + port
execa('node', [
Expand Down
13 changes: 13 additions & 0 deletions test/basic.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { fileURLToPath } from 'url'
import { describe, expect, it } from 'vitest'
import { setup, $fetch } from '@nuxt/test-utils'

describe('fixtures:basic', async () => {
await setup({
rootDir: fileURLToPath(new URL('./fixtures/basic', import.meta.url)),
server: true
})
it('Render hello world', async () => {
expect(await $fetch('/')).to.contain('Hello Nuxt 3!')
})
})
14 changes: 14 additions & 0 deletions test/bridge.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { fileURLToPath } from 'url'
import { describe, expect, it } from 'vitest'
import { setup, $fetch } from '@nuxt/test-utils'

describe('fixtures:bridge', async () => {
await setup({
rootDir: fileURLToPath(new URL('./fixtures/bridge', import.meta.url)),
server: true
})

it('Render hello world', async () => {
expect(await $fetch('/')).to.contain('Hello Vue 2!')
})
})
17 changes: 0 additions & 17 deletions test/examples/hello-world.test.ts

This file was deleted.

1 change: 1 addition & 0 deletions test/fixtures/basic/nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { addComponent } from '@nuxt/kit'

export default defineNuxtConfig({
buildDir: process.env.NITRO_BUILD_DIR,
vite: !process.env.TEST_WITH_WEBPACK,
nitro: {
output: { dir: process.env.NITRO_OUTPUT_DIR }
},
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/basic/pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<Head>
<Title>Basic fixture</Title>
</Head>
<h1>Hello Vue 3</h1>
<h1>Hello Nuxt 3!</h1>
<div>Config: {{ $config.testConfig }}</div>
<CustomComponent />
</div>
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/bridge/nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ export default defineNuxtConfig({
},
bridge: {
meta: true,
vite: !!process.env.TEST_BRIDGE_VITE
vite: !process.env.TEST_WITH_WEBPACK
}
})
83 changes: 0 additions & 83 deletions test/presets/_tests.ts

This file was deleted.

Loading

0 comments on commit 12a95ad

Please sign in to comment.