Unverified Commit 52b14004 authored by Jamiboy Mohammad's avatar Jamiboy Mohammad Committed by GitHub

test: read isNextDev/isNextDeploy/isNextStart from e2e-utils (#100419)

## Summary

Replaces 93 `global.isNextDev` / `isNextDeploy` / `isNextStart` reads in
tests with the typed constants that `e2e-utils` already exports. 92 of
these went through `(global as any)` and one, in `i18n-hybrid.test.ts`,
was uncast. The values are the same, and `nextTestSetup()` returns
getters for these exports.

The global is `true | undefined` and the export is a boolean. Every
replaced read is a boolean check (`if`, `!`, ternaries, defaulted
parameters), so test behaviour does not change.

Some tests destructure `isNextDev` from `nextTestSetup()` and also read
the global inside that same call. Those now use the import, to avoid a
temporal-dead-zone reference.

Two places keep using the global on purpose:
- `test/lib/e2e-utils/index.ts` still sets it.
- `getDistDir()` in `test/lib/next-test-utils.ts` still reads it. That
file is also used by tests that don't import `e2e-utils`, and importing
that module would run its side effects.

## Verification

- Ran `tsc --noEmit` for the root project. The only errors are in
untouched tests that import `next/dist` modules.
- eslint and prettier pass on all changed files.
- Checked every replaced read for non-boolean use. For example, values
passed into `runTests(isDev, isDeploy)` are only used as conditions.

<!-- NEXT_JS_LLM -->
parent 23a1f0cb
import { isReact18, nextTestSetup } from 'e2e-utils' import { isReact18, nextTestSetup, isNextDeploy } from 'e2e-utils'
import { import {
waitForRedbox, waitForRedbox,
waitForNoRedbox, waitForNoRedbox,
...@@ -9,7 +9,7 @@ import { ...@@ -9,7 +9,7 @@ import {
const isRspack = process.env.NEXT_RSPACK !== undefined const isRspack = process.env.NEXT_RSPACK !== undefined
describe('react-dom/server in React Server environment', () => { describe('react-dom/server in React Server environment', () => {
const dependencies = (global as any).isNextDeploy const dependencies = isNextDeploy
? // `link` is incompatible with the npm version used when this test is deployed ? // `link` is incompatible with the npm version used when this test is deployed
{ {
'internal-pkg': 'file:./internal-pkg', 'internal-pkg': 'file:./internal-pkg',
......
import { join } from 'path' import { join } from 'path'
import cheerio from 'cheerio' import cheerio from 'cheerio'
import { FileRef, nextTestSetup } from 'e2e-utils' import { FileRef, nextTestSetup, isNextDev } from 'e2e-utils'
import { waitForNoRedbox, renderViaHTTP, check } from 'next-test-utils' import { waitForNoRedbox, renderViaHTTP, check } from 'next-test-utils'
const customDocumentGipContent = `\ const customDocumentGipContent = `\
...@@ -207,7 +207,7 @@ describe('next/dynamic', () => { ...@@ -207,7 +207,7 @@ describe('next/dynamic', () => {
} }
}) })
if (!(global as any).isNextDev) { if (!isNextDev) {
it('should not include ssr:false imports to server trace', async () => { it('should not include ssr:false imports to server trace', async () => {
const trace = JSON.parse( const trace = JSON.parse(
await next.readFile('.next/server/pages/dynamic/no-ssr.js.nft.json') await next.readFile('.next/server/pages/dynamic/no-ssr.js.nft.json')
......
import path from 'path' import path from 'path'
import fs from 'fs-extra' import fs from 'fs-extra'
import { FileRef, nextTestSetup } from 'e2e-utils' import { FileRef, nextTestSetup, isNextDev } from 'e2e-utils'
import { check, retry } from 'next-test-utils' import { check, retry } from 'next-test-utils'
const pathnames = { const pathnames = {
...@@ -19,7 +19,7 @@ const table = [ ...@@ -19,7 +19,7 @@ const table = [
{ basePath: true, i18n: true, middleware: false }, { basePath: true, i18n: true, middleware: false },
{ basePath: false, i18n: false, middleware: false }, { basePath: false, i18n: false, middleware: false },
...((global as any).isNextDev ...(isNextDev
? [] ? []
: [ : [
// TODO: investigate this failure in development // TODO: investigate this failure in development
...@@ -50,7 +50,7 @@ describe('404-page-router', () => { ...@@ -50,7 +50,7 @@ describe('404-page-router', () => {
describe.each(table)( describe.each(table)(
'404-page-router with basePath of $basePath and i18n of $i18n and middleware $middleware', '404-page-router with basePath of $basePath and i18n of $i18n and middleware $middleware',
(options) => { (options) => {
const isDev = (global as any).isNextDev const isDev = isNextDev
beforeAll(async () => { beforeAll(async () => {
// Only add in the middleware if we're testing with middleware enabled. // Only add in the middleware if we're testing with middleware enabled.
......
import { nextTestSetup } from 'e2e-utils' import { nextTestSetup, isNextDev } from 'e2e-utils'
import { check } from 'next-test-utils' import { check } 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,7 +32,7 @@ describe('app-dir edge SSR', () => { ...@@ -32,7 +32,7 @@ describe('app-dir edge SSR', () => {
expect(appHtml).toContain('the /index route') expect(appHtml).toContain('the /index route')
}) })
if ((globalThis as any).isNextDev) { if (isNextDev) {
it('should resolve module without error in edge runtime', async () => { it('should resolve module without error in edge runtime', async () => {
const logs = [] const logs = []
next.on('stderr', (log) => { next.on('stderr', (log) => {
......
import { FileRef, nextTestSetup } from 'e2e-utils' import { FileRef, nextTestSetup, isNextStart } from 'e2e-utils'
import fs from 'fs-extra' import fs from 'fs-extra'
import os from 'os' import os from 'os'
import path from 'path' import path from 'path'
...@@ -9,7 +9,7 @@ import { ...@@ -9,7 +9,7 @@ import {
fetchViaHTTP, fetchViaHTTP,
} from 'next-test-utils' } from 'next-test-utils'
if (!(globalThis as any).isNextStart) { if (!isNextStart) {
it('should skip for non-next start', () => {}) it('should skip for non-next start', () => {})
} else { } else {
describe('output: standalone with ESM app dir', () => { describe('output: standalone with ESM app dir', () => {
......
import { nextTestSetup } from 'e2e-utils' import { nextTestSetup, isNextDev } from 'e2e-utils'
import { waitForNoRedbox, check, getDistDir, retry } from 'next-test-utils' import { waitForNoRedbox, check, getDistDir, retry } from 'next-test-utils'
async function resolveStreamResponse(response: any, onData?: any) { async function resolveStreamResponse(response: any, onData?: any) {
...@@ -31,7 +31,7 @@ describe('app dir - external dependency', () => { ...@@ -31,7 +31,7 @@ describe('app dir - external dependency', () => {
}, },
}, },
installCommand: 'pnpm i', installCommand: 'pnpm i',
startCommand: (global as any).isNextDev ? 'pnpm dev' : 'pnpm start', startCommand: isNextDev ? 'pnpm dev' : 'pnpm start',
buildCommand: 'pnpm build', buildCommand: 'pnpm build',
}) })
......
...@@ -560,7 +560,7 @@ describe('app-dir static/dynamic handling', () => { ...@@ -560,7 +560,7 @@ describe('app-dir static/dynamic handling', () => {
const newRes = await next.fetch('/variable-revalidate/revalidate-360') const newRes = await next.fetch('/variable-revalidate/revalidate-360')
const cacheHeader = newRes.headers.get('x-nextjs-cache') const cacheHeader = newRes.headers.get('x-nextjs-cache')
if ((global as any).isNextStart && cacheHeader) { if (isNextStart && cacheHeader) {
expect(cacheHeader).toBe('MISS') expect(cacheHeader).toBe('MISS')
} }
const newHtml = await newRes.text() const newHtml = await newRes.text()
...@@ -596,7 +596,7 @@ describe('app-dir static/dynamic handling', () => { ...@@ -596,7 +596,7 @@ describe('app-dir static/dynamic handling', () => {
// On-Demand Revalidate has not effect in dev since app routes // On-Demand Revalidate has not effect in dev since app routes
// aren't considered static until prerendering // aren't considered static until prerendering
if (!(global as any).isNextDev && !process.env.CUSTOM_CACHE_HANDLER) { if (!isNextDev && !process.env.CUSTOM_CACHE_HANDLER) {
it('should not revalidate / when revalidate is not used', async () => { it('should not revalidate / when revalidate is not used', async () => {
let prevData let prevData
...@@ -670,7 +670,7 @@ describe('app-dir static/dynamic handling', () => { ...@@ -670,7 +670,7 @@ describe('app-dir static/dynamic handling', () => {
} }
// On-Demand Revalidate has not effect in dev // On-Demand Revalidate has not effect in dev
if (!(global as any).isNextDev && !process.env.CUSTOM_CACHE_HANDLER) { if (!isNextDev && !process.env.CUSTOM_CACHE_HANDLER) {
it('should revalidate all fetches during on-demand revalidate', async () => { it('should revalidate all fetches during on-demand revalidate', async () => {
const initRes = await next.fetch( const initRes = await next.fetch(
'/variable-revalidate/revalidate-360-isr' '/variable-revalidate/revalidate-360-isr'
...@@ -4515,7 +4515,7 @@ describe('app-dir static/dynamic handling', () => { ...@@ -4515,7 +4515,7 @@ describe('app-dir static/dynamic handling', () => {
const firstTime = $('#now').text() const firstTime = $('#now').text()
if (!(global as any).isNextDev) { if (!isNextDev) {
const res2 = await next.fetch('/force-static') const res2 = await next.fetch('/force-static')
expect(res2.status).toBe(200) expect(res2.status).toBe(200)
...@@ -4613,7 +4613,7 @@ describe('app-dir static/dynamic handling', () => { ...@@ -4613,7 +4613,7 @@ describe('app-dir static/dynamic handling', () => {
const firstTime = $('#now').text() const firstTime = $('#now').text()
if (!(global as any).isNextDev) { if (!isNextDev) {
const res2 = await next.fetch('/force-static/first') const res2 = await next.fetch('/force-static/first')
expect(res2.status).toBe(200) expect(res2.status).toBe(200)
...@@ -4635,7 +4635,7 @@ describe('app-dir static/dynamic handling', () => { ...@@ -4635,7 +4635,7 @@ describe('app-dir static/dynamic handling', () => {
const firstTime = $('#now').text() const firstTime = $('#now').text()
if (!(global as any).isNextDev) { if (!isNextDev) {
const res2 = await next.fetch('/force-static/random') const res2 = await next.fetch('/force-static/random')
expect(res2.status).toBe(200) expect(res2.status).toBe(200)
...@@ -4945,7 +4945,7 @@ describe('app-dir static/dynamic handling', () => { ...@@ -4945,7 +4945,7 @@ describe('app-dir static/dynamic handling', () => {
}) })
// TODO-APP: re-enable after investigating rewrite params // TODO-APP: re-enable after investigating rewrite params
if (!(global as any).isNextDeploy) { if (!isNextDeploy) {
it('should have values from canonical url on rewrite', async () => { it('should have values from canonical url on rewrite', async () => {
const browser = await next.browser( const browser = await next.browser(
'/rewritten-use-search-params?first=a&second=b&third=c' '/rewritten-use-search-params?first=a&second=b&third=c'
......
import 'e2e-utils' import { isNextStart } from 'e2e-utils'
process.env.NEXT_EXPERIMENTAL_COMPILE = '1' process.env.NEXT_EXPERIMENTAL_COMPILE = '1'
if ((global as any).isNextStart) { if (isNextStart) {
require('./index.test') require('./index.test')
} else { } else {
it('should skip', () => {}) it('should skip', () => {})
......
import { nextTestSetup } from 'e2e-utils' import { nextTestSetup, isNextStart } from 'e2e-utils'
import fs from 'fs-extra' import fs from 'fs-extra'
import os from 'os' import os from 'os'
import path from 'path' import path from 'path'
...@@ -9,7 +9,7 @@ import { ...@@ -9,7 +9,7 @@ import {
fetchViaHTTP, fetchViaHTTP,
} from 'next-test-utils' } from 'next-test-utils'
if (!(globalThis as any).isNextStart) { if (!isNextStart) {
it('should skip for non-next start', () => {}) it('should skip for non-next start', () => {})
} else { } else {
describe('output: standalone with getStaticProps', () => { describe('output: standalone with getStaticProps', () => {
......
import { nextTestSetup } from 'e2e-utils' import { nextTestSetup, isNextStart } from 'e2e-utils'
import fs from 'fs-extra' import fs from 'fs-extra'
import os from 'os' import os from 'os'
import path from 'path' import path from 'path'
...@@ -9,7 +9,7 @@ import { ...@@ -9,7 +9,7 @@ import {
fetchViaHTTP, fetchViaHTTP,
} from 'next-test-utils' } from 'next-test-utils'
if (!(globalThis as any).isNextStart) { if (!isNextStart) {
it('should skip for non-next start', () => {}) it('should skip for non-next start', () => {})
} else { } else {
describe('output: standalone with app dir', () => { describe('output: standalone with app dir', () => {
......
import path from 'path' import path from 'path'
import { FileRef, nextTestSetup } from 'e2e-utils' import { FileRef, nextTestSetup, isNextDev, isNextDeploy } from 'e2e-utils'
import { check, retry } from 'next-test-utils' import { check, retry } from 'next-test-utils'
import stripAnsi from 'strip-ansi' import stripAnsi from 'strip-ansi'
...@@ -7,9 +7,9 @@ import stripAnsi from 'strip-ansi' ...@@ -7,9 +7,9 @@ import stripAnsi from 'strip-ansi'
;(process.env.IS_TURBOPACK_TEST ? describe.skip : describe)( ;(process.env.IS_TURBOPACK_TEST ? describe.skip : describe)(
'app-dir create root layout', 'app-dir create root layout',
() => { () => {
const isDev = (global as any).isNextDev const isDev = isNextDev
if ((global as any).isNextDeploy) { if (isNextDeploy) {
it('should skip next deploy for now', () => {}) it('should skip next deploy for now', () => {})
return return
} }
......
// @ts-check // @ts-check
// @ts-ignore // @ts-ignore
import { nextTestSetup } from 'e2e-utils' import { nextTestSetup, isNextDeploy } from 'e2e-utils'
import cheerio from 'cheerio' import cheerio from 'cheerio'
import { retry } from 'next-test-utils' import { retry } from 'next-test-utils'
...@@ -9,7 +9,7 @@ const { i18n } = require('./next.config') ...@@ -9,7 +9,7 @@ const { i18n } = require('./next.config')
const urls = [ const urls = [
// Include the app page without a locale. // Include the app page without a locale.
...(global.isNextDeploy ...(isNextDeploy
? [] ? []
: [ : [
// TODO: enable for deploy mode when behavior is corrected // TODO: enable for deploy mode when behavior is corrected
......
...@@ -2,6 +2,7 @@ import { ...@@ -2,6 +2,7 @@ import {
nextTestSetup, nextTestSetup,
FileRef, FileRef,
patchFileWithDeployEnvAssignments, patchFileWithDeployEnvAssignments,
isNextDev,
} from 'e2e-utils' } from 'e2e-utils'
import * as path from 'path' import * as path from 'path'
...@@ -34,7 +35,7 @@ testFn('import-meta-glob-monorepo', () => { ...@@ -34,7 +35,7 @@ testFn('import-meta-glob-monorepo', () => {
}, },
packageJson: require('./package.json'), packageJson: require('./package.json'),
buildCommand: 'pnpm build', buildCommand: 'pnpm build',
startCommand: (global as any).isNextDev ? 'pnpm dev' : 'pnpm start', startCommand: isNextDev ? 'pnpm dev' : 'pnpm start',
installCommand: 'pnpm i', installCommand: 'pnpm i',
}) })
......
import { FileRef, nextTestSetup } from 'e2e-utils' import { FileRef, nextTestSetup, isNextDeploy } from 'e2e-utils'
describe('navigation between pages and app dir', () => { describe('navigation between pages and app dir', () => {
const { next } = nextTestSetup({ const { next } = nextTestSetup({
...@@ -35,7 +35,7 @@ describe('navigation between pages and app dir', () => { ...@@ -35,7 +35,7 @@ describe('navigation between pages and app dir', () => {
}) })
// TODO: re-enable after 404 transition bug is addressed // TODO: re-enable after 404 transition bug is addressed
if (!(global as any).isNextDeploy) { if (!isNextDeploy) {
it('It should be able to navigate pages -> app and go back an forward', async () => { it('It should be able to navigate pages -> app and go back an forward', async () => {
const browser = await next.browser('/pages') const browser = await next.browser('/pages')
// Increased timeout: in dev mode, cross-router navigation triggers on-demand // Increased timeout: in dev mode, cross-router navigation triggers on-demand
......
...@@ -3,6 +3,7 @@ import { ...@@ -3,6 +3,7 @@ import {
FileRef, FileRef,
patchFileWithDeployEnvAssignments, patchFileWithDeployEnvAssignments,
isNextDeploy, isNextDeploy,
isNextDev,
} from 'e2e-utils' } from 'e2e-utils'
import { import {
waitForRedbox, waitForRedbox,
...@@ -15,7 +16,7 @@ import { realpathSync } from 'fs' ...@@ -15,7 +16,7 @@ import { realpathSync } from 'fs'
import { pathToFileURL } from 'url' import { pathToFileURL } from 'url'
describe('non-root-project-monorepo', () => { describe('non-root-project-monorepo', () => {
const { next, isTurbopack, isNextDev, isRspack } = nextTestSetup({ const { next, isTurbopack, isRspack } = nextTestSetup({
files: { files: {
apps: new FileRef(path.resolve(__dirname, 'apps')), apps: new FileRef(path.resolve(__dirname, 'apps')),
packages: new FileRef(path.resolve(__dirname, 'packages')), packages: new FileRef(path.resolve(__dirname, 'packages')),
...@@ -35,7 +36,7 @@ describe('non-root-project-monorepo', () => { ...@@ -35,7 +36,7 @@ describe('non-root-project-monorepo', () => {
}, },
packageJson: require('./package.json'), packageJson: require('./package.json'),
buildCommand: 'pnpm build', buildCommand: 'pnpm build',
startCommand: (global as any).isNextDev ? 'pnpm dev' : 'pnpm start', startCommand: isNextDev ? 'pnpm dev' : 'pnpm start',
installCommand: 'pnpm i', installCommand: 'pnpm i',
}) })
......
import { nextTestSetup } from 'e2e-utils' import { nextTestSetup, isNextDev, isNextDeploy } from 'e2e-utils'
import { findPort } from 'next-test-utils' import { findPort } from 'next-test-utils'
import { createTestDataServer } from 'test-data-service/writer' import { createTestDataServer } from 'test-data-service/writer'
import { createTestLog } from 'test-log' import { createTestLog } from 'test-log'
describe('avoid-popstate-flash', () => { describe('avoid-popstate-flash', () => {
// Deploy mode exclusion: This suite depends on a test-data service running on a local port. // Deploy mode exclusion: This suite depends on a test-data service running on a local port.
if ((global as any).isNextDev || (global as any).isNextDeploy) { if (isNextDev || isNextDeploy) {
// this is skipped in dev because PPR is not enabled in dev // this is skipped in dev because PPR is not enabled in dev
// and in deploy we can't rely on this test data service existing // and in deploy we can't rely on this test data service existing
test('should skip dev & deploy', () => {}) test('should skip dev & deploy', () => {})
......
import { nextTestSetup } from 'e2e-utils' import { nextTestSetup, isNextDev } from 'e2e-utils'
// TODO(NAR-423): Migrate to Cache Components. // TODO(NAR-423): Migrate to Cache Components.
describe.skip('search-params', () => { describe.skip('search-params', () => {
if ((global as any).isNextDev) { if (isNextDev) {
test('ppr is disabled in dev', () => {}) test('ppr is disabled in dev', () => {})
return return
} }
......
import { nextTestSetup } from 'e2e-utils' import { nextTestSetup, isNextDev, isNextDeploy } from 'e2e-utils'
import { findPort } from 'next-test-utils' import { findPort } from 'next-test-utils'
import { createTestDataServer } from 'test-data-service/writer' import { createTestDataServer } from 'test-data-service/writer'
import { createTestLog } from 'test-log' import { createTestLog } from 'test-log'
describe('stale-prefetch-entry', () => { describe('stale-prefetch-entry', () => {
// Deploy mode exclusion: This suite depends on a test-data service running on a local port. // Deploy mode exclusion: This suite depends on a test-data service running on a local port.
if ((global as any).isNextDev || (global as any).isNextDeploy) { if (isNextDev || isNextDeploy) {
// this is skipped in dev because PPR is not enabled in dev // this is skipped in dev because PPR is not enabled in dev
// and in deploy we can't rely on this test data service existing // and in deploy we can't rely on this test data service existing
test('should skip dev & deploy', () => {}) test('should skip dev & deploy', () => {})
......
import { nextTestSetup } from 'e2e-utils' import { nextTestSetup, isNextDeploy } from 'e2e-utils'
describe('redirects and rewrites', () => { describe('redirects and rewrites', () => {
const { next } = nextTestSetup({ const { next } = nextTestSetup({
...@@ -9,7 +9,7 @@ describe('redirects and rewrites', () => { ...@@ -9,7 +9,7 @@ describe('redirects and rewrites', () => {
}) })
// TODO: investigate test failures on deploy // TODO: investigate test failures on deploy
if ((global as any).isNextDeploy) { if (isNextDeploy) {
it('should skip for deploy', () => {}) it('should skip for deploy', () => {})
return return
} }
......
import { nextTestSetup } from 'e2e-utils' import { nextTestSetup, isNextDeploy } from 'e2e-utils'
describe('self-importing-package-monorepo', () => { describe('self-importing-package-monorepo', () => {
const dependencies = (global as any).isNextDeploy const dependencies = isNextDeploy
? // `link` is incompatible with the npm version used when this test is deployed ? // `link` is incompatible with the npm version used when this test is deployed
{ {
'internal-pkg': 'file:./internal-pkg', 'internal-pkg': 'file:./internal-pkg',
......
import { FileRef, nextTestSetup } from 'e2e-utils' import { FileRef, nextTestSetup, isNextDeploy } from 'e2e-utils'
import { fetchViaHTTP } from 'next-test-utils' import { fetchViaHTTP } from 'next-test-utils'
import path from 'path' import path from 'path'
import fs from 'fs-extra' import fs from 'fs-extra'
...@@ -88,7 +88,7 @@ describe('middleware can use wasm files', () => { ...@@ -88,7 +88,7 @@ describe('middleware can use wasm files', () => {
}) })
}) })
if (!(global as any).isNextDeploy) { if (!isNextDeploy) {
it('lists the necessary wasm bindings in the manifest', async () => { it('lists the necessary wasm bindings in the manifest', async () => {
const manifestPath = path.join( const manifestPath = path.join(
next.testDir, next.testDir,
......
import { nextTestSetup } from 'e2e-utils' import { nextTestSetup, isNextDev } from 'e2e-utils'
import { fetchViaHTTP } from 'next-test-utils' import { fetchViaHTTP } from 'next-test-utils'
// Deploy mode exclusion: This suite manually creates a package in the local `node_modules` directory. // Deploy mode exclusion: This suite manually creates a package in the local `node_modules` directory.
...@@ -40,7 +40,7 @@ describe('Edge compiler module exports preference', () => { ...@@ -40,7 +40,7 @@ describe('Edge compiler module exports preference', () => {
}, },
}, },
installCommand: 'pnpm i', installCommand: 'pnpm i',
startCommand: (global as any).isNextDev ? 'pnpm dev' : 'pnpm start', startCommand: isNextDev ? 'pnpm dev' : 'pnpm start',
buildCommand: 'pnpm run build', buildCommand: 'pnpm run build',
dependencies: {}, dependencies: {},
}) })
......
import { nextTestSetup } from 'e2e-utils' import { nextTestSetup, isNextStart } from 'e2e-utils'
import { fetchViaHTTP, normalizeRegEx } from 'next-test-utils' import { fetchViaHTTP, normalizeRegEx } from 'next-test-utils'
import cheerio from 'cheerio' import cheerio from 'cheerio'
import { join } from 'path' import { join } from 'path'
...@@ -10,7 +10,7 @@ describe('edge-render-getserversideprops', () => { ...@@ -10,7 +10,7 @@ describe('edge-render-getserversideprops', () => {
files: join(__dirname, 'app'), files: join(__dirname, 'app'),
}) })
if ((global as any).isNextStart) { if (isNextStart) {
// Turbopack doesn't have entry chunks for edge routes like Webpack does, so there is no fixed // Turbopack doesn't have entry chunks for edge routes like Webpack does, so there is no fixed
// known path where the nft file would be written to. // known path where the nft file would be written to.
;(process.env.IS_TURBOPACK_TEST ? it.skip : it)( ;(process.env.IS_TURBOPACK_TEST ? it.skip : it)(
...@@ -150,7 +150,7 @@ describe('edge-render-getserversideprops', () => { ...@@ -150,7 +150,7 @@ describe('edge-render-getserversideprops', () => {
expect(props.params).toEqual({ id: '321' }) expect(props.params).toEqual({ id: '321' })
}) })
if ((global as any).isNextStart) { if (isNextStart) {
it('should have data routes in routes-manifest', async () => { it('should have data routes in routes-manifest', async () => {
const manifest = JSON.parse( const manifest = JSON.parse(
await next.readFile('.next/routes-manifest.json') await next.readFile('.next/routes-manifest.json')
......
import { nextTestSetup } from 'e2e-utils' import { nextTestSetup, isNextDev } from 'e2e-utils'
describe('edge-runtime uses edge-light import specifier for packages', () => { describe('edge-runtime uses edge-light import specifier for packages', () => {
const { next } = nextTestSetup({ const { next } = nextTestSetup({
...@@ -11,7 +11,7 @@ describe('edge-runtime uses edge-light import specifier for packages', () => { ...@@ -11,7 +11,7 @@ describe('edge-runtime uses edge-light import specifier for packages', () => {
}, },
}, },
installCommand: 'pnpm i', installCommand: 'pnpm i',
startCommand: (global as any).isNextDev ? 'pnpm dev' : 'pnpm start', startCommand: isNextDev ? 'pnpm dev' : 'pnpm start',
buildCommand: 'pnpm build', buildCommand: 'pnpm build',
}) })
......
/* eslint-env jest */ /* eslint-env jest */
import cheerio from 'cheerio' import cheerio from 'cheerio'
import { FileRef, nextTestSetup } from 'e2e-utils' import { FileRef, nextTestSetup, isNextDev, isNextDeploy } from 'e2e-utils'
import escapeRegex from 'escape-string-regexp' import escapeRegex from 'escape-string-regexp'
import { import {
check, check,
...@@ -898,5 +898,5 @@ describe('getServerSideProps', () => { ...@@ -898,5 +898,5 @@ describe('getServerSideProps', () => {
buildId = next.buildId buildId = next.buildId
}) })
runTests(next, (global as any).isNextDev, (global as any).isNextDeploy) runTests(next, isNextDev, isNextDeploy)
}) })
import { nextTestSetup } from 'e2e-utils' import { nextTestSetup, isNextDeploy } from 'e2e-utils'
import { fetchViaHTTP } from 'next-test-utils' import { fetchViaHTTP } from 'next-test-utils'
describe('i18n API support', () => { describe('i18n API support', () => {
...@@ -49,7 +49,7 @@ describe('i18n API support', () => { ...@@ -49,7 +49,7 @@ describe('i18n API support', () => {
}) })
// TODO: re-enable after this is fixed to match on Vercel // TODO: re-enable after this is fixed to match on Vercel
if (!(global as any).isNextDeploy) { if (!isNextDeploy) {
it('should fallback rewrite non-matching API request', async () => { it('should fallback rewrite non-matching API request', async () => {
const paths = [ const paths = [
'/fr/api/hello', '/fr/api/hello',
......
import { nextTestSetup } from 'e2e-utils' import { nextTestSetup, isNextDeploy } from 'e2e-utils'
import { fetchViaHTTP, renderViaHTTP } from 'next-test-utils' import { fetchViaHTTP, renderViaHTTP } from 'next-test-utils'
import path from 'path' import path from 'path'
import fs from 'fs-extra' import fs from 'fs-extra'
...@@ -33,7 +33,7 @@ describe('i18n-ignore-rewrite-source-locale with basepath', () => { ...@@ -33,7 +33,7 @@ describe('i18n-ignore-rewrite-source-locale with basepath', () => {
) )
// build artifacts aren't available on deploy // build artifacts aren't available on deploy
if (!(global as any).isNextDeploy) { if (!isNextDeploy) {
// chunks are not written to disk with TURBOPACK // chunks are not written to disk with TURBOPACK
;(process.env.IS_TURBOPACK_TEST ? it.skip.each : it.each)(locales)( ;(process.env.IS_TURBOPACK_TEST ? it.skip.each : it.each)(locales)(
'get _next/static/ files by skipping locale in rewrite, locale: %s', 'get _next/static/ files by skipping locale in rewrite, locale: %s',
......
import { nextTestSetup } from 'e2e-utils' import { nextTestSetup, isNextDeploy } from 'e2e-utils'
import { fetchViaHTTP, renderViaHTTP } from 'next-test-utils' import { fetchViaHTTP, renderViaHTTP } from 'next-test-utils'
import path from 'path' import path from 'path'
import fs from 'fs-extra' import fs from 'fs-extra'
...@@ -61,7 +61,7 @@ describe('i18n-ignore-rewrite-source-locale', () => { ...@@ -61,7 +61,7 @@ describe('i18n-ignore-rewrite-source-locale', () => {
) )
// build artifacts aren't available on deploy // build artifacts aren't available on deploy
if (!(global as any).isNextDeploy) { if (!isNextDeploy) {
// chunks are not written to disk with TURBOPACK // chunks are not written to disk with TURBOPACK
;(process.env.IS_TURBOPACK_TEST ? it.skip.each : it.each)(locales)( ;(process.env.IS_TURBOPACK_TEST ? it.skip.each : it.each)(locales)(
'get _next/static/ files by skipping locale in rewrite, locale: %s', 'get _next/static/ files by skipping locale in rewrite, locale: %s',
......
import { nextTestSetup } from 'e2e-utils' import { nextTestSetup, isNextDeploy } from 'e2e-utils'
import { fetchViaHTTP } from 'next-test-utils' import { fetchViaHTTP } from 'next-test-utils'
describe('Middleware fetches with body', () => { describe('Middleware fetches with body', () => {
...@@ -60,7 +60,7 @@ describe('Middleware fetches with body', () => { ...@@ -60,7 +60,7 @@ describe('Middleware fetches with body', () => {
try { try {
expect(res.status).toBe(413) expect(res.status).toBe(413)
if (!(global as any).isNextDeploy) { if (!isNextDeploy) {
expect(res.statusText).toBe('Body exceeded 1mb limit') expect(res.statusText).toBe('Body exceeded 1mb limit')
} }
} catch (err) { } catch (err) {
...@@ -136,7 +136,7 @@ describe('Middleware fetches with body', () => { ...@@ -136,7 +136,7 @@ describe('Middleware fetches with body', () => {
try { try {
expect(res.status).toBe(413) expect(res.status).toBe(413)
if (!(global as any).isNextDeploy) { if (!isNextDeploy) {
expect(res.statusText).toBe('Body exceeded 5kb limit') expect(res.statusText).toBe('Body exceeded 5kb limit')
} }
} catch (err) { } catch (err) {
...@@ -189,7 +189,7 @@ describe('Middleware fetches with body', () => { ...@@ -189,7 +189,7 @@ describe('Middleware fetches with body', () => {
try { try {
expect(res.status).toBe(413) expect(res.status).toBe(413)
if (!(global as any).isNextDeploy) { if (!isNextDeploy) {
expect(res.statusText).toBe('Body exceeded 5mb limit') expect(res.statusText).toBe('Body exceeded 5mb limit')
} }
} catch (err) { } catch (err) {
...@@ -201,7 +201,7 @@ describe('Middleware fetches with body', () => { ...@@ -201,7 +201,7 @@ describe('Middleware fetches with body', () => {
} }
}) })
if (!(global as any).isNextDeploy) { if (!isNextDeploy) {
it('should be able to send and return body size equal to 5mb', async () => { it('should be able to send and return body size equal to 5mb', async () => {
const bodySize = 5 * 1024 * 1024 const bodySize = 5 * 1024 * 1024
const body = 'FGHI1J2K3L4M5N6O7P8Q9R0SaTbUcVdW'.repeat(bodySize / 32) const body = 'FGHI1J2K3L4M5N6O7P8Q9R0SaTbUcVdW'.repeat(bodySize / 32)
...@@ -291,7 +291,7 @@ describe('Middleware fetches with body', () => { ...@@ -291,7 +291,7 @@ describe('Middleware fetches with body', () => {
try { try {
expect(res.status).toBe(413) expect(res.status).toBe(413)
if (!(global as any).isNextDeploy) { if (!isNextDeploy) {
expect(res.statusText).toBe('Body exceeded 5mb limit') expect(res.statusText).toBe('Body exceeded 5mb limit')
} }
} catch (err) { } catch (err) {
......
...@@ -2,7 +2,13 @@ ...@@ -2,7 +2,13 @@
import fs from 'fs-extra' import fs from 'fs-extra'
import { join } from 'path' import { join } from 'path'
import { FileRef, isNextStart, nextTestSetup } from 'e2e-utils' import {
FileRef,
isNextStart,
nextTestSetup,
isNextDev,
isNextDeploy,
} from 'e2e-utils'
import { check, fetchViaHTTP, waitFor } from 'next-test-utils' import { check, fetchViaHTTP, waitFor } from 'next-test-utils'
const urlsError = 'Please use only absolute URLs' const urlsError = 'Please use only absolute URLs'
...@@ -76,7 +82,7 @@ describe('Middleware Runtime', () => { ...@@ -76,7 +82,7 @@ describe('Middleware Runtime', () => {
start: 'next start', start: 'next start',
}, },
}, },
startCommand: (global as any).isNextDev ? 'pnpm dev' : 'pnpm start', startCommand: isNextDev ? 'pnpm dev' : 'pnpm start',
buildCommand: 'pnpm build', buildCommand: 'pnpm build',
env: { env: {
ANOTHER_MIDDLEWARE_TEST: 'asdf2', ANOTHER_MIDDLEWARE_TEST: 'asdf2',
...@@ -174,7 +180,7 @@ describe('Middleware Runtime', () => { ...@@ -174,7 +180,7 @@ describe('Middleware Runtime', () => {
expect(await res.text()).toContain('Example Domain') expect(await res.text()).toContain('Example Domain')
}) })
if ((global as any).isNextDev) { if (isNextDev) {
it('refreshes the page when middleware changes ', async () => { it('refreshes the page when middleware changes ', async () => {
const browser = await next.browser(`/about`) const browser = await next.browser(`/about`)
await browser.eval('window.didrefresh = "hello"') await browser.eval('window.didrefresh = "hello"')
...@@ -209,7 +215,7 @@ describe('Middleware Runtime', () => { ...@@ -209,7 +215,7 @@ describe('Middleware Runtime', () => {
}) })
} }
if ((global as any).isNextStart && !isNodeMiddleware) { if (isNextStart && !isNodeMiddleware) {
it('should have valid middleware field in manifest', async () => { it('should have valid middleware field in manifest', async () => {
const manifest = await fs.readJSON( const manifest = await fs.readJSON(
join(next.testDir, '.next/server/middleware-manifest.json') join(next.testDir, '.next/server/middleware-manifest.json')
...@@ -550,12 +556,12 @@ describe('Middleware Runtime', () => { ...@@ -550,12 +556,12 @@ describe('Middleware Runtime', () => {
const res = await fetchViaHTTP(next.url, `/%2`) const res = await fetchViaHTTP(next.url, `/%2`)
expect(res.status).toBe(400) expect(res.status).toBe(400)
if ((global as any).isNextStart) { if (isNextStart) {
expect(await res.text()).toContain('Bad Request') expect(await res.text()).toContain('Bad Request')
} }
}) })
if (!(global as any).isNextDeploy) { if (!isNextDeploy) {
// user agent differs on Vercel // user agent differs on Vercel
it('should set fetch user agent correctly', async () => { it('should set fetch user agent correctly', async () => {
const res = await fetchViaHTTP(next.url, `/fetch-user-agent-default`) const res = await fetchViaHTTP(next.url, `/fetch-user-agent-default`)
...@@ -579,7 +585,7 @@ describe('Middleware Runtime', () => { ...@@ -579,7 +585,7 @@ describe('Middleware Runtime', () => {
ANOTHER_MIDDLEWARE_TEST: 'asdf2', ANOTHER_MIDDLEWARE_TEST: 'asdf2',
STRING_ENV_VAR: 'asdf3', STRING_ENV_VAR: 'asdf3',
MIDDLEWARE_TEST: 'asdf', MIDDLEWARE_TEST: 'asdf',
...((global as any).isNextDeploy ...(isNextDeploy
? {} ? {}
: { : {
NEXT_RUNTIME: isNodeMiddleware ? 'nodejs' : 'edge', NEXT_RUNTIME: isNodeMiddleware ? 'nodejs' : 'edge',
...@@ -599,7 +605,7 @@ describe('Middleware Runtime', () => { ...@@ -599,7 +605,7 @@ describe('Middleware Runtime', () => {
expect('error' in readMiddlewareJSON(res)).toBe(false) expect('error' in readMiddlewareJSON(res)).toBe(false)
}) })
if (!(global as any).isNextDeploy) { if (!isNextDeploy) {
it(`should accept a URL instance for fetch`, async () => { it(`should accept a URL instance for fetch`, async () => {
const response = await fetchViaHTTP(next.url, '/fetch-url') const response = await fetchViaHTTP(next.url, '/fetch-url')
// TODO: why is an error expected here if it should work? // TODO: why is an error expected here if it should work?
...@@ -706,7 +712,7 @@ describe('Middleware Runtime', () => { ...@@ -706,7 +712,7 @@ describe('Middleware Runtime', () => {
expect(readMiddlewareError(response)).toContain(urlsError) expect(readMiddlewareError(response)).toContain(urlsError)
}) })
if (!(global as any).isNextDeploy) { if (!isNextDeploy) {
// these errors differ on Vercel // these errors differ on Vercel
it('should throw when using Request with a relative URL', async () => { it('should throw when using Request with a relative URL', async () => {
const response = await fetchViaHTTP(next.url, `/url/relative-request`) const response = await fetchViaHTTP(next.url, `/url/relative-request`)
......
import { FileRef, nextTestSetup } from 'e2e-utils' import { FileRef, nextTestSetup, isNextDev, isNextStart } from 'e2e-utils'
import { fetchViaHTTP, retry } from 'next-test-utils' import { fetchViaHTTP, retry } from 'next-test-utils'
import { join } from 'path' import { join } from 'path'
...@@ -121,7 +121,7 @@ describe('Middleware can set the matcher in its config', () => { ...@@ -121,7 +121,7 @@ describe('Middleware can set the matcher in its config', () => {
await retry(async () => { await retry(async () => {
const matchers = await browser.eval( const matchers = await browser.eval(
(global as any).isNextDev isNextDev
? 'window.__DEV_MIDDLEWARE_MATCHERS' ? 'window.__DEV_MIDDLEWARE_MATCHERS'
: 'window.__MIDDLEWARE_MATCHERS' : 'window.__MIDDLEWARE_MATCHERS'
) )
...@@ -133,7 +133,7 @@ describe('Middleware can set the matcher in its config', () => { ...@@ -133,7 +133,7 @@ describe('Middleware can set the matcher in its config', () => {
}) })
}) })
if ((global as any).isNextStart) { if (isNextStart) {
it('produces the expected middleware manifest', async () => { it('produces the expected middleware manifest', async () => {
const manifest = JSON.parse( const manifest = JSON.parse(
await next.readFile('.next/server/middleware-manifest.json') await next.readFile('.next/server/middleware-manifest.json')
...@@ -363,7 +363,7 @@ describe.each([ ...@@ -363,7 +363,7 @@ describe.each([
dependencies: {}, dependencies: {},
}) })
if ((global as any).isNextStart) { if (isNextStart) {
it('produces the expected middleware manifest', async () => { it('produces the expected middleware manifest', async () => {
const manifest = JSON.parse( const manifest = JSON.parse(
await next.readFile('.next/server/middleware-manifest.json') await next.readFile('.next/server/middleware-manifest.json')
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
import { join } from 'path' import { join } from 'path'
import { fetchViaHTTP } from 'next-test-utils' import { fetchViaHTTP } from 'next-test-utils'
import { FileRef, nextTestSetup } from 'e2e-utils' import { FileRef, nextTestSetup, isNextDeploy } from 'e2e-utils'
describe('Middleware Responses', () => { describe('Middleware Responses', () => {
const { next } = nextTestSetup({ const { next } = nextTestSetup({
...@@ -27,7 +27,7 @@ describe('Middleware Responses', () => { ...@@ -27,7 +27,7 @@ describe('Middleware Responses', () => {
const res = await fetchViaHTTP(next.url, `${locale}/stream-a-response`) const res = await fetchViaHTTP(next.url, `${locale}/stream-a-response`)
expect(res.status).toBe(200) expect(res.status).toBe(200)
if (!(global as any).isNextDeploy) { if (!isNextDeploy) {
expect(next.cliOutput).not.toContain( expect(next.cliOutput).not.toContain(
`A middleware can not alter response's body. Learn more: https://nextjs.org/docs/messages/returning-response-body-in-middleware` `A middleware can not alter response's body. Learn more: https://nextjs.org/docs/messages/returning-response-body-in-middleware`
) )
...@@ -38,7 +38,7 @@ describe('Middleware Responses', () => { ...@@ -38,7 +38,7 @@ describe('Middleware Responses', () => {
const res = await fetchViaHTTP(next.url, `${locale}/send-response`) const res = await fetchViaHTTP(next.url, `${locale}/send-response`)
expect(res.status).toBe(200) expect(res.status).toBe(200)
if (!(global as any).isNextDeploy) { if (!isNextDeploy) {
expect(next.cliOutput).not.toContain( expect(next.cliOutput).not.toContain(
`A middleware can not alter response's body. Learn more: https://nextjs.org/docs/messages/returning-response-body-in-middleware` `A middleware can not alter response's body. Learn more: https://nextjs.org/docs/messages/returning-response-body-in-middleware`
) )
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
import { join } from 'path' import { join } from 'path'
import cheerio from 'cheerio' import cheerio from 'cheerio'
import { check, fetchViaHTTP, retry } from 'next-test-utils' import { check, fetchViaHTTP, retry } from 'next-test-utils'
import { FileRef, nextTestSetup } from 'e2e-utils' import { FileRef, nextTestSetup, isNextDev } from 'e2e-utils'
import escapeStringRegexp from 'escape-string-regexp' import escapeStringRegexp from 'escape-string-regexp'
// TODO(deploy-test-completion): Re-enable this suite in deploy mode. // TODO(deploy-test-completion): Re-enable this suite in deploy mode.
...@@ -32,7 +32,7 @@ describe('Middleware Rewrite', () => { ...@@ -32,7 +32,7 @@ describe('Middleware Rewrite', () => {
}, },
}) })
if (!(global as any).isNextDev) { if (!isNextDev) {
browser.elementByCss('#to-article-rewrite').moveTo() browser.elementByCss('#to-article-rewrite').moveTo()
await retry(async () => { await retry(async () => {
...@@ -404,7 +404,7 @@ describe('Middleware Rewrite', () => { ...@@ -404,7 +404,7 @@ describe('Middleware Rewrite', () => {
expect(await element.text()).toEqual('About Bypassed Page') expect(await element.text()).toEqual('About Bypassed Page')
}) })
if (!(global as any).isNextDev) { if (!isNextDev) {
it('should opt out of prefetch caching for dynamic routes', async () => { it('should opt out of prefetch caching for dynamic routes', async () => {
const browser = await next.browser('/') const browser = await next.browser('/')
await browser.eval('window.__SAME_PAGE = true') await browser.eval('window.__SAME_PAGE = true')
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
import fs from 'fs-extra' import fs from 'fs-extra'
import { join } from 'path' import { join } from 'path'
import { FileRef, nextTestSetup } from 'e2e-utils' import { FileRef, nextTestSetup, isNextDev, isNextStart } from 'e2e-utils'
import { check, fetchViaHTTP, waitFor } from 'next-test-utils' import { check, fetchViaHTTP, waitFor } from 'next-test-utils'
describe('Middleware Runtime trailing slash', () => { describe('Middleware Runtime trailing slash', () => {
...@@ -71,7 +71,7 @@ describe('Middleware Runtime trailing slash', () => { ...@@ -71,7 +71,7 @@ describe('Middleware Runtime trailing slash', () => {
}) })
}) })
if ((global as any).isNextDev) { if (isNextDev) {
it('refreshes the page when middleware changes ', async () => { it('refreshes the page when middleware changes ', async () => {
const browser = await next.browser(`/about/`) const browser = await next.browser(`/about/`)
await browser.eval('window.didrefresh = "hello"') await browser.eval('window.didrefresh = "hello"')
...@@ -95,7 +95,7 @@ describe('Middleware Runtime trailing slash', () => { ...@@ -95,7 +95,7 @@ describe('Middleware Runtime trailing slash', () => {
}) })
} }
if ((global as any).isNextStart) { if (isNextStart) {
it('should have valid middleware field in manifest', async () => { it('should have valid middleware field in manifest', async () => {
const manifest = await fs.readJSON( const manifest = await fs.readJSON(
join(next.testDir, '.next/server/middleware-manifest.json') join(next.testDir, '.next/server/middleware-manifest.json')
...@@ -379,7 +379,7 @@ describe('Middleware Runtime trailing slash', () => { ...@@ -379,7 +379,7 @@ describe('Middleware Runtime trailing slash', () => {
const res = await fetchViaHTTP(next.url, `/%2/`) const res = await fetchViaHTTP(next.url, `/%2/`)
expect(res.status).toBe(400) expect(res.status).toBe(400)
if ((global as any).isNextStart) { if (isNextStart) {
expect(await res.text()).toContain('Bad Request') expect(await res.text()).toContain('Bad Request')
} }
}) })
......
import { nextTestSetup } from 'e2e-utils' import { nextTestSetup, isNextDev } from 'e2e-utils'
import { check, waitFor } from 'next-test-utils' import { check, waitFor } from 'next-test-utils'
import path from 'path' import path from 'path'
...@@ -6,10 +6,10 @@ import path from 'path' ...@@ -6,10 +6,10 @@ import path from 'path'
// It likely mutates files in the isolated local fixture after setup. // It likely mutates files in the isolated local fixture after setup.
// @force-gate !deploy // @force-gate !deploy
describe('multi-zone', () => { describe('multi-zone', () => {
const { next, isNextDev } = nextTestSetup({ const { next } = nextTestSetup({
files: path.join(__dirname, 'app'), files: path.join(__dirname, 'app'),
buildCommand: 'pnpm build', buildCommand: 'pnpm build',
startCommand: (global as any).isNextDev ? 'pnpm dev' : 'pnpm start', startCommand: isNextDev ? 'pnpm dev' : 'pnpm start',
serverReadyPattern: /Next mode: (production|development)/, serverReadyPattern: /Next mode: (production|development)/,
packageJson: { packageJson: {
scripts: { scripts: {
......
import { FileRef, nextTestSetup } from 'e2e-utils' import { FileRef, nextTestSetup, isNextDev } from 'e2e-utils'
import { join } from 'path' import { join } from 'path'
const mockedGoogleFontResponses = require.resolve( const mockedGoogleFontResponses = require.resolve(
...@@ -8,7 +8,7 @@ const mockedGoogleFontResponses = require.resolve( ...@@ -8,7 +8,7 @@ const mockedGoogleFontResponses = require.resolve(
// Deploy mode exclusion: This suite intentionally fails the build, so there is no successful deployment to exercise. // Deploy mode exclusion: This suite intentionally fails the build, so there is no successful deployment to exercise.
// @force-gate !deploy // @force-gate !deploy
describe('next/font/google fetch error', () => { describe('next/font/google fetch error', () => {
const isDev = (global as any).isNextDev const isDev = isNextDev
const isTurbopack = !!process.env.IS_TURBOPACK_TEST const isTurbopack = !!process.env.IS_TURBOPACK_TEST
const { next } = nextTestSetup({ const { next } = nextTestSetup({
......
import { FileRef, nextTestSetup } from 'e2e-utils' import { FileRef, nextTestSetup, isNextDev } from 'e2e-utils'
import { join } from 'path' import { join } from 'path'
const mockedGoogleFontResponses = require.resolve( const mockedGoogleFontResponses = require.resolve(
...@@ -9,7 +9,7 @@ const mockedGoogleFontResponses = require.resolve( ...@@ -9,7 +9,7 @@ const mockedGoogleFontResponses = require.resolve(
// Deploy mode exclusion: This suite intentionally fails the build, so there is no successful deployment to exercise. // Deploy mode exclusion: This suite intentionally fails the build, so there is no successful deployment to exercise.
// @force-gate turbopack && !deploy // @force-gate turbopack && !deploy
describe('next/font/google font file fetch error', () => { describe('next/font/google font file fetch error', () => {
const isDev = (global as any).isNextDev const isDev = isNextDev
const fetchError = const fetchError =
'Received response with status 404 when requesting https://fonts.gstatic.com/s/bitter/v42/does-not-exist.woff2' 'Received response with status 404 when requesting https://fonts.gstatic.com/s/bitter/v42/does-not-exist.woff2'
const missingModule = const missingModule =
......
import cheerio from 'cheerio' import cheerio from 'cheerio'
import { FileRef, nextTestSetup } from 'e2e-utils' import { FileRef, nextTestSetup, isNextDev } from 'e2e-utils'
import { renderViaHTTP } from 'next-test-utils' import { renderViaHTTP } from 'next-test-utils'
import { join } from 'path' import { join } from 'path'
...@@ -52,7 +52,7 @@ describe('next/font', () => { ...@@ -52,7 +52,7 @@ describe('next/font', () => {
}, },
}) })
if ((global as any).isNextDev) { if (isNextDev) {
it('should use production cache control for fonts', async () => { it('should use production cache control for fonts', async () => {
const $ = await next.render$('/') const $ = await next.render$('/')
const link = $('[rel="preload"][as="font"]').attr('href') const link = $('[rel="preload"][as="font"]').attr('href')
......
import cheerio from 'cheerio' import cheerio from 'cheerio'
import { nextTestSetup } from 'e2e-utils' import { nextTestSetup, isNextDev } from 'e2e-utils'
import { renderViaHTTP } from 'next-test-utils' import { renderViaHTTP } from 'next-test-utils'
import { join } from 'path' import { join } from 'path'
...@@ -7,7 +7,7 @@ const mockedGoogleFontResponses = require.resolve( ...@@ -7,7 +7,7 @@ const mockedGoogleFontResponses = require.resolve(
'./google-font-mocked-responses.js' './google-font-mocked-responses.js'
) )
const isDev = (global as any).isNextDev const isDev = isNextDev
// Deploy mode exclusion: This suite passes an absolute local mocked-font-response path into the build. // Deploy mode exclusion: This suite passes an absolute local mocked-font-response path into the build.
// @force-gate !deploy // @force-gate !deploy
......
import { FileRef, nextTestSetup } from 'e2e-utils' import { FileRef, nextTestSetup, isNextDev } from 'e2e-utils'
import { renderViaHTTP } from 'next-test-utils' import { renderViaHTTP } from 'next-test-utils'
import cheerio from 'cheerio' import cheerio from 'cheerio'
import { join } from 'path' import { join } from 'path'
...@@ -63,7 +63,7 @@ describe('next/head', () => { ...@@ -63,7 +63,7 @@ describe('next/head', () => {
}) })
describe('next/head dev route discovery', () => { describe('next/head dev route discovery', () => {
if (!(global as any).isNextDev) { if (!isNextDev) {
return return
} }
......
import { FileRef, nextTestSetup } from 'e2e-utils' import { FileRef, nextTestSetup, isNextStart, isNextDev } from 'e2e-utils'
import { fetchViaHTTP, renderViaHTTP } from 'next-test-utils' import { fetchViaHTTP, renderViaHTTP } from 'next-test-utils'
import { randomUUID } from 'crypto' import { randomUUID } from 'crypto'
import fs from 'fs-extra' import fs from 'fs-extra'
...@@ -64,10 +64,7 @@ describe('og-api', () => { ...@@ -64,10 +64,7 @@ describe('og-api', () => {
expect(body.size).toBeGreaterThan(0) expect(body.size).toBeGreaterThan(0)
}) })
if ( if (isNextStart && process.env.TEST_OUTPUT_STANDALONE === 'true') {
(global as any).isNextStart &&
process.env.TEST_OUTPUT_STANDALONE === 'true'
) {
it('should copy files correctly', async () => { it('should copy files correctly', async () => {
expect(next.cliOutput).not.toContain('Failed to copy traced files') expect(next.cliOutput).not.toContain('Failed to copy traced files')
...@@ -90,7 +87,7 @@ describe('og-api', () => { ...@@ -90,7 +87,7 @@ describe('og-api', () => {
}) })
} }
if ((global as any).isNextDev) { if (isNextDev) {
it('should throw error when returning a response object in pages/api in node runtime', async () => { it('should throw error when returning a response object in pages/api in node runtime', async () => {
const res = await fetchViaHTTP(next.url, '/api/og-wrong-runtime') const res = await fetchViaHTTP(next.url, '/api/og-wrong-runtime')
expect(res.status).toBe(500) expect(res.status).toBe(500)
......
import { nextTestSetup } from 'e2e-utils' import { nextTestSetup, isNextDev } from 'e2e-utils'
import { retry } from 'next-test-utils' import { retry } from 'next-test-utils'
for (const { app, src, pathname, text } of [ for (const { app, src, pathname, text } of [
...@@ -53,7 +53,7 @@ for (const { app, src, pathname, text } of [ ...@@ -53,7 +53,7 @@ for (const { app, src, pathname, text } of [
start: 'next start', start: 'next start',
}, },
}, },
startCommand: `pnpm ${(global as any).isNextDev ? 'dev' : 'start'}`, startCommand: `pnpm ${isNextDev ? 'dev' : 'start'}`,
buildCommand: `pnpm build`, buildCommand: `pnpm build`,
dependencies: require('./package.json').dependencies, dependencies: require('./package.json').dependencies,
}) })
......
import path from 'path' import path from 'path'
import { isReact18, nextTestSetup } from 'e2e-utils' import { isReact18, nextTestSetup, isNextStart } from 'e2e-utils'
const fixture = path.join(__dirname, 'prerender-native-module') const fixture = path.join(__dirname, 'prerender-native-module')
...@@ -57,7 +57,7 @@ describe('prerender native module', () => { ...@@ -57,7 +57,7 @@ describe('prerender native module', () => {
}) })
}) })
if ((global as any).isNextStart) { if (isNextStart) {
it('should output traces', async () => { it('should output traces', async () => {
const checks = [ const checks = [
{ {
......
...@@ -3,7 +3,14 @@ import cookie from 'cookie' ...@@ -3,7 +3,14 @@ import cookie from 'cookie'
import cheerio from 'cheerio' import cheerio from 'cheerio'
import { join, sep } from 'path' import { join, sep } from 'path'
import escapeRegex from 'escape-string-regexp' import escapeRegex from 'escape-string-regexp'
import { FileRef, isReact18, nextTestSetup } from 'e2e-utils' import {
FileRef,
isReact18,
nextTestSetup,
isNextStart,
isNextDev,
isNextDeploy,
} from 'e2e-utils'
import { import {
waitForRedbox, waitForRedbox,
check, check,
...@@ -924,7 +931,7 @@ describe('Prerender', () => { ...@@ -924,7 +931,7 @@ describe('Prerender', () => {
expect(value).toMatch(/Hi \[third\] \[fourth\]/) expect(value).toMatch(/Hi \[third\] \[fourth\]/)
}) })
if ((global as any).isNextStart) { if (isNextStart) {
// TODO: dev currently renders this page as blocking, meaning it shows the // TODO: dev currently renders this page as blocking, meaning it shows the
// server error instead of continuously retrying. Do we want to change this? // server error instead of continuously retrying. Do we want to change this?
it.skip('should reload page on failed data request, and retry', async () => { it.skip('should reload page on failed data request, and retry', async () => {
...@@ -1148,7 +1155,7 @@ describe('Prerender', () => { ...@@ -1148,7 +1155,7 @@ describe('Prerender', () => {
) )
}) })
if ((global as any).isNextDev) { if (isNextDev) {
it('should show warning every time page with large amount of page data is returned', async () => { it('should show warning every time page with large amount of page data is returned', async () => {
await renderViaHTTP(next.url, '/large-page-data-ssr') await renderViaHTTP(next.url, '/large-page-data-ssr')
await check( await check(
...@@ -1165,7 +1172,7 @@ describe('Prerender', () => { ...@@ -1165,7 +1172,7 @@ describe('Prerender', () => {
}) })
} }
if ((global as any).isNextStart) { if (isNextStart) {
it('should only show warning once per page when large amount of page data is returned', async () => { it('should only show warning once per page when large amount of page data is returned', async () => {
await renderViaHTTP(next.url, '/large-page-data-ssr') await renderViaHTTP(next.url, '/large-page-data-ssr')
await check( await check(
...@@ -1181,7 +1188,7 @@ describe('Prerender', () => { ...@@ -1181,7 +1188,7 @@ describe('Prerender', () => {
}) })
} }
if ((global as any).isNextDev) { if (isNextDev) {
it('should not show warning from url prop being returned', async () => { it('should not show warning from url prop being returned', async () => {
await next.patchFile( await next.patchFile(
'pages/url-prop.js', 'pages/url-prop.js',
...@@ -1428,7 +1435,7 @@ describe('Prerender', () => { ...@@ -1428,7 +1435,7 @@ describe('Prerender', () => {
await check(() => getBrowserBodyText(browser), /hello /) await check(() => getBrowserBodyText(browser), /hello /)
}) })
if ((global as any).isNextStart && !isDeploy) { if (isNextStart && !isDeploy) {
it('outputs dataRoutes in routes-manifest correctly', async () => { it('outputs dataRoutes in routes-manifest correctly', async () => {
const { dataRoutes } = JSON.parse( const { dataRoutes } = JSON.parse(
await next.readFile('.next/routes-manifest.json') await next.readFile('.next/routes-manifest.json')
...@@ -2270,7 +2277,7 @@ describe('Prerender', () => { ...@@ -2270,7 +2277,7 @@ describe('Prerender', () => {
}) })
} }
if ((global as any).isNextStart) { if (isNextStart) {
it('should of formatted build output correctly', () => { it('should of formatted build output correctly', () => {
expect(next.cliOutput).toMatch(/○ \/normal/) expect(next.cliOutput).toMatch(/○ \/normal/)
expect(next.cliOutput).toMatch(/[├└] {3}\/blog\/\[post\]/) expect(next.cliOutput).toMatch(/[├└] {3}\/blog\/\[post\]/)
...@@ -2698,5 +2705,5 @@ describe('Prerender', () => { ...@@ -2698,5 +2705,5 @@ describe('Prerender', () => {
expect(next.cliOutput).not.toContain('argument entity must be string') expect(next.cliOutput).not.toContain('argument entity must be string')
}) })
} }
runTests((global as any).isNextDev, (global as any).isNextDeploy) runTests(isNextDev, isNextDeploy)
}) })
import { isReact18, nextTestSetup, FileRef } from 'e2e-utils' import { isReact18, nextTestSetup, FileRef, isNextDeploy } from 'e2e-utils'
import { waitForRedbox, shouldUseTurbopack } from 'next-test-utils' import { waitForRedbox, shouldUseTurbopack } from 'next-test-utils'
import { join } from 'path' import { join } from 'path'
import stripAnsi from 'strip-ansi' import stripAnsi from 'strip-ansi'
...@@ -26,7 +26,7 @@ describe.each(['default', 'babelrc', 'rust'] as const)( ...@@ -26,7 +26,7 @@ describe.each(['default', 'babelrc', 'rust'] as const)(
return return
} }
const dependencies = (global as any).isNextDeploy const dependencies = isNextDeploy
? // `link` is incompatible with the npm version used when this test is deployed ? // `link` is incompatible with the npm version used when this test is deployed
{ {
'reference-library': 'file:./reference-library', 'reference-library': 'file:./reference-library',
......
import { FileRef, nextTestSetup } from 'e2e-utils' import { FileRef, nextTestSetup, isNextDeploy, isNextStart } from 'e2e-utils'
import { check, fetchViaHTTP } from 'next-test-utils' import { check, fetchViaHTTP } from 'next-test-utils'
import { import {
NEXT_HMR_REFRESH_HEADER, NEXT_HMR_REFRESH_HEADER,
...@@ -225,7 +225,7 @@ describe('skip-trailing-slash-redirect', () => { ...@@ -225,7 +225,7 @@ describe('skip-trailing-slash-redirect', () => {
expect(res.status).toBe(200) expect(res.status).toBe(200)
expect(await res.text()).toContain('Example Domain') expect(await res.text()).toContain('Example Domain')
if (!(global as any).isNextDeploy) { if (!isNextDeploy) {
await check(() => next.cliOutput, /missing-id rewrite/) await check(() => next.cliOutput, /missing-id rewrite/)
expect(next.cliOutput).toContain('/_next/data/missing-id/hello.json') expect(next.cliOutput).toContain('/_next/data/missing-id/hello.json')
} }
...@@ -310,7 +310,7 @@ describe('skip-trailing-slash-redirect', () => { ...@@ -310,7 +310,7 @@ describe('skip-trailing-slash-redirect', () => {
) )
}) })
if ((global as any).isNextStart) { if (isNextStart) {
it('should not have trailing slash redirects in manifest', async () => { it('should not have trailing slash redirects in manifest', async () => {
const routesManifest = JSON.parse( const routesManifest = JSON.parse(
await next.readFile('.next/routes-manifest.json') await next.readFile('.next/routes-manifest.json')
......
import { join } from 'path' import { join } from 'path'
import { renderViaHTTP, check } from 'next-test-utils' import { renderViaHTTP, check } from 'next-test-utils'
import { FileRef, nextTestSetup } from 'e2e-utils' import { FileRef, nextTestSetup, isNextDev } from 'e2e-utils'
describe('React Context', () => { describe('React Context', () => {
const { next } = nextTestSetup({ const { next } = nextTestSetup({
...@@ -20,7 +20,7 @@ describe('React Context', () => { ...@@ -20,7 +20,7 @@ describe('React Context', () => {
expect(html).toMatch(/Value: .*?12345/) expect(html).toMatch(/Value: .*?12345/)
}) })
if ((globalThis as any).isNextDev) { if (isNextDev) {
it('should render with context after change', async () => { it('should render with context after change', async () => {
const aboutAppPagePath = 'pages/_app.js' const aboutAppPagePath = 'pages/_app.js'
const originalContent = await next.readFile(aboutAppPagePath) const originalContent = await next.readFile(aboutAppPagePath)
......
import { join } from 'path' import { join } from 'path'
import { nextTestSetup } from 'e2e-utils' import { nextTestSetup, isNextDev, isNextDeploy } from 'e2e-utils'
import { import {
check, check,
fetchViaHTTP, fetchViaHTTP,
...@@ -9,7 +9,7 @@ import { ...@@ -9,7 +9,7 @@ import {
renderViaHTTP, renderViaHTTP,
} from 'next-test-utils' } from 'next-test-utils'
const isNextProd = !(global as any).isNextDev && !(global as any).isNextDeploy const isNextProd = !isNextDev && !isNextDeploy
describe('streaming SSR with custom next configs', () => { describe('streaming SSR with custom next configs', () => {
const { next } = nextTestSetup({ const { next } = nextTestSetup({
...@@ -55,7 +55,7 @@ describe('streaming SSR with custom next configs', () => { ...@@ -55,7 +55,7 @@ describe('streaming SSR with custom next configs', () => {
expect(html).toContain('マルチバイト'.repeat(28)) expect(html).toContain('マルチバイト'.repeat(28))
}) })
if ((global as any).isNextDev) { if (isNextDev) {
it('should work with custom document', async () => { it('should work with custom document', async () => {
await next.patchFile( await next.patchFile(
'pages/_document.js', 'pages/_document.js',
......
/* eslint-env jest */ /* eslint-env jest */
import { FileRef, nextTestSetup } from 'e2e-utils' import { FileRef, nextTestSetup, isNextDev } from 'e2e-utils'
import { check, fetchViaHTTP, renderViaHTTP, waitFor } from 'next-test-utils' import { check, fetchViaHTTP, renderViaHTTP, waitFor } from 'next-test-utils'
function splitLines(text) { function splitLines(text) {
...@@ -44,7 +44,7 @@ describe('Switchable runtime', () => { ...@@ -44,7 +44,7 @@ describe('Switchable runtime', () => {
} }
}) })
if ((global as any).isNextDev) { if (isNextDev) {
describe('Switchable runtime (dev)', () => { describe('Switchable runtime (dev)', () => {
it('should not include edge api routes and edge ssr routes into dev middleware manifest', async () => { it('should not include edge api routes and edge ssr routes into dev middleware manifest', async () => {
const res = await fetchViaHTTP( const res = await fetchViaHTTP(
......
import { nextTestSetup } from 'e2e-utils' import { nextTestSetup, isNextStart } from 'e2e-utils'
import fs from 'fs-extra' import fs from 'fs-extra'
import os from 'os' import os from 'os'
import path from 'path' import path from 'path'
...@@ -9,7 +9,7 @@ import { ...@@ -9,7 +9,7 @@ import {
fetchViaHTTP, fetchViaHTTP,
} from 'next-test-utils' } from 'next-test-utils'
if (!(globalThis as any).isNextStart) { if (!isNextStart) {
it('should skip for non-next start', () => {}) it('should skip for non-next start', () => {})
} else { } else {
describe('output: standalone with twoslash', () => { describe('output: standalone with twoslash', () => {
......
import { nextTestSetup } from 'e2e-utils' import { nextTestSetup, isNextDeploy } from 'e2e-utils'
import { waitForNoRedbox, renderViaHTTP } from 'next-test-utils' import { waitForNoRedbox, renderViaHTTP } from 'next-test-utils'
import cheerio from 'cheerio' import cheerio from 'cheerio'
...@@ -62,7 +62,7 @@ describe('Type module interop', () => { ...@@ -62,7 +62,7 @@ describe('Type module interop', () => {
beforeAll(async () => { beforeAll(async () => {
// can't modify build output after deploy // can't modify build output after deploy
if (!(global as any).isNextDeploy) { if (!isNextDeploy) {
const contents = await next.readFile('package.json') const contents = await next.readFile('package.json')
const pkg = JSON.parse(contents) const pkg = JSON.parse(contents)
await next.patchFile( await next.patchFile(
......
import fs from 'fs-extra' import fs from 'fs-extra'
import { join } from 'path' import { join } from 'path'
import { fetchViaHTTP } from 'next-test-utils' import { fetchViaHTTP } from 'next-test-utils'
import { FileRef, nextTestSetup } from 'e2e-utils' import { FileRef, nextTestSetup, isNextDeploy, isNextDev } from 'e2e-utils'
jest.setTimeout(2 * 60 * 1000) jest.setTimeout(2 * 60 * 1000)
...@@ -12,7 +12,7 @@ export function runTests( ...@@ -12,7 +12,7 @@ export function runTests(
) { ) {
const versionParts = process.versions.node.split('.').map((i) => Number(i)) const versionParts = process.versions.node.split('.').map((i) => Number(i))
if ((global as any).isNextDeploy) { if (isNextDeploy) {
it('should not run for next deploy', () => {}) it('should not run for next deploy', () => {})
return return
} }
...@@ -63,7 +63,7 @@ export function runTests( ...@@ -63,7 +63,7 @@ export function runTests(
].join(' && ') ].join(' && ')
}, },
buildCommand: `yarn next build`, buildCommand: `yarn next build`,
startCommand: (global as any).isNextDev ? `yarn next` : `yarn next start`, startCommand: isNextDev ? `yarn next` : `yarn next start`,
}) })
it(`should compile and serve the index page correctly ${example}`, async () => { it(`should compile and serve the index page correctly ${example}`, async () => {
......
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