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