Unverified Commit 7a2f4ad1 authored by Hendrik Liebau's avatar Hendrik Liebau Committed by GitHub

Type-check `run-tests.js` and remove unused `related` flag (#88433)

The file already had the `@ts-check` directive, so the IDE did show errors in that file. But since it was not included in the root `tsconfig.json`, those errors were not reported during CI runs.

One issue found this way was that the `related` flag was defined but never used. The referenced script was removed in #67644.
parent d067b620
...@@ -168,6 +168,7 @@ ...@@ -168,6 +168,7 @@
"@types/shell-quote": "1.7.1", "@types/shell-quote": "1.7.1",
"@types/string-hash": "1.1.1", "@types/string-hash": "1.1.1",
"@types/trusted-types": "2.0.3", "@types/trusted-types": "2.0.3",
"@types/yargs": "16.0.11",
"@vercel/devlow-bench": "workspace:*", "@vercel/devlow-bench": "workspace:*",
"@vercel/kv": "3.0.0", "@vercel/kv": "3.0.0",
"@vercel/og": "0.7.2", "@vercel/og": "0.7.2",
......
...@@ -213,6 +213,9 @@ importers: ...@@ -213,6 +213,9 @@ importers:
'@types/trusted-types': '@types/trusted-types':
specifier: 2.0.3 specifier: 2.0.3
version: 2.0.3 version: 2.0.3
'@types/yargs':
specifier: 16.0.11
version: 16.0.11
'@vercel/devlow-bench': '@vercel/devlow-bench':
specifier: workspace:* specifier: workspace:*
version: link:turbopack/packages/devlow-bench version: link:turbopack/packages/devlow-bench
...@@ -6905,6 +6908,9 @@ packages: ...@@ -6905,6 +6908,9 @@ packages:
'@types/yargs-parser@21.0.0': '@types/yargs-parser@21.0.0':
resolution: {integrity: sha512-iO9ZQHkZxHn4mSakYV0vFHAVDyEOIJQrV2uZ06HxEPcx+mt8swXoZHIbaaJ2crJYFfErySgktuTZ3BeLz+XmFA==} resolution: {integrity: sha512-iO9ZQHkZxHn4mSakYV0vFHAVDyEOIJQrV2uZ06HxEPcx+mt8swXoZHIbaaJ2crJYFfErySgktuTZ3BeLz+XmFA==}
'@types/yargs@16.0.11':
resolution: {integrity: sha512-sbtvk8wDN+JvEdabmZExoW/HNr1cB7D/j4LT08rMiuikfA7m/JNJg7ATQcgzs34zHnoScDkY0ZRSl29Fkmk36g==}
'@types/yargs@17.0.10': '@types/yargs@17.0.10':
resolution: {integrity: sha512-gmEaFwpj/7f/ROdtIlci1R1VYU1J4j95m8T+Tj3iBgiBFKg1foE/PSl93bBd5T9LDXNPo8UlNN6W0qwD8O5OaA==} resolution: {integrity: sha512-gmEaFwpj/7f/ROdtIlci1R1VYU1J4j95m8T+Tj3iBgiBFKg1foE/PSl93bBd5T9LDXNPo8UlNN6W0qwD8O5OaA==}
...@@ -24370,6 +24376,10 @@ snapshots: ...@@ -24370,6 +24376,10 @@ snapshots:
'@types/yargs-parser@21.0.0': {} '@types/yargs-parser@21.0.0': {}
'@types/yargs@16.0.11':
dependencies:
'@types/yargs-parser': 21.0.0
'@types/yargs@17.0.10': '@types/yargs@17.0.10':
dependencies: dependencies:
'@types/yargs-parser': 21.0.0 '@types/yargs-parser': 21.0.0
...@@ -29,12 +29,10 @@ let argv = require('yargs/yargs')(process.argv.slice(2)) ...@@ -29,12 +29,10 @@ let argv = require('yargs/yargs')(process.argv.slice(2))
.string('g') .string('g')
.alias('g', 'group') .alias('g', 'group')
.number('c') .number('c')
.boolean('related')
.boolean('dry') .boolean('dry')
.boolean('print-tests') .boolean('print-tests')
.describe('print-tests', 'Prints the test files that will be run') .describe('print-tests', 'Prints the test files that will be run')
.boolean('local') .boolean('local')
.alias('r', 'related')
.alias('c', 'concurrency').argv .alias('c', 'concurrency').argv
function escapeRegexp(str) { function escapeRegexp(str) {
...@@ -236,7 +234,6 @@ async function main() { ...@@ -236,7 +234,6 @@ async function main() {
group: argv.group ?? false, group: argv.group ?? false,
testPattern: argv.testPattern ?? false, testPattern: argv.testPattern ?? false,
type: argv.type ?? false, type: argv.type ?? false,
related: argv.related ?? false,
retries: argv.retries ?? DEFAULT_NUM_RETRIES, retries: argv.retries ?? DEFAULT_NUM_RETRIES,
dry: argv.dry ?? false, dry: argv.dry ?? false,
local: argv.local ?? false, local: argv.local ?? false,
...@@ -288,20 +285,6 @@ async function main() { ...@@ -288,20 +285,6 @@ async function main() {
testPatternRegex = new RegExp(options.testPattern) testPatternRegex = new RegExp(options.testPattern)
} }
if (options.related) {
const { getRelatedTests } = await import('./scripts/run-related-test.mjs')
const tests = await getRelatedTests()
if (tests.length)
testPatternRegex = new RegExp(tests.map(escapeRegexp).join('|'))
if (testPatternRegex) {
console.log('Running related tests:', testPatternRegex.toString())
} else {
console.log('No matching related tests, exiting.')
process.exit(0)
}
}
tests = ( tests = (
await glob('**/*.test.{js,ts,tsx}', { await glob('**/*.test.{js,ts,tsx}', {
nodir: true, nodir: true,
...@@ -555,7 +538,6 @@ ${ENDGROUP}`) ...@@ -555,7 +538,6 @@ ${ENDGROUP}`)
// Format the output of junit report to include the test name // Format the output of junit report to include the test name
// For the debugging purpose to compare actual run list to the generated reports // For the debugging purpose to compare actual run list to the generated reports
// [NOTE]: This won't affect if junit reporter is not enabled // [NOTE]: This won't affect if junit reporter is not enabled
// @ts-expect-error .replaceAll() does exist. Follow-up why TS is not recognizing it
JEST_JUNIT_OUTPUT_NAME: test.file.replaceAll('/', '_'), JEST_JUNIT_OUTPUT_NAME: test.file.replaceAll('/', '_'),
// Specify suite name for the test to avoid unexpected merging across different env / grouped tests // Specify suite name for the test to avoid unexpected merging across different env / grouped tests
// This is not individual suites name (corresponding 'describe'), top level suite name which have redundant names by default // This is not individual suites name (corresponding 'describe'), top level suite name which have redundant names by default
......
...@@ -34,7 +34,7 @@ interface CliOptions { ...@@ -34,7 +34,7 @@ interface CliOptions {
const cliOptions = yargs(hideBin(process.argv)) const cliOptions = yargs(hideBin(process.argv))
.scriptName('pack-next') .scriptName('pack-next')
.command('$0') .command('$0', 'Pack Next.js for testing in external projects')
.option('js-build', { .option('js-build', {
type: 'boolean', type: 'boolean',
default: true, default: true,
...@@ -60,17 +60,18 @@ const cliOptions = yargs(hideBin(process.argv)) ...@@ -60,17 +60,18 @@ const cliOptions = yargs(hideBin(process.argv))
'none', 'none',
'strip', 'strip',
...(process.platform === 'linux' ? ['objcopy-zlib', 'objcopy-zstd'] : []), ...(process.platform === 'linux' ? ['objcopy-zlib', 'objcopy-zstd'] : []),
], ] as const,
}) })
.check((opts: CliOptions) => { .check((opts) => {
if (!opts.tar && (opts.compress ?? 'none') !== 'none') { const compress = opts.compress as CompressOpt | undefined
if (!opts.tar && (compress ?? 'none') !== 'none') {
throw new Error('--compress is only valid in combination with --tar') throw new Error('--compress is only valid in combination with --tar')
} }
return true return true
}) })
.middleware((opts: CliOptions) => { .middleware((opts) => {
if (opts.tar && process.platform === 'linux' && opts.compress == null) { if (opts.tar && process.platform === 'linux' && opts.compress == null) {
opts.compress = 'strip' ;(opts as CliOptions).compress = 'strip'
} }
}) })
.strict().argv as unknown as CliOptions .strict().argv as unknown as CliOptions
......
...@@ -11,9 +11,7 @@ import buildNative from './build-native.js' ...@@ -11,9 +11,7 @@ import buildNative from './build-native.js'
interface Options { interface Options {
project: string project: string
build: boolean build: boolean
noBuild: boolean 'build-native': boolean
buildNative: boolean
noNativeBuild: boolean
verbose: number verbose: number
_: string[] _: string[]
} }
...@@ -21,15 +19,15 @@ interface Options { ...@@ -21,15 +19,15 @@ interface Options {
// --- Parse command line arguments --- // --- Parse command line arguments ---
const argv = yargs(hideBin(process.argv)) const argv = yargs(hideBin(process.argv))
.scriptName('patch-next') .scriptName('patch-next')
.usage( .command(
'$0 <project> [..options]', '$0 <project> [options]',
'Patch Local Next.js packages to the target project directory', 'Patch local Next.js packages to the target project directory',
(yargs: any) => { (yargs) => {
yargs return yargs
.positional('project', { .positional('project', {
type: 'string', type: 'string',
describe: ': Target directory of the Next.js Project to patch', describe: 'Target directory of the Next.js project to patch',
nargs: 1, demandOption: true,
}) })
.example( .example(
'$0 ../my-app --no-build --no-build-native', '$0 ../my-app --no-build --no-build-native',
...@@ -69,7 +67,7 @@ const argv = yargs(hideBin(process.argv)) ...@@ -69,7 +67,7 @@ const argv = yargs(hideBin(process.argv))
const { const {
project: projectDir, project: projectDir,
build, build,
buildNative: buildNativeEnabled, 'build-native': buildNativeEnabled,
verbose: verboseLevel, verbose: verboseLevel,
_: buildNativeArgs, _: buildNativeArgs,
} = argv as Options } = argv as Options
......
...@@ -41,7 +41,7 @@ async function installDependencies(cwd, tmpDir) { ...@@ -41,7 +41,7 @@ async function installDependencies(cwd, tmpDir) {
* @param {object} [param0.packageJson] * @param {object} [param0.packageJson]
* @param {string} [param0.subDir] * @param {string} [param0.subDir]
* @param {boolean} [param0.keepRepoDir] * @param {boolean} [param0.keepRepoDir]
* @param {(span: import('@next/telemetry').Span, installDir: string) => Promise<void>} param0.beforeInstall * @param {(span: import('@next/telemetry').Span, installDir: string) => Promise<void>} [param0.beforeInstall]
* @returns {Promise<{installDir: string, pkgPaths: Map<string, string>, tmpRepoDir: string | undefined}>} * @returns {Promise<{installDir: string, pkgPaths: Map<string, string>, tmpRepoDir: string | undefined}>}
*/ */
async function createNextInstall({ async function createNextInstall({
......
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
} }
}, },
"include": [ "include": [
"run-tests.js",
"test/**/*.test.ts", "test/**/*.test.ts",
"test/**/*.test.tsx", "test/**/*.test.tsx",
"test/**/*.util.ts", "test/**/*.util.ts",
......
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