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