mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-29 17:07:22 +00:00
chore(ci): enable testing fixtures in development (#3755)
Co-authored-by: Anthony Fu <anthonyfu117@hotmail.com>
This commit is contained in:
parent
d5962a23ec
commit
2cc3aaba5f
5
.github/workflows/ci.yml
vendored
5
.github/workflows/ci.yml
vendored
@ -88,6 +88,11 @@ jobs:
|
|||||||
- name: Test (fixtures)
|
- name: Test (fixtures)
|
||||||
run: yarn test:fixtures
|
run: yarn test:fixtures
|
||||||
|
|
||||||
|
- name: Test (fixtures with dev)
|
||||||
|
run: yarn test:fixtures:dev
|
||||||
|
env:
|
||||||
|
NODE_OPTIONS: --max-old-space-size=8192
|
||||||
|
|
||||||
test-fixtures-webpack:
|
test-fixtures-webpack:
|
||||||
runs-on: ${{ matrix.os }}
|
runs-on: ${{ matrix.os }}
|
||||||
|
|
||||||
|
@ -23,6 +23,7 @@
|
|||||||
"release": "yarn && yarn lint && FORCE_COLOR=1 lerna publish -m \"chore: release\" && yarn stub",
|
"release": "yarn && yarn lint && FORCE_COLOR=1 lerna publish -m \"chore: release\" && yarn stub",
|
||||||
"stub": "lerna run prepack -- --stub",
|
"stub": "lerna run prepack -- --stub",
|
||||||
"test:fixtures": "yarn nuxi prepare test/fixtures/basic && JITI_ESM_RESOLVE=1 vitest run --dir test",
|
"test:fixtures": "yarn nuxi prepare test/fixtures/basic && JITI_ESM_RESOLVE=1 vitest run --dir test",
|
||||||
|
"test:fixtures:dev": "NUXT_TEST_DEV=true yarn test:fixtures",
|
||||||
"test:fixtures:webpack": "TEST_WITH_WEBPACK=1 yarn test:fixtures",
|
"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:types": "yarn run nuxi prepare test/fixtures/basic && cd test/fixtures/basic && npx vue-tsc --noEmit",
|
||||||
"test:unit": "JITI_ESM_RESOLVE=1 yarn vitest run --dir packages",
|
"test:unit": "JITI_ESM_RESOLVE=1 yarn vitest run --dir packages",
|
||||||
|
@ -37,7 +37,8 @@ export async function loadFixture () {
|
|||||||
|
|
||||||
ctx.options.rootDir = resolveRootDir()
|
ctx.options.rootDir = resolveRootDir()
|
||||||
|
|
||||||
const randomId = Math.random().toString(36).substr(2, 8)
|
if (!ctx.options.dev) {
|
||||||
|
const randomId = Math.random().toString(36).slice(2, 8)
|
||||||
const buildDir = resolve(ctx.options.rootDir, '.nuxt', randomId)
|
const buildDir = resolve(ctx.options.rootDir, '.nuxt', randomId)
|
||||||
Object.assign(ctx.options.nuxtConfig, {
|
Object.assign(ctx.options.nuxtConfig, {
|
||||||
buildDir,
|
buildDir,
|
||||||
@ -47,6 +48,7 @@ export async function loadFixture () {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
}
|
||||||
|
|
||||||
ctx.nuxt = await kit.loadNuxt({
|
ctx.nuxt = await kit.loadNuxt({
|
||||||
cwd: ctx.options.rootDir,
|
cwd: ctx.options.rootDir,
|
||||||
|
@ -10,14 +10,24 @@ export async function startServer () {
|
|||||||
const port = await getRandomPort()
|
const port = await getRandomPort()
|
||||||
ctx.url = 'http://localhost:' + port
|
ctx.url = 'http://localhost:' + port
|
||||||
if (ctx.options.dev) {
|
if (ctx.options.dev) {
|
||||||
ctx.listener = await ctx.nuxt.server.listen(port)
|
ctx.serverProcess = execa('npx', ['nuxi', 'dev'], {
|
||||||
await waitForPort(port, { retries: 8 })
|
cwd: ctx.nuxt.options.rootDir,
|
||||||
|
stdio: 'inherit',
|
||||||
|
env: {
|
||||||
|
...process.env,
|
||||||
|
PORT: String(port),
|
||||||
|
NODE_ENV: 'development'
|
||||||
|
}
|
||||||
|
})
|
||||||
|
await waitForPort(port, { retries: 16 })
|
||||||
for (let i = 0; i < 50; i++) {
|
for (let i = 0; i < 50; i++) {
|
||||||
await new Promise(resolve => setTimeout(resolve, 100))
|
await new Promise(resolve => setTimeout(resolve, 100))
|
||||||
|
try {
|
||||||
const res = await $fetch('/')
|
const res = await $fetch('/')
|
||||||
if (!res.includes('__NUXT_LOADING__')) {
|
if (!res.includes('__NUXT_LOADING__')) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
} catch {}
|
||||||
}
|
}
|
||||||
throw new Error('Timeout waiting for dev server!')
|
throw new Error('Timeout waiting for dev server!')
|
||||||
} else {
|
} else {
|
||||||
|
@ -147,7 +147,9 @@ describe('errors', () => {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
expect(res.status).toBe(500)
|
expect(res.status).toBe(500)
|
||||||
expect(await res.json()).toMatchInlineSnapshot(`
|
const error = await res.json()
|
||||||
|
delete error.stack
|
||||||
|
expect(error).toMatchInlineSnapshot(`
|
||||||
{
|
{
|
||||||
"message": "This is a custom error",
|
"message": "This is a custom error",
|
||||||
"statusCode": 500,
|
"statusCode": 500,
|
||||||
@ -302,6 +304,12 @@ describe('extends support', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
describe('dynamic paths', () => {
|
describe('dynamic paths', () => {
|
||||||
|
if (process.env.NUXT_TEST_DEV) {
|
||||||
|
// TODO:
|
||||||
|
it.todo('dynamic paths in dev')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
it('should work with no overrides', async () => {
|
it('should work with no overrides', async () => {
|
||||||
const html = await $fetch('/assets')
|
const html = await $fetch('/assets')
|
||||||
for (const match of html.matchAll(/(href|src)="(.*?)"/g)) {
|
for (const match of html.matchAll(/(href|src)="(.*?)"/g)) {
|
||||||
@ -311,13 +319,15 @@ describe('dynamic paths', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('adds relative paths to CSS', async () => {
|
it('adds relative paths to CSS', async () => {
|
||||||
const html = await $fetch('/assets')
|
|
||||||
const urls = Array.from(html.matchAll(/(href|src)="(.*?)"/g)).map(m => m[2])
|
|
||||||
const cssURL = urls.find(u => /_nuxt\/entry.*\.css$/.test(u))
|
|
||||||
if (process.env.TEST_WITH_WEBPACK) {
|
if (process.env.TEST_WITH_WEBPACK) {
|
||||||
// Webpack injects CSS differently
|
// Webpack injects CSS differently
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const html = await $fetch('/assets')
|
||||||
|
const urls = Array.from(html.matchAll(/(href|src)="(.*?)"/g)).map(m => m[2])
|
||||||
|
const cssURL = urls.find(u => /_nuxt\/entry.*\.css$/.test(u))
|
||||||
|
expect(cssURL).toBeDefined()
|
||||||
const css = await $fetch(cssURL)
|
const css = await $fetch(cssURL)
|
||||||
const imageUrls = Array.from(css.matchAll(/url\(([^)]*)\)/g)).map(m => m[1].replace(/[-.][\w]{8}\./g, '.'))
|
const imageUrls = Array.from(css.matchAll(/url\(([^)]*)\)/g)).map(m => m[1].replace(/[-.][\w]{8}\./g, '.'))
|
||||||
expect(imageUrls).toMatchInlineSnapshot(`
|
expect(imageUrls).toMatchInlineSnapshot(`
|
||||||
|
@ -32,7 +32,9 @@ describe('fixtures:bridge', async () => {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
expect(res.status).toBe(500)
|
expect(res.status).toBe(500)
|
||||||
expect(await res.json()).toMatchInlineSnapshot(`
|
const error = await res.json()
|
||||||
|
delete error.stack
|
||||||
|
expect(error).toMatchInlineSnapshot(`
|
||||||
{
|
{
|
||||||
"message": "This is a custom error",
|
"message": "This is a custom error",
|
||||||
"statusCode": 500,
|
"statusCode": 500,
|
||||||
@ -49,6 +51,11 @@ describe('fixtures:bridge', async () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
describe('dynamic paths', () => {
|
describe('dynamic paths', () => {
|
||||||
|
if (process.env.NUXT_TEST_DEV) {
|
||||||
|
// TODO:
|
||||||
|
it.todo('dynamic paths in dev')
|
||||||
|
return
|
||||||
|
}
|
||||||
if (process.env.TEST_WITH_WEBPACK) {
|
if (process.env.TEST_WITH_WEBPACK) {
|
||||||
// TODO:
|
// TODO:
|
||||||
it.todo('work with webpack')
|
it.todo('work with webpack')
|
||||||
|
@ -8,5 +8,8 @@ export default defineConfig({
|
|||||||
},
|
},
|
||||||
esbuild: {
|
esbuild: {
|
||||||
tsconfigRaw: '{}'
|
tsconfigRaw: '{}'
|
||||||
|
},
|
||||||
|
test: {
|
||||||
|
testTimeout: 10000
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user