test(electron): make dev-resolution tests self-sufficient on fresh clones#689
test(electron): make dev-resolution tests self-sufficient on fresh clones#689ozymandiashh wants to merge 1 commit into
Conversation
iamtoruk
left a comment
There was a problem hiding this comment.
The core fixture is sound and the assertions got stronger (exact-path toBe instead of toMatch, real statSync and X_OK checks still exercised), but three things before this can merge.
-
It is stale against main: there is a content conflict in app/electron/cli.test.ts, and main gained a third fresh-clone failure after this branched (the resolveTarget test where the dev repo CLI beats the bundled CLI). As-is, Closes #681 would close the issue with one of its three symptoms still failing. Rebase and cover that test too.
-
The stub writes the real repo dist/cli.js, which is the published bin and exactly what npm run dev spawns. The snapshot-restore in afterEach is careful, but a SIGKILL or worker crash between the write and the restore leaves a developer's real build replaced by a 20-byte no-op, silently. Since there is no CI test job, this suite runs precisely on developer machines where that hurts. The cleaner shape already has precedent in this file: CODEBURN_PATH_DIRS exists for tests and advanced setups. A matching dev-root override env var lets the whole fixture live in the per-test tmpdir and deletes the snapshot machinery, the precondition check, and the crash window.
-
Please drop the beforeAll repo-scanning guard that globs test files and regex-scans imports. It misses import-star and indirect uses, will spuriously fail the suite when someone adds a legitimate isolated resolver test, and likely self-detects on Windows path separators. It is the needless-defensiveness pattern we strip in review.
Happy to re-review quickly, the direction is right.
…_ROOT Rework of the #681 fix per review: instead of stubbing the real repo dist/cli.js with snapshot-restore, the Vite-dev resolution branch gains a CODEBURN_DEV_REPO_ROOT override (matching the CODEBURN_PATH_DIRS precedent) so the whole fixture lives in a per-test tmpdir. With the env unset the resolution order is byte-identical to before. - covers all three fresh-clone failures on current main, including the resolveTarget dev-repo-beats-bundled case - deletes the snapshot-restore machinery, the parent-path precondition and the beforeAll repo-scanning guard - tests assert both override-set (tmpdir wins) and override-unset behavior Closes #681
|
Reworked per review, force-pushed as a fresh implementation on current main:
|
c832e85 to
044a062
Compare
Closes #681.
Problem
On a fresh clone (no
npm run build), the two Vite-developmentresolveCodeburnPathtests failed with.toMatch() expects to receive a string, but got object: the dev branch only returns the repo CLI path whendist/cli.jsexists and is executable.Fix
Per the issue's preferred direction, the tests now create the fixture they depend on:
fakeRepoDevCli()writes a stub executabledist/cli.jsat the exact path the productionsourceDevBinfallback resolves, and snapshot-restores any pre-existing real build artifact (content and mode restored byte-identically inafterEach; the fixture deletes only what it created, anddist/is kept when it was non-empty before).dist/cli.jscandidate (which resolution prefers under vitest's module layout) does not exist, naming the offending absolute path instead of failing later with a confusingtoBemismatch.Production code untouched.
Verification
npx vitest run app/electron/cli.test.tson a checkout with NOdist/cli.js: 19/19.dist/cli.js(distinct bytes, mode 0711): 19/19, then the sentinel is restored byte-identically with its exact mode (cmpclean).npx tsc --noEmitclean.