Unverified Commit cc0cdc8b authored by Niklas Mischkulnig's avatar Niklas Mischkulnig Committed by GitHub

test: remove some more dev/prod gating (#100717)

**View diff without whitespace**

Removes unnecessary dev/production restrictions to expand test coverage,
consolidates duplicate suites, and replaces remaining conditional skips
with explicit gate directives.
parent 5988244c
......@@ -13,43 +13,41 @@ describe.each([
},
},
])('unused scss', ({ dependencies, nextConfig }) => {
describe('Body is not hidden when unused in Development ($dependencies)', () => {
const { next, isNextDev } = nextTestSetup({
describe('Body is not hidden when unused ($dependencies)', () => {
const { next } = nextTestSetup({
files: __dirname,
dependencies,
nextConfig,
})
;(isNextDev ? describe : describe.skip)('development only', () => {
it('should have body visible', async () => {
const browser = await next.browser('/')
const currentDisplay = await browser.eval(
`window.getComputedStyle(document.querySelector('body')).display`
)
expect(currentDisplay).toBe('block')
})
it('should have body visible', async () => {
const browser = await next.browser('/')
const currentDisplay = await browser.eval(
`window.getComputedStyle(document.querySelector('body')).display`
)
expect(currentDisplay).toBe('block')
})
})
// This test introduces a syntax error after startup and requires HMR.
// @force-gate dev
describe('Body is not hidden when broken in Development', () => {
const { next, isNextDev } = nextTestSetup({
const { next } = nextTestSetup({
files: __dirname,
dependencies,
nextConfig,
})
;(isNextDev ? describe : describe.skip)('development only', () => {
it('should have body visible', async () => {
await next.patchFile('pages/index.js', (contents) => {
return contents.replace('<div />', '<div>')
})
const browser = await next.browser('/')
const currentDisplay = await browser.eval(
`window.getComputedStyle(document.querySelector('body')).display`
)
expect(currentDisplay).toBe('block')
it('should have body visible', async () => {
await next.patchFile('pages/index.js', (contents) => {
return contents.replace('<div />', '<div>')
})
const browser = await next.browser('/')
const currentDisplay = await browser.eval(
`window.getComputedStyle(document.querySelector('body')).display`
)
expect(currentDisplay).toBe('block')
})
})
})
import { join } from 'path'
import { nextTestSetup, isNextDev, isNextStart } from 'e2e-utils'
import { nextTestSetup, isNextStart } from 'e2e-utils'
import { findPort, initNextServerScript, killApp } from 'next-test-utils'
// Deploy mode exclusion: This suite starts an HTTP server on a local port and
// patches that port into next.config.js, which a deployment can't reach.
// @force-gate !deploy
describe('Fetch polyfill with ky-universal', () => {
;(isNextDev ? describe : describe.skip)('development mode', () => {
const { next } = nextTestSetup({
files: __dirname,
skipStart: true,
dependencies: { 'ky-universal': '0.6.0', ky: '0.19.1' },
})
let apiServerPort: number
let apiServer: any
beforeAll(async () => {
const scriptPath = join(__dirname, 'api-server.js')
apiServerPort = await findPort()
apiServer = await initNextServerScript(
scriptPath,
/ready on/i,
{ ...process.env, PORT: String(apiServerPort) },
/ReferenceError: options is not defined/
)
next.env.NEXT_PUBLIC_API_PORT = String(apiServerPort)
await next.start()
})
afterAll(async () => {
await killApp(apiServer)
})
it('includes polyfilled fetch when using getStaticProps (dev)', async () => {
const html = await next.render('/static')
expect(html).toMatch(/bar/)
})
it('includes polyfilled fetch when using getServerSideProps (dev)', async () => {
const html = await next.render('/ssr')
expect(html).toMatch(/bar/)
})
it('includes polyfilled fetch when using getInitialProps (dev)', async () => {
const html = await next.render('/getinitialprops')
expect(html).toMatch(/bar/)
})
const { next } = nextTestSetup({
files: __dirname,
skipStart: true,
dependencies: { 'ky-universal': '0.6.0', ky: '0.19.1' },
})
;(isNextStart ? describe : describe.skip)('production mode', () => {
const { next } = nextTestSetup({
files: __dirname,
skipStart: true,
dependencies: { 'ky-universal': '0.6.0', ky: '0.19.1' },
})
let apiServerPort: number
let apiServer: any
beforeAll(async () => {
const scriptPath = join(__dirname, 'api-server.js')
apiServerPort = await findPort()
apiServer = await initNextServerScript(
scriptPath,
/ready on/i,
{ ...process.env, PORT: String(apiServerPort) },
/ReferenceError: options is not defined/
)
next.env.NEXT_PUBLIC_API_PORT = String(apiServerPort)
let apiServerPort: number
let apiServer: any
beforeAll(async () => {
const scriptPath = join(__dirname, 'api-server.js')
apiServerPort = await findPort()
apiServer = await initNextServerScript(
scriptPath,
/ready on/i,
{ ...process.env, PORT: String(apiServerPort) },
/ReferenceError: options is not defined/
)
next.env.NEXT_PUBLIC_API_PORT = String(apiServerPort)
if (isNextStart) {
await next.build()
await next.start()
})
}
await next.start()
})
afterAll(async () => {
await killApp(apiServer)
})
afterAll(async () => {
await killApp(apiServer)
})
it('includes polyfilled fetch when using getStaticProps (prod)', async () => {
const html = await next.render('/static')
expect(html).toMatch(/bar/)
})
it('includes polyfilled fetch when using getStaticProps', async () => {
const html = await next.render('/static')
expect(html).toMatch(/bar/)
})
it('includes polyfilled fetch when using getServerSideProps (prod)', async () => {
const html = await next.render('/ssr')
expect(html).toMatch(/bar/)
})
it('includes polyfilled fetch when using getServerSideProps', async () => {
const html = await next.render('/ssr')
expect(html).toMatch(/bar/)
})
it('includes polyfilled fetch when using getInitialProps (prod)', async () => {
const html = await next.render('/getinitialprops')
expect(html).toMatch(/bar/)
})
it('includes polyfilled fetch when using getInitialProps', async () => {
const html = await next.render('/getinitialprops')
expect(html).toMatch(/bar/)
})
})
......@@ -60,107 +60,103 @@ describe('i18n Support basePath', () => {
afterAll(() => {
externalServer?.close()
})
;(isNextDev ? describe : describe.skip)('development mode', () => {
runTests(ctx)
})
;(!isNextDev ? describe : describe.skip)('production mode', () => {
runTests(ctx)
})
runTests(ctx)
// These checks rebuild the fixture and inspect the production routes manifest.
// @force-gate !dev
describe('with localeDetection disabled', () => {
if (!isNextDev) {
beforeAll(async () => {
await next.stop()
await next.patchFile('next.config.js', (content) =>
content.replace('// localeDetection', 'localeDetection')
)
await next.build()
await next.start()
ctx.appPort = Number(new URL(next.url).port)
})
beforeAll(async () => {
await next.stop()
await next.patchFile('next.config.js', (content) =>
content.replace('// localeDetection', 'localeDetection')
)
await next.build()
await next.start()
ctx.appPort = Number(new URL(next.url).port)
})
it('should have localeDetection in routes-manifest', async () => {
const routesManifest = JSON.parse(
await next.readFile('.next/routes-manifest.json')
)
it('should have localeDetection in routes-manifest', async () => {
const routesManifest = JSON.parse(
await next.readFile('.next/routes-manifest.json')
)
expect(routesManifest.i18n).toEqual({
localeDetection: false,
locales: [
'en-US',
'nl-NL',
'nl-BE',
'nl',
'fr-BE',
'fr',
'en',
'go',
'go-BE',
'do',
'do-BE',
],
defaultLocale: 'en-US',
domains: [
{
http: true,
domain: 'example.do',
defaultLocale: 'do',
locales: ['do-BE'],
},
{
domain: 'example.com',
defaultLocale: 'go',
locales: ['go-BE'],
},
],
})
expect(routesManifest.i18n).toEqual({
localeDetection: false,
locales: [
'en-US',
'nl-NL',
'nl-BE',
'nl',
'fr-BE',
'fr',
'en',
'go',
'go-BE',
'do',
'do-BE',
],
defaultLocale: 'en-US',
domains: [
{
http: true,
domain: 'example.do',
defaultLocale: 'do',
locales: ['do-BE'],
},
{
domain: 'example.com',
defaultLocale: 'go',
locales: ['go-BE'],
},
],
})
})
it('should not detect locale from accept-language', async () => {
const res = await fetchViaHTTP(
ctx.appPort,
`${ctx.basePath || '/'}`,
{},
{
redirect: 'manual',
headers: {
'accept-language': 'fr',
},
}
)
expect(res.status).toBe(200)
const $ = cheerio.load(await res.text())
expect($('html').attr('lang')).toBe('en-US')
expect($('#router-locale').text()).toBe('en-US')
expect(JSON.parse($('#router-locales').text())).toEqual(locales)
expect($('#router-pathname').text()).toBe('/')
expect($('#router-as-path').text()).toBe('/')
})
it('should not detect locale from accept-language', async () => {
it('should set locale from detected path', async () => {
for (const locale of locales) {
const res = await fetchViaHTTP(
ctx.appPort,
`${ctx.basePath || '/'}`,
`${ctx.basePath}/${locale}`,
{},
{
redirect: 'manual',
headers: {
'accept-language': 'fr',
'accept-language': 'en-US,en;q=0.9',
},
}
)
expect(res.status).toBe(200)
const $ = cheerio.load(await res.text())
expect($('html').attr('lang')).toBe('en-US')
expect($('#router-locale').text()).toBe('en-US')
expect($('html').attr('lang')).toBe(locale)
expect($('#router-locale').text()).toBe(locale)
expect(JSON.parse($('#router-locales').text())).toEqual(locales)
expect($('#router-pathname').text()).toBe('/')
expect($('#router-as-path').text()).toBe('/')
})
it('should set locale from detected path', async () => {
for (const locale of locales) {
const res = await fetchViaHTTP(
ctx.appPort,
`${ctx.basePath}/${locale}`,
{},
{
redirect: 'manual',
headers: {
'accept-language': 'en-US,en;q=0.9',
},
}
)
expect(res.status).toBe(200)
const $ = cheerio.load(await res.text())
expect($('html').attr('lang')).toBe(locale)
expect($('#router-locale').text()).toBe(locale)
expect(JSON.parse($('#router-locales').text())).toEqual(locales)
expect($('#router-pathname').text()).toBe('/')
expect($('#router-as-path').text()).toBe('/')
}
})
}
}
})
})
})
import { nextTestSetup, isNextDev, isNextStart } from 'e2e-utils'
import { nextTestSetup, isNextDev } from 'e2e-utils'
import { retry } from 'next-test-utils'
// TODO(deploy-test-completion): Re-enable this suite in deploy mode.
......@@ -32,9 +32,8 @@ describe('Errors on invalid custom middleware matchers', () => {
)
}
/** Same branching as integration `runTests(getStderr, isDev)`. */
function assertInvalidMatchersStderr(stderr: string, isDev: boolean) {
if (isTurbopack && !isDev) {
function assertInvalidMatchersStderr(stderr: string) {
if (isTurbopack && !isNextDev) {
expect(stderr).toContain('Turbopack build failed with 10 errors')
let matches = 0
......@@ -109,102 +108,91 @@ describe('Errors on invalid custom middleware matchers', () => {
}
}
function runTests(mode: 'dev' | 'start') {
const isDevMode = mode === 'dev'
it('should error when source length is exceeded', async () => {
await writeMiddleware([{ source: `/${Array(4096).join('a')}` }])
if (isDevMode) {
await next.start()
try {
await next.fetch('/').catch(() => {})
await retry(() => {
expect(next.cliOutput).toContain(
'exceeds max built length of 4096 for route'
)
})
} finally {
await next.stop()
}
} else {
await next.build()
expect(next.cliOutput).toContain(
'exceeds max built length of 4096 for route'
)
it('should error when source length is exceeded', async () => {
await writeMiddleware([{ source: `/${Array(4096).join('a')}` }])
if (isNextDev) {
await next.start()
try {
await next.fetch('/').catch(() => {})
await retry(() => {
expect(next.cliOutput).toContain(
'exceeds max built length of 4096 for route'
)
})
} finally {
await next.stop()
}
})
} else {
await next.build()
expect(next.cliOutput).toContain(
'exceeds max built length of 4096 for route'
)
}
})
it('should error during next build for invalid matchers', async () => {
await writeMiddleware([
{
// missing source
},
{
// invalid source
source: 123,
},
// missing forward slash in source
'hello',
{
// extra field
source: '/hello',
destination: '/not-allowed',
},
// invalid objects
null,
// invalid has items
{
source: '/hello',
has: [
{
type: 'cookiee',
key: 'loggedIn',
},
],
},
{
source: '/hello',
has: [
{
type: 'headerr',
},
{
type: 'queryr',
key: 'hello',
},
],
},
{
source: '/hello',
basePath: false,
},
{
source: '/hello',
locale: true,
},
])
it('should error during next build for invalid matchers', async () => {
await writeMiddleware([
{
// missing source
},
{
// invalid source
source: 123,
},
// missing forward slash in source
'hello',
{
// extra field
source: '/hello',
destination: '/not-allowed',
},
// invalid objects
null,
// invalid has items
{
source: '/hello',
has: [
{
type: 'cookiee',
key: 'loggedIn',
},
],
},
{
source: '/hello',
has: [
{
type: 'headerr',
},
{
type: 'queryr',
key: 'hello',
},
],
},
{
source: '/hello',
basePath: false,
},
{
source: '/hello',
locale: true,
},
])
if (isDevMode) {
await next.start()
try {
await next.fetch('/').catch(() => {})
await retry(async () => {
assertInvalidMatchersStderr(next.cliOutput, isDevMode)
})
} finally {
await next.stop()
}
} else {
await next.build()
assertInvalidMatchersStderr(next.cliOutput, isDevMode)
if (isNextDev) {
await next.start()
try {
await next.fetch('/').catch(() => {})
await retry(async () => {
assertInvalidMatchersStderr(next.cliOutput)
})
} finally {
await next.stop()
}
})
}
;(isNextDev ? describe : describe.skip)('development mode', () => {
runTests('dev')
})
;(isNextStart ? describe : describe.skip)('production mode', () => {
runTests('start')
} else {
await next.build()
assertInvalidMatchersStderr(next.cliOutput)
}
})
})
import { nextTestSetup, isNextDev, isNextStart } from 'e2e-utils'
import { nextTestSetup } from 'e2e-utils'
import {
getClientBuildManifestLoaderChunkUrlPath,
retry,
......@@ -45,17 +45,13 @@ describe('Link ref forwarding', () => {
await browser.close()
}
function runCommonTests() {
it('should not have a race condition with a click handler', async () => {
const browser = await next.browser('/click-away-race-condition')
await browser.elementByCss('#click-me').click()
await browser.waitForElementByCss('#the-menu')
})
}
;(isNextDev ? describe : describe.skip)('development mode', () => {
runCommonTests()
it('should not have a race condition with a click handler', async () => {
const browser = await next.browser('/click-away-race-condition')
await browser.elementByCss('#click-me').click()
await browser.waitForElementByCss('#the-menu')
})
describe('ref forwarding', () => {
it('should not show error for function component with forwardRef', async () => {
await noError('/function')
})
......@@ -76,9 +72,10 @@ describe('Link ref forwarding', () => {
await noError('/child-ref-func-cleanup')
})
})
;(isNextStart ? describe : describe.skip)('production mode', () => {
runCommonTests()
// Prefetching is disabled in dev, and these checks read the local build manifest.
// @force-gate start
describe('production mode', () => {
it('should preload with forwardRef', async () => {
await didPrefetch('/function')
})
......
......@@ -4,31 +4,28 @@ import {
testShouldRedirect,
testLinkShouldRewriteTo,
} from './shared-tests.util'
import { nextTestSetup, isNextDev } from 'e2e-utils'
import { nextTestSetup } from 'e2e-utils'
// we don't need to exhaustively test this, just do some basic sanity checks
// for use in combiantion with basePath
;(isNextDev ? describe : describe.skip)(
'Trailing slashes in development mode, with basepath, trailingSlash: true',
() => {
const { next } = nextTestSetup({
files: __dirname,
nextConfig: {
trailingSlash: true,
basePath: '/docs',
},
})
// for use in combination with basePath
describe('Trailing slashes with basePath, trailingSlash: true', () => {
const { next } = nextTestSetup({
files: __dirname,
nextConfig: {
trailingSlash: true,
basePath: '/docs',
},
})
testShouldRedirect(next, [
['/docs/about', '/docs/about/'],
['/docs', '/docs/'],
['/docs/catch-all/hello/world', '/docs/catch-all/hello/world/'],
['/docs/catch-all/hello.world/', '/docs/catch-all/hello.world'],
])
testShouldRedirect(next, [
['/docs/about', '/docs/about/'],
['/docs', '/docs/'],
['/docs/catch-all/hello/world', '/docs/catch-all/hello/world/'],
['/docs/catch-all/hello.world/', '/docs/catch-all/hello.world'],
])
testLinkShouldRewriteTo(next, [
['/docs/linker?href=/about', '/docs/about/'],
['/docs/linker?href=/', '/docs/'],
])
}
)
testLinkShouldRewriteTo(next, [
['/docs/linker?href=/about', '/docs/about/'],
['/docs/linker?href=/', '/docs/'],
])
})
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