{"record":{"id":"2f595c43427b9393","repo":"withastro/astro","slug":"missing-test-glob-pattern","errorCode":null,"errorMessage":"Missing test glob pattern","messagePattern":"Missing test glob pattern","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"scripts/cmd/test.js","lineNumber":44,"sourceCode":"\t\t\t// Test timeout in milliseconds (default: 30000ms)\n\t\t\ttimeout: { type: 'string', alias: 't' },\n\t\t\t// Test setup file\n\t\t\tsetup: { type: 'string', alias: 's' },\n\t\t\t// Test teardown file\n\t\t\tteardown: { type: 'string' },\n\t\t\t// Use tsx to run the tests,\n\t\t\ttsx: { type: 'boolean' },\n\t\t\t// Use Node.js experimental strip types to run TypeScript tests\n\t\t\t'strip-types': { type: 'boolean' },\n\t\t\t// Configures the test runner to exit the process once all known tests have finished executing even if the event loop would otherwise remain active\n\t\t\t'force-exit': { type: 'boolean' },\n\t\t\t// Test teardown file to include in the test files list\n\t\t\t'teardown-test': { type: 'string' },\n\t\t},\n\t});\n\n\tconst pattern = args.positionals[1];\n\tif (!pattern) throw new Error('Missing test glob pattern');\n\n\tconst files = await glob(pattern, {\n\t\tfilesOnly: true,\n\t\tabsolute: true,\n\t\tignore: ['**/node_modules/**'],\n\t});\n\n\tif (args.values['teardown-test']) {\n\t\tfiles.push(path.resolve(args.values['teardown-test']));\n\t}\n\n\t// For some reason, the `only` option does not work and we need to explicitly set the CLI flag instead.\n\t// Node.js requires opt-in to run .only tests :(\n\t// https://nodejs.org/api/test.html#only-tests\n\tif (args.values.only) {\n\t\tprocess.env.NODE_OPTIONS ??= '';\n\t\tprocess.env.NODE_OPTIONS += ' --test-only';\n\t}","sourceCodeStart":26,"sourceCodeEnd":62,"githubUrl":"https://github.com/withastro/astro/blob/d081033d5fe8e8a68c4bbbad4af9d2deb9c74bca/scripts/cmd/test.js#L26-L62","documentation":"Thrown by the repo's test runner CLI (`scripts/cmd/test.js`) when the second positional argument — the glob pattern selecting which test files to run — is missing. The script parses argv with `util.parseArgs`, reads `args.positionals[1]` as the pattern, and refuses to proceed with an empty glob because that would either match nothing or, depending on the globber, match the entire tree.","triggerScenarios":"Invoking the test command without a glob, e.g. `node scripts/cmd/test.js` or `pnpm test` with no path argument; passing the pattern as a flag (`--pattern`) instead of a positional; argument order shifted so the glob landed in `positionals[0]` (the command name slot).","commonSituations":"A developer types `pnpm test` expecting a default suite but this script requires an explicit glob; a wrapper script/IDE task forgets to append the glob; refactoring of argv parsing changes positional indices.","solutions":["Pass the test glob as a positional: e.g. `node scripts/cmd/test.js \"test/**/*.test.js\"`.","If invoking via a package script, ensure the glob is appended (`pnpm -C packages/astro exec astro-scripts test \"test/**/*.test.js\"`).","Quote the glob so the shell does not expand it — the runner does its own globbing.","Confirm no leading flag consumed the glob slot."],"exampleFix":"# before\nnode scripts/cmd/test.js\n# error: Missing test glob pattern\n\n# after\nnode scripts/cmd/test.js \"test/**/*.test.js\"","handlingStrategy":"validation","validationCode":"const pattern = args.positionals[1];\nif (!pattern || typeof pattern !== 'string') {\n  console.error('Usage: test <glob>  e.g. test \"test/**/*.test.js\"');\n  process.exit(1);\n}\n// (the script already throws; this just improves the message before calling glob)","typeGuard":"function isNonEmptyString(v: unknown): v is string {\n  return typeof v === 'string' && v.length > 0;\n}","tryCatchPattern":null,"preventionTips":["Always pass an explicit, quoted glob when invoking the test script.","Document the expected argv layout in the script's `--help`.","In npm/pnpm package scripts, append the glob so wrappers do not forget it."],"tags":["cli","test-runner","argument-validation","monorepo"],"backgroundTag":null,"analyzedSha":"d081033d5fe8e8a68c4bbbad4af9d2deb9c74bca","analyzedAt":"2026-08-12T13:37:29.035Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}