Repository navigation
feat: make Jest discovery cwd-aware - #28
Conversation
Jest mounted the workspace root and ran one `npx jest` over it, which gives a multi-project workspace no definition of which projects a run should cover, and no way to act on the project you are actually in. `projects` now delegates discovery to `polyfill.findConfigDirs`, per the convention in dagger/dagger#13688: every directory holding a `jest.config.*` at or below the client cwd, plus the nearest enclosing project as a `..`-relative path when the cwd holds no config of its own. A `jest` key in package.json also configures Jest, but package.json marks every npm package, so it is not a discovery marker. `testAll` becomes the automatic check and runs every discovered project. A cwd holding no config of its own sits inside its enclosing project, so that project runs too; scoping a run to a single project is done by entering it. `test`, `list` and `source` take a cwd-relative project path and a Workspace argument; the workspace can no longer be a field on the module object, which also drops the `source` toolchain customization from the README. Signed-off-by: Tom Chauveau <[email protected]>
1febd7d to
353bf52
Compare
|
Cross-posting a limitation found while reviewing the vitest equivalent (dagger/vitest#17, thread) — it reproduces here identically, since Scratch monorepo: Two independent failures running 1. Dependency root. 2. Config inheritance. Giving They don't collapse into one fix — in a pnpm/yarn workspace each package has its own Direction under discussion for the follow-up is to mount the dagger workspace root and set Worth checking whether this belongs in Not addressing it in this PR; it's correct for self-contained projects, which is what the checks cover. |
Implements the cwd-aware config discovery convention from dagger/dagger#13688 for the Jest toolchain. Port of dagger/vitest#17.
Before
The constructor flattened the workspace to
ws.directory("/")andtestran a singlenpx jestat its root. A workspace with several Jest projects had no definition of which projects a run covers, and no way to act on the project you are in.After
projects(ws)delegates topolyfill.findConfigDirsforjest.config.{js,mjs,cjs,ts,mts,cts,json}, excludingnode_modules. Paths are cwd-relative:.,sub..A
jestkey inpackage.jsonalso configures Jest, butpackage.jsonmarks every npm package, so it is deliberately not a discovery marker. Projects configured that way are not discovered; they can still be run explicitly withtest --path.testAll(ws)is the new automatic@checkand runs all discovered projects: a cwd holding no config sits inside its enclosing project, so that project runs too. Scoping a run to one project is done by entering it.testkeeps its behavior, loses@check, and gains a cwd-relativepath(default.);listandsourcelikewise.Workspacecan no longer be stored as a field on a module object, so it moves from the constructor to a function argument on each entry point. That also removes thesourcetoolchain customization from the README — it targeted a constructor argument that no longer exists.Behavior
Given two sibling projects under a config-less root:
from the root
projectsreturnsa,b; fromait returns..Adding a root project does not change the view from below — the config in the cwd shadows the enclosing one:
from the root:
.,a,b; froma:.; fromb:..The
..case appears only when the cwd holds no config:from
work:..,app, anddagger checkruns both.Tests
Five new e2e checks build synthetic workspaces from copies of
kpenfound/demo-react-app(.gitand itsdagger.jsonstripped) and enter them at a chosen cwd:sibling-discovery-check,nested-discovery-check,ancestor-discovery-check— the three layouts above, plus that the returned..resolves back to the enclosing projectdescendant-scope-check— runs real Jest: a failure planted inb/srcis seen from the root and not froma, and a failure planted ina/srcis seen fromaancestor-scope-check— a failure planted in the enclosing project is seen from the config-lessworktest-demo-appis unchanged apart from callingtestAll.Also verified against a real client cwd (not
asWorkspace(cwd:)) in a scratch workspace: root →a b . work/app,a/→.,work/→.. app, anddagger checkfromwork/passes.Note
engineVersionstays atv0.20.6; nothing here needs a newer engine. The e2e module keeps its ownv1.0.0-beta.3, which is whatDirectory.asWorkspace(cwd:)requires.