Unverified Commit 6e6a3308 authored by Jiachi Liu's avatar Jiachi Liu Committed by GitHub

test: exclude the ts testing files from tsconfig during local dev in nextjs repo (#74647)

### What

We're suffering from local dev that every time the `*.test.ts` files are
resolved with the local tsconfig.json, which was intended to be handled
by the root tsconfig.json in the Next.js monorepo as they require to
resolve the utils alias.

By leveraing the `NEXT_PRIVATE_SKIP_CANARY_CHECK` flag which is renamed
to `NEXT_PRIVATE_LOCAL_DEV` for our development. This only happen in
local development in our monorepo, not in development of users or any
other situations.

### Benefits

This helps us to always write the tests with correct type hints
especially for the rare cheerio or playwright interface APIs with our
testing suite
parent 44304f00
......@@ -51,10 +51,10 @@
"prepublishOnly": "turbo run build",
"lint-staged": "lint-staged",
"next-with-deps": "./scripts/next-with-deps.sh",
"next": "cross-env NEXT_PRIVATE_SKIP_CANARY_CHECK=1 NEXT_TELEMETRY_DISABLED=1 NODE_OPTIONS=\"--trace-deprecation --enable-source-maps\" next",
"next": "cross-env NEXT_PRIVATE_LOCAL_DEV=1 NEXT_TELEMETRY_DISABLED=1 NODE_OPTIONS=\"--trace-deprecation --enable-source-maps\" next",
"next-no-sourcemaps": "echo 'No longer supported. Use `pnpm next --disable-source-maps` instead'; exit 1;",
"clean-trace-jaeger": "node scripts/rm.mjs test/integration/basic/.next && TRACE_TARGET=JAEGER pnpm next build test/integration/basic",
"debug": "cross-env NEXT_PRIVATE_SKIP_CANARY_CHECK=1 NEXT_TELEMETRY_DISABLED=1 node --inspect --trace-deprecation --enable-source-maps packages/next/dist/bin/next",
"debug": "cross-env NEXT_PRIVATE_LOCAL_DEV=1 NEXT_TELEMETRY_DISABLED=1 node --inspect --trace-deprecation --enable-source-maps packages/next/dist/bin/next",
"postinstall": "node scripts/git-configure.mjs && node scripts/install-native.mjs",
"version": "pnpm install --no-frozen-lockfile && IS_PUBLISH=yes ./scripts/check-pre-compiled.sh && git add .",
"prepare": "husky",
......
......@@ -313,6 +313,21 @@ export async function writeConfigurationDefaults(
)
}
// During local development inside Next.js repo, exclude the test files coverage by the local tsconfig
if (process.env.NEXT_PRIVATE_LOCAL_DEV && userTsConfig.exclude) {
const tsGlob = '**/*.test.ts'
const tsxGlob = '**/*.test.tsx'
if (!userTsConfig.exclude.includes(tsGlob)) {
userTsConfig.exclude.push(tsGlob)
}
if (!userTsConfig.exclude.includes(tsxGlob)) {
userTsConfig.exclude.push(tsxGlob)
}
requiredActions.push(
'Local development only: Excluded test files from coverage'
)
}
if (suggestedActions.length < 1 && requiredActions.length < 1) {
return
}
......
......@@ -242,7 +242,7 @@ function assignDefaults(
if (
!process.env.__NEXT_VERSION?.includes('canary') &&
!process.env.__NEXT_TEST_MODE &&
!process.env.NEXT_PRIVATE_SKIP_CANARY_CHECK
!process.env.NEXT_PRIVATE_LOCAL_DEV
) {
// Prevents usage of certain experimental features outside of canary
if (result.experimental?.ppr) {
......
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