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 webdriver, { Playwright } from 'next-webdriver'
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
// remove once it's fixed
if (shouldRunTurboDevTest()) {
if (process.env.IS_TURBOPACK_TEST) {
jest.setTimeout(1000 * 60 * 5)
}
......
import { nextTestSetup } from 'e2e-utils'
import { shouldRunTurboDevTest } from 'next-test-utils'
describe('experimental-https-server OpenGraph image', () => {
const { next, skipped } = nextTestSetup({
files: __dirname,
startCommand: `pnpm next ${
shouldRunTurboDevTest() ? 'dev --turbo' : 'dev'
} --experimental-https`,
startCommand: 'pnpm next dev --experimental-https',
skipStart: !process.env.NEXT_TEST_CI,
})
if (skipped) return
......
import { nextTestSetup } from 'e2e-utils'
import https from 'https'
import { renderViaHTTP, shouldRunTurboDevTest } from 'next-test-utils'
import { renderViaHTTP } from 'next-test-utils'
describe('experimental-https-server (generated certificate)', () => {
const { next, skipped } = nextTestSetup({
files: __dirname,
startCommand: `pnpm next ${
shouldRunTurboDevTest() ? 'dev --turbo' : 'dev'
} --experimental-https`,
startCommand: 'pnpm next dev --experimental-https',
skipStart: !process.env.NEXT_TEST_CI,
})
if (skipped) return
......
import { nextTestSetup } from 'e2e-utils'
import https from 'https'
import { renderViaHTTP, shouldRunTurboDevTest } from 'next-test-utils'
import { renderViaHTTP } from 'next-test-utils'
describe('experimental-https-server (provided certificate)', () => {
const { next } = nextTestSetup({
files: __dirname,
startCommand: `pnpm next ${
shouldRunTurboDevTest() ? 'dev --turbo' : 'dev'
} --experimental-https --experimental-https-key ./certificates/localhost-key.pem --experimental-https-cert ./certificates/localhost.pem`,
startCommand: `pnpm next dev --experimental-https --experimental-https-key ./certificates/localhost-key.pem --experimental-https-cert ./certificates/localhost.pem`,
})
const agent = new https.Agent({
rejectUnauthorized: false,
......
import { nextTestSetup } from 'e2e-utils'
import {
assertNoRedbox,
check,
retry,
shouldRunTurboDevTest,
} from 'next-test-utils'
import { assertNoRedbox, check, retry } from 'next-test-utils'
async function resolveStreamResponse(response: any, onData?: any) {
let result = ''
......@@ -30,7 +25,7 @@ describe('app dir - external dependency', () => {
packageJson: {
scripts: {
build: 'next build',
dev: `next ${shouldRunTurboDevTest() ? 'dev --turbo' : 'dev'}`,
dev: 'next dev',
start: 'next start',
},
},
......
import { createNext } 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', () => {
let next: NextInstance
......@@ -44,7 +44,7 @@ describe('Edge compiler module exports preference', () => {
packageJson: {
scripts: {
build: 'next build',
dev: `next ${shouldRunTurboDevTest() ? 'dev --turbo' : 'dev'}`,
dev: 'next dev',
start: 'next start',
},
},
......
import { nextTestSetup } from 'e2e-utils'
import { shouldRunTurboDevTest } from '../../lib/next-test-utils'
describe('edge-runtime uses edge-light import specifier for packages', () => {
const { next, skipped } = nextTestSetup({
......@@ -7,7 +6,7 @@ describe('edge-runtime uses edge-light import specifier for packages', () => {
packageJson: {
scripts: {
build: 'next build',
dev: `next ${shouldRunTurboDevTest() ? 'dev --turbo' : 'dev'}`,
dev: 'next dev',
start: 'next start',
},
},
......
......@@ -4,12 +4,7 @@ import fs from 'fs-extra'
import { join } from 'path'
import webdriver from 'next-webdriver'
import { isNextStart, NextInstance } from 'e2e-utils'
import {
check,
fetchViaHTTP,
shouldRunTurboDevTest,
waitFor,
} from 'next-test-utils'
import { check, fetchViaHTTP, waitFor } from 'next-test-utils'
import { createNext, FileRef } from 'e2e-utils'
const urlsError = 'Please use only absolute URLs'
......@@ -89,9 +84,7 @@ describe('Middleware Runtime', () => {
scripts: {
setup: `cp -r ./shared-package ./node_modules`,
build: 'pnpm run setup && next build',
dev: `pnpm run setup && next ${
shouldRunTurboDevTest() ? 'dev --turbo' : 'dev'
}`,
dev: 'pnpm run setup && next dev',
start: 'next start',
},
},
......
......@@ -6,7 +6,7 @@ import { NextInstance, NextInstanceOpts } from '../next-modes/base'
import { NextDevInstance } from '../next-modes/next-dev'
import { NextStartInstance } from '../next-modes/next-start'
import { NextDeployInstance } from '../next-modes/next-deploy'
import { shouldRunTurboDevTest } from '../next-test-utils'
import { shouldUseTurbopack } from '../next-test-utils'
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.
// 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.
let testTimeout = shouldRunTurboDevTest()
? (240 * 1000) / 2
: (process.platform === 'win32' ? 240 : 120) * 1000
let testTimeout = (process.platform === 'win32' ? 240 : 120) * 1000
if (process.env.NEXT_E2E_TEST_TIMEOUT) {
try {
......@@ -166,7 +164,7 @@ export async function createNext(
return await trace('createNext').traceAsyncFn(async (rootSpan) => {
const useTurbo = !!process.env.NEXT_TEST_WASM
? false
: opts?.turbo ?? shouldRunTurboDevTest()
: opts?.turbo ?? shouldUseTurbopack()
if (testMode === 'dev') {
// next dev
......@@ -291,8 +289,7 @@ export function nextTestSetup(
},
get isTurbopack(): boolean {
return Boolean(
!process.env.NEXT_TEST_WASM &&
(options.turbo ?? shouldRunTurboDevTest())
!process.env.NEXT_TEST_WASM && (options.turbo ?? shouldUseTurbopack())
)
},
......
import spawn from 'cross-spawn'
import { Span } from 'next/dist/trace'
import { NextInstance } from './base'
import { getTurbopackFlag } from '../turbo'
import { retry, waitFor } from 'next-test-utils'
import stripAnsi from 'strip-ansi'
......@@ -33,7 +32,7 @@ export class NextDevInstance extends NextInstance {
let startArgs = [
'pnpm',
'next',
useTurbo ? getTurbopackFlag() : undefined,
useTurbo ? '--turbopack' : undefined,
].filter(Boolean) as string[]
if (this.startCommand) {
......
......@@ -28,13 +28,13 @@ import type { RequestInit, Response } from 'node-fetch'
import type { NextServer } from 'next/dist/server/next'
import { Playwright } from 'next-webdriver'
import { getTurbopackFlag, shouldRunTurboDevTest } from './turbo'
import { shouldUseTurbopack } from './turbo'
import stripAnsi from 'strip-ansi'
// 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.
import './add-redbox-matchers'
export { shouldRunTurboDevTest }
export { shouldUseTurbopack }
export const nextServer = server
export const pkg = _pkg
......@@ -451,11 +451,11 @@ export function launchApp(
opts?: NextDevOptions
) {
const options = opts ?? {}
const useTurbo = shouldRunTurboDevTest()
const useTurbo = shouldUseTurbopack()
return runNextCommandDev(
[
useTurbo ? getTurbopackFlag() : undefined,
useTurbo ? '--turbopack' : undefined,
dir,
'-p',
port as string,
......@@ -1435,7 +1435,7 @@ export function getSnapshotTestDescribe(variant: TestVariants) {
)
}
const shouldRunTurboDev = shouldRunTurboDevTest()
const shouldRunTurboDev = shouldUseTurbopack()
const shouldSkip =
(runningEnv === 'turbo' && !shouldRunTurboDev) ||
(runningEnv === 'default' && shouldRunTurboDev)
......
let loggedTurbopack = false
/**
* 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 {
export function shouldUseTurbopack(): boolean {
if (!!process.env.NEXT_TEST_WASM) {
return false
}
const shouldRunTurboDev = !!process.env.IS_TURBOPACK_TEST
if (shouldRunTurboDev && !loggedTurbopack) {
const enabled = !!process.env.IS_TURBOPACK_TEST
if (enabled && !loggedTurbopack) {
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
}
return shouldRunTurboDev
}
export function getTurbopackFlag(): string {
if (!!process.env.IS_TURBOPACK_TEST) {
return '--turbo'
} else {
throw Error(`Cannot get the flag for running turbopack`)
}
return enabled
}
......@@ -9,7 +9,6 @@ import {
initNextServerScript,
killApp,
renderViaHTTP,
shouldRunTurboDevTest,
} from 'next-test-utils'
describe('pnpm support', () => {
......@@ -73,7 +72,7 @@ describe('pnpm support', () => {
},
packageJson: {
scripts: {
dev: `next ${shouldRunTurboDevTest() ? 'dev --turbo' : 'dev'}`,
dev: 'next dev',
build: 'next build',
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