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 { join } from 'path'
import { nextTestSetup, isNextDev, isNextStart } from 'e2e-utils'
import { nextTestSetup } from 'e2e-utils'
import { check } from 'next-test-utils'
import { cleanImagesDir, expectWidth, fsToJson } from './util'
......@@ -281,19 +281,12 @@ describe('Image Optimizer', () => {
expect(res.status).toBe(200)
})
})
;(isNextStart ? describe : describe.skip)(
'Server support for headers in next.config.js',
() => {
const size = 96
const { next, skipped } = nextTestSetup({
files: join(__dirname, 'app'),
})
if (skipped) return
beforeAll(async () => {
await next.patchFile(
'next.config.js',
`module.exports = {
describe('Server support for headers in next.config.js', () => {
const size = 96
const { next, skipped, isNextDev } = nextTestSetup({
files: join(__dirname, 'app'),
nextConfig: {
async headers() {
return [
{
......@@ -307,221 +300,179 @@ describe('Image Optimizer', () => {
},
]
},
}`
)
})
afterAll(async () => {
await next.patchFile(
'next.config.js',
'// prettier-ignore\nmodule.exports = { /* replaceme */ }'
)
})
},
})
if (skipped) return
it('should set max-age header', async () => {
const query = { url: '/test.png', w: size, q: 75 }
const opts = { headers: { accept: 'image/webp' } }
const res = await next.fetch(
`/_next/image?${toQueryString(query)}`,
opts
)
expect(res.status).toBe(200)
expect(res.headers.get('Cache-Control')).toBe(
'public, max-age=14400, must-revalidate'
)
expect(res.headers.get('Content-Disposition')).toBe(
'attachment; filename="test.webp"'
)
it('should set max-age header', async () => {
const query = { url: '/test.png', w: size, q: 75 }
const opts = { headers: { accept: 'image/webp' } }
const res = await next.fetch(`/_next/image?${toQueryString(query)}`, opts)
expect(res.status).toBe(200)
expect(res.headers.get('Cache-Control')).toBe(
`public, max-age=${isNextDev ? 0 : 14400}, must-revalidate`
)
expect(res.headers.get('Content-Disposition')).toBe(
'attachment; filename="test.webp"'
)
const imagesDir = join(next.testDir, '.next', 'cache', 'images')
await check(async () => {
const files = await fsToJson(imagesDir)
let found = false
const maxAge = '14400'
Object.keys(files).forEach((dir) => {
if (
Object.keys(files[dir]).some((file) =>
file.includes(`${maxAge}.`)
)
) {
found = true
}
})
return found ? 'success' : 'failed'
}, 'success')
})
const imagesDir = join(next.testDir, next.distDir, 'cache', 'images')
await check(async () => {
const files = await fsToJson(imagesDir)
let found = false
const maxAge = '14400'
Object.keys(files).forEach((dir) => {
if (
Object.keys(files[dir]).some((file) => file.includes(`${maxAge}.`))
) {
found = true
}
})
return found ? 'success' : 'failed'
}, 'success')
})
it('should not set max-age header when not matching next.config.js', async () => {
const query = { url: '/test.jpg', w: size, q: 75 }
const opts = { headers: { accept: 'image/webp' } }
const res = await next.fetch(
`/_next/image?${toQueryString(query)}`,
opts
)
expect(res.status).toBe(200)
expect(res.headers.get('Cache-Control')).toBe(
'public, max-age=14400, must-revalidate'
)
expect(res.headers.get('Content-Disposition')).toBe(
'attachment; filename="test.webp"'
)
})
}
)
;(isNextDev ? describe : describe.skip)(
'dev support next.config.js cloudinary loader',
() => {
const { next, skipped } = nextTestSetup({
files: join(__dirname, 'app'),
nextConfig: {
images: {
loader: 'cloudinary',
path: 'https://example.com/act123/',
},
},
})
if (skipped) return
it('should not set max-age header when not matching next.config.js', async () => {
const query = { url: '/test.jpg', w: size, q: 75 }
const opts = { headers: { accept: 'image/webp' } }
const res = await next.fetch(`/_next/image?${toQueryString(query)}`, opts)
expect(res.status).toBe(200)
expect(res.headers.get('Cache-Control')).toBe(
`public, max-age=${isNextDev ? 0 : 14400}, must-revalidate`
)
expect(res.headers.get('Content-Disposition')).toBe(
'attachment; filename="test.webp"'
)
})
})
it('should 404 when loader is not default', async () => {
const size = 384
const query = { w: size, q: 90, url: '/test.svg' }
const opts = { headers: { accept: 'image/webp' } }
const res = await next.fetch(
`/_next/image?${toQueryString(query)}`,
opts
)
expect(res.status).toBe(404)
})
}
)
;(isNextDev ? describe : describe.skip)(
'images.unoptimized in next.config.js',
() => {
const { next, skipped } = nextTestSetup({
files: join(__dirname, 'app'),
nextConfig: {
images: { unoptimized: true },
describe('next.config.js cloudinary loader', () => {
const { next, skipped } = nextTestSetup({
files: join(__dirname, 'app'),
nextConfig: {
images: {
loader: 'cloudinary',
path: 'https://example.com/act123/',
},
})
if (skipped) return
},
})
if (skipped) return
it('should 404 when unoptimized', async () => {
const size = 384
const query = { w: size, q: 75, url: '/test.jpg' }
const opts = { headers: { accept: 'image/webp' } }
const res = await next.fetch(
`/_next/image?${toQueryString(query)}`,
opts
)
expect(res.status).toBe(404)
})
}
)
;(isNextDev ? describe : describe.skip)(
'experimental.imgOptMaxInputPixels in next.config.js',
() => {
const { next, skipped } = nextTestSetup({
files: join(__dirname, 'app'),
nextConfig: {
experimental: { imgOptMaxInputPixels: 100 },
},
})
if (skipped) return
it('should 404 when loader is not default', async () => {
const size = 384
const query = { w: size, q: 90, url: '/test.svg' }
const opts = { headers: { accept: 'image/webp' } }
const res = await next.fetch(`/_next/image?${toQueryString(query)}`, opts)
expect(res.status).toBe(404)
})
})
describe('images.unoptimized in next.config.js', () => {
const { next, skipped } = nextTestSetup({
files: join(__dirname, 'app'),
nextConfig: {
images: { unoptimized: true },
},
})
if (skipped) return
it('should fallback to source image when input exceeds imgOptMaxInputPixels', async () => {
const size = 256
const query = { w: size, q: 75, url: '/test.jpg' }
const opts = { headers: { accept: 'image/webp' } }
const res = await next.fetch(
`/_next/image?${toQueryString(query)}`,
opts
)
expect(res.status).toBe(200)
expect(res.headers.get('Content-Type')).toBe('image/jpeg')
})
}
)
;(isNextStart ? describe : describe.skip)(
'External rewrite support with for serving static content in images',
() => {
const { next, skipped } = nextTestSetup({
files: join(__dirname, 'app'),
nextConfig: {
async rewrites() {
return [
{
source: '/:base(next-js)/:rest*',
destination:
'https://assets.vercel.com/image/upload/v1538361091/repositories/:base/:rest*',
},
]
},
it('should 404 when unoptimized', async () => {
const size = 384
const query = { w: size, q: 75, url: '/test.jpg' }
const opts = { headers: { accept: 'image/webp' } }
const res = await next.fetch(`/_next/image?${toQueryString(query)}`, opts)
expect(res.status).toBe(404)
})
})
describe('experimental.imgOptMaxInputPixels in next.config.js', () => {
const { next, skipped } = nextTestSetup({
files: join(__dirname, 'app'),
nextConfig: {
experimental: { imgOptMaxInputPixels: 100 },
},
})
if (skipped) return
it('should fallback to source image when input exceeds imgOptMaxInputPixels', async () => {
const size = 256
const query = { w: size, q: 75, url: '/test.jpg' }
const opts = { headers: { accept: 'image/webp' } }
const res = await next.fetch(`/_next/image?${toQueryString(query)}`, opts)
expect(res.status).toBe(200)
expect(res.headers.get('Content-Type')).toBe('image/jpeg')
})
})
describe('External rewrite support with for serving static content in images', () => {
const { next, skipped, isNextDev } = nextTestSetup({
files: join(__dirname, 'app'),
nextConfig: {
async rewrites() {
return [
{
source: '/:base(next-js)/:rest*',
destination:
'https://assets.vercel.com/image/upload/v1538361091/repositories/:base/:rest*',
},
]
},
})
if (skipped) return
},
})
if (skipped) return
it('should return response when image is served from an external rewrite', async () => {
const imagesDir = join(next.testDir, '.next', 'cache', 'images')
await cleanImagesDir(imagesDir)
it('should return response when image is served from an external rewrite', async () => {
const imagesDir = join(next.testDir, next.distDir, 'cache', 'images')
await cleanImagesDir(imagesDir)
const query = { url: '/next-js/next-js-bg.png', w: 64, q: 75 }
const opts = { headers: { accept: 'image/webp' } }
const res = await next.fetch(
`/_next/image?${toQueryString(query)}`,
opts
)
expect(res.status).toBe(200)
expect(res.headers.get('Content-Type')).toBe('image/webp')
expect(res.headers.get('Cache-Control')).toBe(
'public, max-age=31536000, must-revalidate'
)
expect(res.headers.get('Vary')).toBe('Accept')
expect(res.headers.get('Content-Disposition')).toBe(
'attachment; filename="next-js-bg.webp"'
)
const query = { url: '/next-js/next-js-bg.png', w: 64, q: 75 }
const opts = { headers: { accept: 'image/webp' } }
const res = await next.fetch(`/_next/image?${toQueryString(query)}`, opts)
expect(res.status).toBe(200)
expect(res.headers.get('Content-Type')).toBe('image/webp')
expect(res.headers.get('Cache-Control')).toBe(
`public, max-age=${isNextDev ? 0 : 31536000}, must-revalidate`
)
expect(res.headers.get('Vary')).toBe('Accept')
expect(res.headers.get('Content-Disposition')).toBe(
'attachment; filename="next-js-bg.webp"'
)
await check(async () => {
const files = await fsToJson(imagesDir)
let found = false
const maxAge = '31536000'
Object.keys(files).forEach((dir) => {
if (
Object.keys(files[dir]).some((file) =>
file.includes(`${maxAge}.`)
)
) {
found = true
}
})
return found ? 'success' : 'failed'
}, 'success')
await expectWidth(res, 64)
})
}
)
;(isNextDev ? describe : describe.skip)(
'dev support for dynamic blur placeholder',
() => {
const { next, skipped } = nextTestSetup({
files: join(__dirname, 'app'),
nextConfig: {
images: {
deviceSizes: [largeSize],
imageSizes: [],
},
await check(async () => {
const files = await fsToJson(imagesDir)
let found = false
const maxAge = '31536000'
Object.keys(files).forEach((dir) => {
if (
Object.keys(files[dir]).some((file) => file.includes(`${maxAge}.`))
) {
found = true
}
})
return found ? 'success' : 'failed'
}, 'success')
await expectWidth(res, 64)
})
})
// Only development accepts the implicit blur-placeholder width and quality.
// @gate dev
describe('dev support for dynamic blur placeholder', () => {
const { next, skipped } = nextTestSetup({
files: join(__dirname, 'app'),
nextConfig: {
images: {
deviceSizes: [largeSize],
imageSizes: [],
},
})
if (skipped) return
},
})
if (skipped) return
it('should support width 8 per BLUR_IMG_SIZE with next dev', async () => {
const query = { url: '/test.png', w: 8, q: 70 }
const opts = { headers: { accept: 'image/webp' } }
const res = await next.fetch(
`/_next/image?${toQueryString(query)}`,
opts
)
expect(res.status).toBe(200)
await expectWidth(res, 320)
})
}
)
it('should support width 8 per BLUR_IMG_SIZE with next dev', async () => {
const query = { url: '/test.png', w: 8, q: 70 }
const opts = { headers: { accept: 'image/webp' } }
const res = await next.fetch(`/_next/image?${toQueryString(query)}`, opts)
expect(res.status).toBe(200)
await expectWidth(res, 320)
})
})
})
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