Unverified Commit d3499931 authored by Jamiboy Mohammad's avatar Jamiboy Mohammad Committed by GitHub

test: enable deploy coverage for asset and compiler errors (#98850)

## Summary
Enable deployment coverage for 15 asset/compiler exclusion locations
using the deferred deployment lifecycle from #98776. Replace local-only
build calls with explicit start/failure assertions and retain the
expected image, Sass, loader, foreign-package, and missing-dependency
diagnostics. Preserve the existing development-only and bundler-specific
exclusions.

## Verification
- All applicable focused Turbopack production/development and Webpack
production checks passed.
- Local checks used the published native binding. Exact native and
deploy validation are pending repository CI.

<!-- NEXT_JS_LLM -->

---------
Co-authored-by: 's avatarClaude Opus 5 <noreply@anthropic.com>
parent ef0d79f5
......@@ -28,19 +28,16 @@ describe('Error test if the loader file export a named function', () => {
})
})
// @force-gate !dev
describe('in Build and Start', () => {
const { next, isNextStart } = nextTestSetup({
const { next } = nextTestSetup({
skipStart: true,
files: __dirname,
})
;(isNextStart ? describe : describe.skip)('build and start only', () => {
it('should show the build error', async () => {
await expect(next.start()).rejects.toThrow(
'next build failed with code/signal 1'
)
expect(next.cliOutput).toContain(errorMessage)
})
})
it('should show the build error', async () => {
await expect(next.start()).rejects.toThrow()
expect(next.cliOutput).toContain(errorMessage)
}, 240_000)
})
})
import { nextTestSetup } from 'e2e-utils'
describe('metadata-invalid-image-file', () => {
const { next, isTurbopack, isNextDev, skipped, isRspack } = nextTestSetup({
const { next, isTurbopack, isNextDev, isRspack } = nextTestSetup({
files: __dirname,
skipDeployment: true,
skipStart: true,
})
if (skipped) return
it('should error on invalid metadata image file', async () => {
// In dev, it needs to render the page first
if (isNextDev) {
await next.start()
await next.fetch('/')
} else {
await next.build()
await expect(next.start()).rejects.toThrow()
}
if (isTurbopack) {
......@@ -43,5 +40,5 @@ describe('metadata-invalid-image-file', () => {
)
}
}
})
}, 240_000)
})
import { nextTestSetup } from 'e2e-utils'
describe('next-image-legacy-src-with-query-without-local-patterns', () => {
const { next, isNextDev, skipped } = nextTestSetup({
const { next, isNextDev, isNextDeploy } = nextTestSetup({
files: __dirname,
skipStart: true,
skipDeployment: true,
})
if (skipped) {
return
}
it('should throw error for relative image with query without localPatterns for legacy Image', async () => {
if (isNextDev) {
await next.start()
......@@ -19,10 +14,17 @@ describe('next-image-legacy-src-with-query-without-local-patterns', () => {
'Image with src "/test.png?v=1" is using a query string which is not configured in images.localPatterns.\nRead more: https://nextjs.org/docs/messages/next-image-unconfigured-localpatterns'
)
} else {
const { cliOutput } = await next.build()
await expect(next.start()).rejects.toThrow()
// Deployment build logs prefix each line with an ISO timestamp.
const cliOutput = isNextDeploy
? next.cliOutput.replace(
/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z {2}/gm,
''
)
: next.cliOutput
expect(cliOutput).toContain(
'Image with src "/test.png?v=1" is using a query string which is not configured in images.localPatterns.\nRead more: https://nextjs.org/docs/messages/next-image-unconfigured-localpatterns'
)
}
})
}, 240_000)
})
import { nextTestSetup } from 'e2e-utils'
describe('next-image-src-with-query-without-local-patterns', () => {
const { next, isNextDev, skipped } = nextTestSetup({
const { next, isNextDev } = nextTestSetup({
files: __dirname,
skipStart: true,
skipDeployment: true,
})
if (skipped) {
return
}
it('should throw error for relative image with query without localPatterns', async () => {
if (isNextDev) {
await next.start()
......@@ -19,10 +14,11 @@ describe('next-image-src-with-query-without-local-patterns', () => {
'Image with src "/test.png?v=1" is using a query string which is not configured in images.localPatterns.\nRead more: https://nextjs.org/docs/messages/next-image-unconfigured-localpatterns'
)
} else {
const { cliOutput } = await next.build()
await expect(next.start()).rejects.toThrow()
const cliOutput = next.cliOutput
expect(cliOutput).toContain(
'Image with src "/test.png?v=1" is using a query string which is not configured in images.localPatterns.\nRead more: https://nextjs.org/docs/messages/next-image-unconfigured-localpatterns'
)
}
})
}, 240_000)
})
/* eslint-env jest */
import { isNextStart, nextTestSetup } from 'e2e-utils'
import { isNextDev, nextTestSetup } from 'e2e-utils'
import { waitForRedbox, getRedboxSource } from 'next-test-utils'
describe('Invalid Global CSS with Custom App', () => {
const { next, skipped, isTurbopack, isRspack } = nextTestSetup({
const { next, isTurbopack, isRspack } = nextTestSetup({
files: __dirname,
skipStart: isNextStart,
skipDeployment: true,
skipStart: !isNextDev,
dependencies: { sass: '1.54.0' },
})
if (skipped) {
return
}
if (isNextStart) {
if (!isNextDev) {
it('should fail to build', async () => {
const { exitCode, cliOutput } = await next.build()
expect(exitCode).not.toBe(0)
await expect(next.start()).rejects.toThrow()
const cliOutput = next.cliOutput
if (!isTurbopack) {
expect(cliOutput).toContain('Failed to compile')
}
......@@ -30,7 +26,7 @@ describe('Invalid Global CSS with Custom App', () => {
if (!process.env.NEXT_RSPACK) {
expect(cliOutput).toMatch(/Location:.*pages[\\/]index\.js/)
}
})
}, 240_000)
} else {
it('should show a build error', async () => {
const browser = await next.browser('/')
......
/* eslint-env jest */
import { isNextStart, nextTestSetup } from 'e2e-utils'
import { isNextDev, nextTestSetup } from 'e2e-utils'
import { waitForRedbox, getRedboxSource } from 'next-test-utils'
describe('Invalid Global CSS', () => {
const { next, skipped, isTurbopack, isRspack } = nextTestSetup({
const { next, isTurbopack, isRspack } = nextTestSetup({
files: __dirname,
skipStart: isNextStart,
skipDeployment: true,
skipStart: !isNextDev,
dependencies: { sass: '1.54.0' },
})
if (skipped) {
return
}
if (isNextStart) {
if (!isNextDev) {
it('should fail to build', async () => {
const { exitCode, cliOutput } = await next.build()
expect(exitCode).not.toBe(0)
await expect(next.start()).rejects.toThrow()
const cliOutput = next.cliOutput
if (!isTurbopack) {
expect(cliOutput).toContain('Failed to compile')
}
......@@ -30,7 +26,7 @@ describe('Invalid Global CSS', () => {
if (!process.env.NEXT_RSPACK) {
expect(cliOutput).toMatch(/Location:.*pages[\\/]index\.js/)
}
})
}, 240_000)
} else {
it('should show a build error', async () => {
const browser = await next.browser('/')
......
/* eslint-env jest */
import { isNextStart, nextTestSetup } from 'e2e-utils'
import { isNextDev, nextTestSetup } from 'e2e-utils'
import { waitForRedbox, getRedboxSource } from 'next-test-utils'
// Importing module CSS in _document is allowed in Turbopack
;(process.env.IS_TURBOPACK_TEST ? describe.skip : describe)(
'Invalid SCSS in _document',
() => {
const { next, skipped, isRspack } = nextTestSetup({
const { next, isRspack } = nextTestSetup({
files: __dirname,
skipStart: isNextStart,
skipDeployment: true,
skipStart: !isNextDev,
dependencies: { sass: '1.54.0' },
})
if (skipped) {
return
}
if (isNextStart) {
if (!isNextDev) {
it('should fail to build', async () => {
const { exitCode, cliOutput } = await next.build()
expect(exitCode).not.toBe(0)
await expect(next.start()).rejects.toThrow()
const cliOutput = next.cliOutput
expect(cliOutput).toContain('Failed to compile')
expect(cliOutput).toContain('styles.module.scss')
expect(cliOutput).toMatch(
......@@ -31,7 +27,7 @@ import { waitForRedbox, getRedboxSource } from 'next-test-utils'
if (!process.env.NEXT_RSPACK) {
expect(cliOutput).toMatch(/Location:.*pages[\\/]_document\.js/)
}
})
}, 240_000)
} else {
it('should show a build error', async () => {
const browser = await next.browser('/')
......
/* eslint-env jest */
import { isNextStart, nextTestSetup } from 'e2e-utils'
import { isNextDev, nextTestSetup } from 'e2e-utils'
import { waitForRedbox, getRedboxSource } from 'next-test-utils'
describe('CSS Import from node_modules', () => {
const { next, skipped, isTurbopack, isRspack } = nextTestSetup({
const { next, isTurbopack, isRspack } = nextTestSetup({
files: __dirname,
skipStart: isNextStart,
skipDeployment: true,
skipStart: !isNextDev,
dependencies: { sass: '1.54.0' },
})
if (skipped) {
return
}
if (isNextStart) {
if (!isNextDev) {
it('should fail the build', async () => {
const { exitCode, cliOutput } = await next.build()
expect(exitCode).not.toBe(0)
await expect(next.start()).rejects.toThrow()
const cliOutput = next.cliOutput
if (isRspack) {
expect(cliOutput).toMatch(
/RspackResolver\(NotFound\(\\?"nprogress\/nprogress.css\\?"\)\)/
......@@ -27,7 +23,7 @@ describe('CSS Import from node_modules', () => {
expect(cliOutput).toMatch(/Can't resolve '[^']*?nprogress[^']*?'/)
}
expect(cliOutput).toMatch(/Build failed|Build error occurred/)
})
}, 240_000)
} else {
it('should show a build error', async () => {
const browser = await next.browser('/')
......
/* eslint-env jest */
import { isNextStart, nextTestSetup } from 'e2e-utils'
import { isNextDev, nextTestSetup } from 'e2e-utils'
import { waitForRedbox, getRedboxSource } from 'next-test-utils'
describe('Valid and Invalid Global CSS with Custom App', () => {
const { next, skipped, isTurbopack, isRspack } = nextTestSetup({
const { next, isTurbopack, isRspack } = nextTestSetup({
files: __dirname,
skipStart: isNextStart,
skipDeployment: true,
skipStart: !isNextDev,
dependencies: { sass: '1.54.0' },
})
if (skipped) {
return
}
if (isNextStart) {
if (!isNextDev) {
it('should fail to build', async () => {
const { exitCode, cliOutput } = await next.build()
expect(exitCode).not.toBe(0)
await expect(next.start()).rejects.toThrow()
const cliOutput = next.cliOutput
if (!isTurbopack) {
expect(cliOutput).toContain('Failed to compile')
}
......@@ -30,7 +26,7 @@ describe('Valid and Invalid Global CSS with Custom App', () => {
if (!process.env.NEXT_RSPACK) {
expect(cliOutput).toMatch(/Location:.*pages[\\/]index\.js/)
}
})
}, 240_000)
} else {
it('should show a build error', async () => {
const browser = await next.browser('/')
......
......@@ -5,13 +5,12 @@ describe('SCSS Support', () => {
const { next, isNextDev } = nextTestSetup({
files: __dirname,
skipStart: true,
skipDeployment: true,
})
// Production only test
;(isNextDev ? describe.skip : describe)('Friendly Webpack Error', () => {
it('should be a friendly error successfully', async () => {
const { exitCode, cliOutput } = await next.build()
expect(exitCode).toBe(1)
await expect(next.start()).rejects.toThrow()
const cliOutput = next.cliOutput
expect(cliOutput).toContain('./styles/global.scss')
expect(cliOutput).toContain(
......@@ -26,6 +25,6 @@ describe('SCSS Support', () => {
expect(cliOutput).not.toContain('css-loader')
expect(cliOutput).not.toContain('sass-loader')
})
}, 240_000)
})
})
import { nextTestSetup } from 'e2e-utils'
describe('next-image-legacy-src-with-query-without-local-patterns', () => {
const { next, isNextDev, skipped } = nextTestSetup({
const { next, isNextDev } = nextTestSetup({
files: __dirname,
skipStart: true,
skipDeployment: true,
})
if (skipped) {
return
}
it('should throw error for relative image with query without localPatterns for legacy Image', async () => {
if (isNextDev) {
await next.start()
......@@ -19,10 +14,11 @@ describe('next-image-legacy-src-with-query-without-local-patterns', () => {
'Image with src "/test.png?v=1" is using a query string which is not configured in images.localPatterns.\nRead more: https://nextjs.org/docs/messages/next-image-unconfigured-localpatterns'
)
} else {
const { cliOutput } = await next.build()
await expect(next.start()).rejects.toThrow()
const cliOutput = next.cliOutput
expect(cliOutput).toContain(
'Image with src "/test.png?v=1" is using a query string which is not configured in images.localPatterns.\nRead more: https://nextjs.org/docs/messages/next-image-unconfigured-localpatterns'
)
}
})
}, 240_000)
})
import { nextTestSetup } from 'e2e-utils'
describe('next-image-src-with-query-without-local-patterns', () => {
const { next, isNextDev, skipped } = nextTestSetup({
const { next, isNextDev } = nextTestSetup({
files: __dirname,
skipStart: true,
skipDeployment: true,
})
if (skipped) {
return
}
it('should throw error for relative image with query without localPatterns', async () => {
if (isNextDev) {
await next.start()
......@@ -19,10 +14,11 @@ describe('next-image-src-with-query-without-local-patterns', () => {
'Image with src "/test.png?v=1" is using a query string which is not configured in images.localPatterns.\nRead more: https://nextjs.org/docs/messages/next-image-unconfigured-localpatterns'
)
} else {
const { cliOutput } = await next.build()
await expect(next.start()).rejects.toThrow()
const cliOutput = next.cliOutput
expect(cliOutput).toContain(
'Image with src "/test.png?v=1" is using a query string which is not configured in images.localPatterns.\nRead more: https://nextjs.org/docs/messages/next-image-unconfigured-localpatterns'
)
}
})
}, 240_000)
})
import { nextTestSetup } from 'e2e-utils'
import { join } from 'path'
// @force-gate !dev
describe('script-loader - partytown-missing', () => {
const { next, isNextDev } = nextTestSetup({
const { next, isNextDeploy } = nextTestSetup({
files: join(__dirname, 'partytown-missing'),
skipStart: true,
// Vercel deployment fails to build/deploy this fixture in CI; skip in deploy mode.
skipDeployment: true,
})
it('Error message is shown if Partytown is not installed locally', async () => {
if (isNextDev) return
const { cliOutput } = await next.build()
await expect(next.start()).rejects.toThrow()
// Deployment build logs prefix each line with an ISO timestamp.
const cliOutput = isNextDeploy
? next.cliOutput.replace(
/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z {2}/gm,
''
)
: next.cliOutput
expect(cliOutput.replace(/[\n\r]/g, '')).toMatch(
/It looks like you're trying to use Partytown with next\/script but do not have the required package\(s\) installed.Please install Partytown by running:.*?(npm|pnpm|yarn) (install|add) (--save-dev|--dev) @builder\.io\/partytownIf you are not trying to use Partytown, please disable the experimental "nextScriptWorkers" flag in next\.config\.js\./
)
})
}, 240_000)
})
import { nextTestSetup } from 'e2e-utils'
// vercel.json uses pnpm so file: dependencies are installed inside node_modules.
// npm links them to fixture source, which is transpiled without transpilePackages.
describe('transpile-packages-typescript-foreign', () => {
describe('without transpilePackages', () => {
const { next, skipped } = nextTestSetup({
const { next, isNextDev } = nextTestSetup({
files: __dirname,
skipDeployment: true,
skipStart: true,
// Use the fixture's packageManager version rather than Vercel's default pnpm.
env: { ENABLE_EXPERIMENTAL_COREPACK: '1' },
dependencies: {
pkg: `file:./pkg`,
},
})
if (skipped) {
return
}
it('should fail', async () => {
try {
await next.start()
await next.render('/')
} catch (e) {}
if (isNextDev) {
try {
await next.start()
await next.render('/')
} catch {}
} else {
await expect(next.start()).rejects.toThrow()
}
if (process.env.IS_TURBOPACK_TEST) {
expect(next.cliOutput).toContain(`pkg/index.ts
......@@ -35,12 +38,13 @@ This module doesn't have an associated type`)
expect(next.cliOutput).toContain(`pkg/index.ts
Module parse failed: Unexpected token`)
}
})
}, 240_000)
})
describe('with transpilePackages', () => {
const { next } = nextTestSetup({
files: __dirname,
env: { ENABLE_EXPERIMENTAL_COREPACK: '1' },
dependencies: {
pkg: `file:./pkg`,
},
......
......@@ -75,18 +75,12 @@ function extractErrorBlock(output: string, errorTitle: string): string {
return block.trimEnd()
}
// @force-gate dev
describe('webpack-loader-parse-error (development)', () => {
const { next, isTurbopack, isNextDev, skipped } = nextTestSetup({
const { next, isTurbopack } = nextTestSetup({
files: __dirname,
skipDeployment: true,
skipStart: true,
})
if (skipped) return
if (!isNextDev) {
it('skipped in production mode', () => {})
return
}
beforeAll(() => next.start())
......@@ -198,26 +192,29 @@ describe('webpack-loader-parse-error (development)', () => {
})
})
// @force-gate !dev
describe('webpack-loader-parse-error (production)', () => {
const { next, isNextStart, isTurbopack } = nextTestSetup({
const { next, isTurbopack, isNextDeploy } = nextTestSetup({
files: __dirname,
skipDeployment: true,
skipStart: true,
})
if (!isNextStart) {
it('skipped in development mode', () => {})
return
}
it('should fail the build with parse errors from loaders', async () => {
await expect(next.start()).rejects.toThrow(
'next build failed with code/signal 1'
)
await expect(next.start()).rejects.toThrow()
const output = normalizePaths(stripAnsi(next.cliOutput), next.testDir)
if (isTurbopack) {
if (isNextDeploy) {
// Deployment logs prefix every line with a timestamp and strip
// code-frame indentation, so the exact formatting the snapshots below
// assert cannot survive the round trip. Assert the error titles, which
// are single lines, and leave the formatting to the local build.
expect(output).toContain("Expected '</', got '{'")
if (isTurbopack) {
expect(output).toContain('Parsing CSS source code failed')
}
} else if (isTurbopack) {
const jsError = extractErrorBlock(output, "Expected '</', got '{'")
expect(jsError).toMatchInlineSnapshot(`
"./app/data.broken.js:3:1
......@@ -299,5 +296,5 @@ describe('webpack-loader-parse-error (production)', () => {
./app/page.js"
`)
}
})
}, 240_000)
})
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment