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,14 +13,13 @@ 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(
......@@ -29,16 +28,16 @@ describe.each([
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>')
......@@ -51,5 +50,4 @@ describe.each([
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/)
})
})
;(isNextStart ? describe : describe.skip)('production mode', () => {
const { next } = nextTestSetup({
files: __dirname,
skipStart: true,
......@@ -67,7 +26,9 @@ describe('Fetch polyfill with ky-universal', () => {
)
next.env.NEXT_PUBLIC_API_PORT = String(apiServerPort)
if (isNextStart) {
await next.build()
}
await next.start()
})
......@@ -75,19 +36,18 @@ describe('Fetch polyfill with ky-universal', () => {
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')
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')
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')
expect(html).toMatch(/bar/)
})
})
})
......@@ -60,15 +60,12 @@ describe('i18n Support basePath', () => {
afterAll(() => {
externalServer?.close()
})
;(isNextDev ? describe : describe.skip)('development mode', () => {
runTests(ctx)
})
;(!isNextDev ? describe : describe.skip)('production mode', () => {
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) =>
......@@ -161,6 +158,5 @@ describe('i18n Support basePath', () => {
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',
() => {
describe('Server support for headers in next.config.js', () => {
const size = 96
const { next, skipped } = nextTestSetup({
const { next, skipped, isNextDev } = nextTestSetup({
files: join(__dirname, 'app'),
})
if (skipped) return
beforeAll(async () => {
await next.patchFile(
'next.config.js',
`module.exports = {
nextConfig: {
async headers() {
return [
{
......@@ -307,41 +300,30 @@ 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
)
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'
`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')
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}.`)
)
Object.keys(files[dir]).some((file) => file.includes(`${maxAge}.`))
) {
found = true
}
......@@ -353,23 +335,18 @@ describe('Image Optimizer', () => {
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
)
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'
`public, max-age=${isNextDev ? 0 : 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',
() => {
})
describe('next.config.js cloudinary loader', () => {
const { next, skipped } = nextTestSetup({
files: join(__dirname, 'app'),
nextConfig: {
......@@ -385,17 +362,11 @@ describe('Image Optimizer', () => {
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
)
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',
() => {
})
describe('images.unoptimized in next.config.js', () => {
const { next, skipped } = nextTestSetup({
files: join(__dirname, 'app'),
nextConfig: {
......@@ -408,17 +379,11 @@ describe('Image Optimizer', () => {
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
)
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',
() => {
})
describe('experimental.imgOptMaxInputPixels in next.config.js', () => {
const { next, skipped } = nextTestSetup({
files: join(__dirname, 'app'),
nextConfig: {
......@@ -431,19 +396,14 @@ describe('Image Optimizer', () => {
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
)
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({
})
describe('External rewrite support with for serving static content in images', () => {
const { next, skipped, isNextDev } = nextTestSetup({
files: join(__dirname, 'app'),
nextConfig: {
async rewrites() {
......@@ -460,19 +420,16 @@ describe('Image Optimizer', () => {
if (skipped) return
it('should return response when image is served from an external rewrite', async () => {
const imagesDir = join(next.testDir, '.next', 'cache', 'images')
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
)
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'
`public, max-age=${isNextDev ? 0 : 31536000}, must-revalidate`
)
expect(res.headers.get('Vary')).toBe('Accept')
expect(res.headers.get('Content-Disposition')).toBe(
......@@ -485,9 +442,7 @@ describe('Image Optimizer', () => {
const maxAge = '31536000'
Object.keys(files).forEach((dir) => {
if (
Object.keys(files[dir]).some((file) =>
file.includes(`${maxAge}.`)
)
Object.keys(files[dir]).some((file) => file.includes(`${maxAge}.`))
) {
found = true
}
......@@ -496,11 +451,11 @@ describe('Image Optimizer', () => {
}, 'success')
await expectWidth(res, 64)
})
}
)
;(isNextDev ? describe : describe.skip)(
'dev support for dynamic blur placeholder',
() => {
})
// 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: {
......@@ -515,13 +470,9 @@ describe('Image Optimizer', () => {
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
)
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,12 +108,9 @@ 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) {
if (isNextDev) {
await next.start()
try {
await next.fetch('/').catch(() => {})
......@@ -184,27 +180,19 @@ describe('Errors on invalid custom middleware matchers', () => {
},
])
if (isDevMode) {
if (isNextDev) {
await next.start()
try {
await next.fetch('/').catch(() => {})
await retry(async () => {
assertInvalidMatchersStderr(next.cliOutput, isDevMode)
assertInvalidMatchersStderr(next.cliOutput)
})
} finally {
await next.stop()
}
} else {
await next.build()
assertInvalidMatchersStderr(next.cliOutput, isDevMode)
}
})
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 {
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()
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,13 +4,11 @@ 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',
() => {
// for use in combination with basePath
describe('Trailing slashes with basePath, trailingSlash: true', () => {
const { next } = nextTestSetup({
files: __dirname,
nextConfig: {
......@@ -30,5 +28,4 @@ import { nextTestSetup, isNextDev } from 'e2e-utils'
['/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