Repository navigation
test(electron): make dev-resolution tests self-sufficient on fresh clones - #689
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
|
Verified the current head end to end on a fresh clone and with a built dist. All three earlier review asks are addressed and the production change in app/electron/cli.ts is safe (gated on VITE_DEV_SERVER_URL, byte-identical resolution when the override is unset). One remaining issue: the new test at app/electron/cli.test.ts:88-96 asserts toBeNull() with the override unset, but the else branch resolves /dist/cli.js when it exists, so the suite fails 26/27 on any checkout that has run a build (fresh clone passes 27/27). The assertion is coupled to the absence of a gitignored build artifact and cannot be made environment-independent as written. Suggest dropping that test: the override-set cases at :58/:68/:143 already prove the new branch, and :98-105 covers the null path outside Vite dev. With that one change this is ready. |
…-root override The override-unset case resolved <repo>/dist/cli.js whenever a build had run, so the toBeNull() assertion depended on the absence of a gitignored artifact. The override-set tests already prove the new branch and the non-Vite test covers the null path.
|
Done in d5efe3b: dropped the environment-coupled test. The suite passes 26/26 both on a fresh clone and with a built dist/cli.js present (verified both locally). Branch coverage stays intact via the override-set cases at :58/:68 and the non-Vite null path at :98-105. |
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.