Unverified Commit eba04da2 authored by Niklas Mischkulnig's avatar Niklas Mischkulnig Committed by GitHub

Cleanup `shouldRunTurboDevTest` usage (#82603)

Co-authored-by: 's avatarvercel[bot] <35613825+vercel[bot]@users.noreply.github.com>
parent 662918f9
import { join } from 'path' import { join } from 'path'
import webdriver, { Playwright } from 'next-webdriver' import webdriver, { Playwright } from 'next-webdriver'
import { FileRef, nextTestSetup } from 'e2e-utils' import { FileRef, nextTestSetup } from 'e2e-utils'
import { check, shouldRunTurboDevTest } from 'next-test-utils' import { check } from 'next-test-utils'
// [TODO]: It is unclear why turbopack takes longer to run this test // [TODO]: It is unclear why turbopack takes longer to run this test
// remove once it's fixed // remove once it's fixed
if (shouldRunTurboDevTest()) { if (process.env.IS_TURBOPACK_TEST) {
jest.setTimeout(1000 * 60 * 5) jest.setTimeout(1000 * 60 * 5)
} }
......
import { nextTestSetup } from 'e2e-utils' import { nextTestSetup } from 'e2e-utils'
import { shouldRunTurboDevTest } from 'next-test-utils'
describe('experimental-https-server OpenGraph image', () => { describe('experimental-https-server OpenGraph image', () => {
const { next, skipped } = nextTestSetup({ const { next, skipped } = nextTestSetup({
files: __dirname, files: __dirname,
startCommand: `pnpm next ${ startCommand: 'pnpm next dev --experimental-https',
shouldRunTurboDevTest() ? 'dev --turbo' : 'dev'
} --experimental-https`,
skipStart: !process.env.NEXT_TEST_CI, skipStart: !process.env.NEXT_TEST_CI,
}) })
if (skipped) return if (skipped) return
......
import { nextTestSetup } from 'e2e-utils' import { nextTestSetup } from 'e2e-utils'
import https from 'https' import https from 'https'
import { renderViaHTTP, shouldRunTurboDevTest } from 'next-test-utils' import { renderViaHTTP } from 'next-test-utils'
describe('experimental-https-server (generated certificate)', () => { describe('experimental-https-server (generated certificate)', () => {
const { next, skipped } = nextTestSetup({ const { next, skipped } = nextTestSetup({
files: __dirname, files: __dirname,
startCommand: `pnpm next ${ startCommand: 'pnpm next dev --experimental-https',
shouldRunTurboDevTest() ? 'dev --turbo' : 'dev'
} --experimental-https`,
skipStart: !process.env.NEXT_TEST_CI, skipStart: !process.env.NEXT_TEST_CI,
}) })
if (skipped) return if (skipped) return
......
import { nextTestSetup } from 'e2e-utils' import { nextTestSetup } from 'e2e-utils'
import https from 'https' import https from 'https'
import { renderViaHTTP, shouldRunTurboDevTest } from 'next-test-utils' import { renderViaHTTP } from 'next-test-utils'
describe('experimental-https-server (provided certificate)', () => { describe('experimental-https-server (provided certificate)', () => {
const { next } = nextTestSetup({ const { next } = nextTestSetup({
files: __dirname, files: __dirname,
startCommand: `pnpm next ${ startCommand: `pnpm next dev --experimental-https --experimental-https-key ./certificates/localhost-key.pem --experimental-https-cert ./certificates/localhost.pem`,
shouldRunTurboDevTest() ? 'dev --turbo' : 'dev'
} --experimental-https --experimental-https-key ./certificates/localhost-key.pem --experimental-https-cert ./certificates/localhost.pem`,
}) })
const agent = new https.Agent({ const agent = new https.Agent({
rejectUnauthorized: false, rejectUnauthorized: false,
......
import { nextTestSetup } from 'e2e-utils' import { nextTestSetup } from 'e2e-utils'
import { import { assertNoRedbox, check, retry } from 'next-test-utils'
assertNoRedbox,
check,
retry,
shouldRunTurboDevTest,
} from 'next-test-utils'
async function resolveStreamResponse(response: any, onData?: any) { async function resolveStreamResponse(response: any, onData?: any) {
let result = '' let result = ''
...@@ -30,7 +25,7 @@ describe('app dir - external dependency', () => { ...@@ -30,7 +25,7 @@ describe('app dir - external dependency', () => {
packageJson: { packageJson: {
scripts: { scripts: {
build: 'next build', build: 'next build',
dev: `next ${shouldRunTurboDevTest() ? 'dev --turbo' : 'dev'}`, dev: 'next dev',
start: 'next start', start: 'next start',
}, },
}, },
......
import { createNext } from 'e2e-utils' import { createNext } from 'e2e-utils'
import { NextInstance } from 'e2e-utils' import { NextInstance } from 'e2e-utils'
import { fetchViaHTTP, shouldRunTurboDevTest } from 'next-test-utils' import { fetchViaHTTP } from 'next-test-utils'
describe('Edge compiler module exports preference', () => { describe('Edge compiler module exports preference', () => {
let next: NextInstance let next: NextInstance
...@@ -44,7 +44,7 @@ describe('Edge compiler module exports preference', () => { ...@@ -44,7 +44,7 @@ describe('Edge compiler module exports preference', () => {
packageJson: { packageJson: {
scripts: { scripts: {
build: 'next build', build: 'next build',
dev: `next ${shouldRunTurboDevTest() ? 'dev --turbo' : 'dev'}`, dev: 'next dev',
start: 'next start', start: 'next start',
}, },
}, },
......
import { nextTestSetup } from 'e2e-utils' import { nextTestSetup } from 'e2e-utils'
import { shouldRunTurboDevTest } from '../../lib/next-test-utils'
describe('edge-runtime uses edge-light import specifier for packages', () => { describe('edge-runtime uses edge-light import specifier for packages', () => {
const { next, skipped } = nextTestSetup({ const { next, skipped } = nextTestSetup({
...@@ -7,7 +6,7 @@ describe('edge-runtime uses edge-light import specifier for packages', () => { ...@@ -7,7 +6,7 @@ describe('edge-runtime uses edge-light import specifier for packages', () => {
packageJson: { packageJson: {
scripts: { scripts: {
build: 'next build', build: 'next build',
dev: `next ${shouldRunTurboDevTest() ? 'dev --turbo' : 'dev'}`, dev: 'next dev',
start: 'next start', start: 'next start',
}, },
}, },
......
...@@ -4,12 +4,7 @@ import fs from 'fs-extra' ...@@ -4,12 +4,7 @@ import fs from 'fs-extra'
import { join } from 'path' import { join } from 'path'
import webdriver from 'next-webdriver' import webdriver from 'next-webdriver'
import { isNextStart, NextInstance } from 'e2e-utils' import { isNextStart, NextInstance } from 'e2e-utils'
import { import { check, fetchViaHTTP, waitFor } from 'next-test-utils'
check,
fetchViaHTTP,
shouldRunTurboDevTest,
waitFor,
} from 'next-test-utils'
import { createNext, FileRef } from 'e2e-utils' import { createNext, FileRef } from 'e2e-utils'
const urlsError = 'Please use only absolute URLs' const urlsError = 'Please use only absolute URLs'
...@@ -89,9 +84,7 @@ describe('Middleware Runtime', () => { ...@@ -89,9 +84,7 @@ describe('Middleware Runtime', () => {
scripts: { scripts: {
setup: `cp -r ./shared-package ./node_modules`, setup: `cp -r ./shared-package ./node_modules`,
build: 'pnpm run setup && next build', build: 'pnpm run setup && next build',
dev: `pnpm run setup && next ${ dev: 'pnpm run setup && next dev',
shouldRunTurboDevTest() ? 'dev --turbo' : 'dev'
}`,
start: 'next start', start: 'next start',
}, },
}, },
......
...@@ -6,7 +6,7 @@ import { NextInstance, NextInstanceOpts } from '../next-modes/base' ...@@ -6,7 +6,7 @@ import { NextInstance, NextInstanceOpts } from '../next-modes/base'
import { NextDevInstance } from '../next-modes/next-dev' import { NextDevInstance } from '../next-modes/next-dev'
import { NextStartInstance } from '../next-modes/next-start' import { NextStartInstance } from '../next-modes/next-start'
import { NextDeployInstance } from '../next-modes/next-deploy' import { NextDeployInstance } from '../next-modes/next-deploy'
import { shouldRunTurboDevTest } from '../next-test-utils' import { shouldUseTurbopack } from '../next-test-utils'
export type { NextInstance } export type { NextInstance }
...@@ -14,9 +14,7 @@ export type { NextInstance } ...@@ -14,9 +14,7 @@ export type { NextInstance }
// if either test runs for the --turbo or have a custom timeout, set reduced timeout instead. // if either test runs for the --turbo or have a custom timeout, set reduced timeout instead.
// this is due to current --turbo test have a lot of tests fails with timeouts, ends up the whole // this is due to current --turbo test have a lot of tests fails with timeouts, ends up the whole
// test job exceeds the 6 hours limit. // test job exceeds the 6 hours limit.
let testTimeout = shouldRunTurboDevTest() let testTimeout = (process.platform === 'win32' ? 240 : 120) * 1000
? (240 * 1000) / 2
: (process.platform === 'win32' ? 240 : 120) * 1000
if (process.env.NEXT_E2E_TEST_TIMEOUT) { if (process.env.NEXT_E2E_TEST_TIMEOUT) {
try { try {
...@@ -166,7 +164,7 @@ export async function createNext( ...@@ -166,7 +164,7 @@ export async function createNext(
return await trace('createNext').traceAsyncFn(async (rootSpan) => { return await trace('createNext').traceAsyncFn(async (rootSpan) => {
const useTurbo = !!process.env.NEXT_TEST_WASM const useTurbo = !!process.env.NEXT_TEST_WASM
? false ? false
: opts?.turbo ?? shouldRunTurboDevTest() : opts?.turbo ?? shouldUseTurbopack()
if (testMode === 'dev') { if (testMode === 'dev') {
// next dev // next dev
...@@ -291,8 +289,7 @@ export function nextTestSetup( ...@@ -291,8 +289,7 @@ export function nextTestSetup(
}, },
get isTurbopack(): boolean { get isTurbopack(): boolean {
return Boolean( return Boolean(
!process.env.NEXT_TEST_WASM && !process.env.NEXT_TEST_WASM && (options.turbo ?? shouldUseTurbopack())
(options.turbo ?? shouldRunTurboDevTest())
) )
}, },
......
import spawn from 'cross-spawn' import spawn from 'cross-spawn'
import { Span } from 'next/dist/trace' import { Span } from 'next/dist/trace'
import { NextInstance } from './base' import { NextInstance } from './base'
import { getTurbopackFlag } from '../turbo'
import { retry, waitFor } from 'next-test-utils' import { retry, waitFor } from 'next-test-utils'
import stripAnsi from 'strip-ansi' import stripAnsi from 'strip-ansi'
...@@ -33,7 +32,7 @@ export class NextDevInstance extends NextInstance { ...@@ -33,7 +32,7 @@ export class NextDevInstance extends NextInstance {
let startArgs = [ let startArgs = [
'pnpm', 'pnpm',
'next', 'next',
useTurbo ? getTurbopackFlag() : undefined, useTurbo ? '--turbopack' : undefined,
].filter(Boolean) as string[] ].filter(Boolean) as string[]
if (this.startCommand) { if (this.startCommand) {
......
...@@ -28,13 +28,13 @@ import type { RequestInit, Response } from 'node-fetch' ...@@ -28,13 +28,13 @@ import type { RequestInit, Response } from 'node-fetch'
import type { NextServer } from 'next/dist/server/next' import type { NextServer } from 'next/dist/server/next'
import { Playwright } from 'next-webdriver' import { Playwright } from 'next-webdriver'
import { getTurbopackFlag, shouldRunTurboDevTest } from './turbo' import { shouldUseTurbopack } from './turbo'
import stripAnsi from 'strip-ansi' import stripAnsi from 'strip-ansi'
// TODO: Create dedicated Jest environment that sets up these matchers // TODO: Create dedicated Jest environment that sets up these matchers
// Edge Runtime unit tests fail with "EvalError: Code generation from strings disallowed for this context" if these matchers are imported in those tests. // Edge Runtime unit tests fail with "EvalError: Code generation from strings disallowed for this context" if these matchers are imported in those tests.
import './add-redbox-matchers' import './add-redbox-matchers'
export { shouldRunTurboDevTest } export { shouldUseTurbopack }
export const nextServer = server export const nextServer = server
export const pkg = _pkg export const pkg = _pkg
...@@ -451,11 +451,11 @@ export function launchApp( ...@@ -451,11 +451,11 @@ export function launchApp(
opts?: NextDevOptions opts?: NextDevOptions
) { ) {
const options = opts ?? {} const options = opts ?? {}
const useTurbo = shouldRunTurboDevTest() const useTurbo = shouldUseTurbopack()
return runNextCommandDev( return runNextCommandDev(
[ [
useTurbo ? getTurbopackFlag() : undefined, useTurbo ? '--turbopack' : undefined,
dir, dir,
'-p', '-p',
port as string, port as string,
...@@ -1435,7 +1435,7 @@ export function getSnapshotTestDescribe(variant: TestVariants) { ...@@ -1435,7 +1435,7 @@ export function getSnapshotTestDescribe(variant: TestVariants) {
) )
} }
const shouldRunTurboDev = shouldRunTurboDevTest() const shouldRunTurboDev = shouldUseTurbopack()
const shouldSkip = const shouldSkip =
(runningEnv === 'turbo' && !shouldRunTurboDev) || (runningEnv === 'turbo' && !shouldRunTurboDev) ||
(runningEnv === 'default' && shouldRunTurboDev) (runningEnv === 'default' && shouldRunTurboDev)
......
let loggedTurbopack = false let loggedTurbopack = false
/** export function shouldUseTurbopack(): boolean {
* Utility function to determine if a given test case needs to run with --turbo.
*
* This is primarily for the gradual test enablement with latest turbopack upstream changes.
*
* Note: it could be possible to dynamically create test cases itself (createDevTest(): it.each([...])), but
* it makes hard to conform with existing lint rules. Instead, starting off from manual fixture setup and
* update test cases accordingly as turbopack changes enable more test cases.
*/
export function shouldRunTurboDevTest(): boolean {
if (!!process.env.NEXT_TEST_WASM) { if (!!process.env.NEXT_TEST_WASM) {
return false return false
} }
const shouldRunTurboDev = !!process.env.IS_TURBOPACK_TEST const enabled = !!process.env.IS_TURBOPACK_TEST
if (shouldRunTurboDev && !loggedTurbopack) { if (enabled && !loggedTurbopack) {
require('console').log( require('console').log(
`Running tests with turbopack because environment variable TURBOPACK is set` `Running tests with turbopack because environment variable IS_TURBOPACK_TEST is set`
) )
loggedTurbopack = true loggedTurbopack = true
} }
return shouldRunTurboDev return enabled
}
export function getTurbopackFlag(): string {
if (!!process.env.IS_TURBOPACK_TEST) {
return '--turbo'
} else {
throw Error(`Cannot get the flag for running turbopack`)
}
} }
...@@ -9,7 +9,6 @@ import { ...@@ -9,7 +9,6 @@ import {
initNextServerScript, initNextServerScript,
killApp, killApp,
renderViaHTTP, renderViaHTTP,
shouldRunTurboDevTest,
} from 'next-test-utils' } from 'next-test-utils'
describe('pnpm support', () => { describe('pnpm support', () => {
...@@ -73,7 +72,7 @@ describe('pnpm support', () => { ...@@ -73,7 +72,7 @@ describe('pnpm support', () => {
}, },
packageJson: { packageJson: {
scripts: { scripts: {
dev: `next ${shouldRunTurboDevTest() ? 'dev --turbo' : 'dev'}`, dev: 'next dev',
build: 'next build', build: 'next build',
start: 'next start', start: 'next start',
}, },
......
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