withastro/astro · error · Error

Missing test glob pattern

Error message

Missing test glob pattern

What it means

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.

Source

Thrown at scripts/cmd/test.js:44

			// Test timeout in milliseconds (default: 30000ms)
			timeout: { type: 'string', alias: 't' },
			// Test setup file
			setup: { type: 'string', alias: 's' },
			// Test teardown file
			teardown: { type: 'string' },
			// Use tsx to run the tests,
			tsx: { type: 'boolean' },
			// Use Node.js experimental strip types to run TypeScript tests
			'strip-types': { type: 'boolean' },
			// Configures the test runner to exit the process once all known tests have finished executing even if the event loop would otherwise remain active
			'force-exit': { type: 'boolean' },
			// Test teardown file to include in the test files list
			'teardown-test': { type: 'string' },
		},
	});

	const pattern = args.positionals[1];
	if (!pattern) throw new Error('Missing test glob pattern');

	const files = await glob(pattern, {
		filesOnly: true,
		absolute: true,
		ignore: ['**/node_modules/**'],
	});

	if (args.values['teardown-test']) {
		files.push(path.resolve(args.values['teardown-test']));
	}

	// For some reason, the `only` option does not work and we need to explicitly set the CLI flag instead.
	// Node.js requires opt-in to run .only tests :(
	// https://nodejs.org/api/test.html#only-tests
	if (args.values.only) {
		process.env.NODE_OPTIONS ??= '';
		process.env.NODE_OPTIONS += ' --test-only';
	}

View on GitHub (pinned to d081033d5f)

Solutions

  1. Pass the test glob as a positional: e.g. `node scripts/cmd/test.js "test/**/*.test.js"`.
  2. If invoking via a package script, ensure the glob is appended (`pnpm -C packages/astro exec astro-scripts test "test/**/*.test.js"`).
  3. Quote the glob so the shell does not expand it — the runner does its own globbing.
  4. Confirm no leading flag consumed the glob slot.

Example fix

# before
node scripts/cmd/test.js
# error: Missing test glob pattern

# after
node scripts/cmd/test.js "test/**/*.test.js"
Defensive patterns

Strategy: validation

Validate before calling

const pattern = args.positionals[1];
if (!pattern || typeof pattern !== 'string') {
  console.error('Usage: test <glob>  e.g. test "test/**/*.test.js"');
  process.exit(1);
}
// (the script already throws; this just improves the message before calling glob)

Type guard

function isNonEmptyString(v: unknown): v is string {
  return typeof v === 'string' && v.length > 0;
}

Prevention

When it happens

Trigger: 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).

Common situations: 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.

Related errors


AI-assisted analysis of withastro/astro@d081033d5f (2026-08-12). Data as JSON: /api/errors/2f595c43427b9393. Report an issue: GitHub.