Fix `pnpm new-test` unit type generating no test file (#100641)
### What?
`pnpm new-test` with the `unit` type now generates a flat
`test/unit/<name>.test.ts` from a template, and nothing else.
### Why?
The `test` generator copied from `test/unit/test-template`, which didn't
exist. As a result, `pnpm new-test --args false my-unit unit` created no
test file at all, only `test/unit/my-unit/tsconfig.json` and
`next-env.d.ts`. That layout also doesn't match how unit tests are
organized: they are flat files in `test/unit/`. Since `AGENTS.md`
requires generating tests with `pnpm new-test`, the unit type needs to
work.
### How?
- Added a unit template, `test/unit/test-template/template.ts`. It's a
minimal Jest test that passes as generated, with a pointer on how to
import the code under test. A single `add` action renders it to
`test/unit/{{ toFileName name }}.test.ts`.
- Unlike the e2e templates, the file is deliberately not named
`*.test.ts` and has no spaces in its path. Otherwise the unit runner
would collect the template as a test, and on Windows `run-tests.js`
spawns jest through a shell that splits the Handlebars filename at its
spaces. That makes the `test unit windows` job pick up unrelated e2e
suites and fail.
- The generator treats unit tests as a separate case:
- `appDir` is ignored, so output never goes into `test/unit/app-dir/`.
- The `tsconfig.json`/`next-env.d.ts` steps are skipped, since those
only make sense for Next.js app fixtures.
- The e2e, production and development generation is unchanged.
- Documented the unit invocation in `AGENTS.md`.
### Verification
- `pnpm new-test --args false my-unit unit` and `pnpm new-test --args
true my-unit unit` both create only `test/unit/my-unit.test.ts`, and
`pnpm jest test/unit/my-unit.test.ts` passes.
- `node run-tests.js --type unit --dry` and `pnpm jest --listTests
test/unit/test-template` no longer pick up the template.
- `pnpm new-test --args true my-e2e e2e` and `pnpm new-test --args false
my-prod production` still generate their fixtures, test file,
`tsconfig.json` and `next-env.d.ts`.
<!-- NEXT_JS_LLM -->
<!-- fleet 813069b1-faf3-4c96-bd75-2be047fed0b3 -->
---------
Co-authored-by:
vercel-fleet-prod[bot] <318278635+vercel-fleet-prod[bot]@users.noreply.github.com>
Co-authored-by:
Tobias Koppers <1365881+sokra@users.noreply.github.com>
Showing
Please
register
or
sign in
to comment