-
-
Notifications
You must be signed in to change notification settings - Fork 0
fix: namespace dev condition to holdmytask-dev; correct + test devcheck #12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
2240dfd
fix: namespace dev condition to holdmytask-dev; correct + test devcheck
Shinrai c6427b1
refactor(devcheck): align to the @cldmv/uuid reference pattern
Shinrai d2c6896
fix(devcheck): keep condition-only trigger + detect execArgv; drop uuβ¦
Shinrai 2af4c55
fix(review): exact --conditions match, drop NODE_ENV override, keep mβ¦
Shinrai f3f39ef
fix: remove vestigial ./devcheck export (points at unshipped file)
Shinrai a959151
fix(review): parse --conditions as whole literal values (no comma/pipβ¦
Shinrai cc37aa2
docs(review): drop stale test.env reference in vitest config comment
Shinrai 4f96129
fix(review): advance scanner past consumed --conditions value; drop iβ¦
Shinrai ee9235b
docs(review): soften devcheck message - don't assert it's "loading frβ¦
Shinrai File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,159 @@ | ||
| /** | ||
| * @Project: @cldmv/holdmytask | ||
| * @Filename: /tests/DevCheck.test.vitest.mjs | ||
| * @Date: 2026-08-08T00:00:00-08:00 (1786233600) | ||
| * @Author: Nate Hyson <CLDMV> | ||
| * @Email: <Shinrai@users.noreply.github.com> | ||
| * ----- | ||
| * @Last modified by: Nate Hyson <CLDMV> (Shinrai@users.noreply.github.com) | ||
| * @Last modified time: 2026-08-08T00:00:00-08:00 (1786233600) | ||
| * ----- | ||
| * @Copyright: Copyright (c) 2013-2026 Catalyzed Motivation Inc. All rights reserved. | ||
| */ | ||
|
|
||
| import { test, expect, describe, beforeAll, afterAll } from "vitest"; | ||
| import { spawnSync } from "node:child_process"; | ||
| import { mkdtempSync, mkdirSync, copyFileSync, rmSync } from "node:fs"; | ||
| import { tmpdir } from "node:os"; | ||
| import path from "node:path"; | ||
| import { fileURLToPath } from "node:url"; | ||
|
|
||
| // devcheck.mjs resolves `src/` relative to its own file location and reads process.env | ||
| // / process.execArgv, so each case runs a COPY of it in a purpose-built fixture | ||
| // directory with a from-scratch env (only PATH), preventing the real CI environment | ||
| // this suite runs in from leaking `CI`/`GITHUB_ACTIONS`/`NODE_OPTIONS` into the | ||
| // subprocess. | ||
| const repoRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), ".."); | ||
| const devcheckSrc = path.join(repoRoot, "devcheck.mjs"); | ||
|
|
||
| let tmpRoot; | ||
| let counter = 0; | ||
|
|
||
| beforeAll(() => { | ||
| tmpRoot = mkdtempSync(path.join(tmpdir(), "holdmytask-devcheck-")); | ||
| }); | ||
|
|
||
| afterAll(() => { | ||
| if (tmpRoot) rmSync(tmpRoot, { recursive: true, force: true }); | ||
| }); | ||
|
|
||
| // Materialize a fixture dir with a copy of devcheck.mjs plus optional src/ and dist/, | ||
| // optionally nested under node_modules/<scope>/<pkg> to simulate an installed package. | ||
| function makeFixture({ src = true, dist = false, installed = false } = {}) { | ||
| const base = path.join(tmpRoot, `f${counter++}`); | ||
| const pkgDir = installed ? path.join(base, "node_modules", "@cldmv", "holdmytask") : path.join(base, "holdmytask"); | ||
| mkdirSync(pkgDir, { recursive: true }); | ||
| if (src) mkdirSync(path.join(pkgDir, "src"), { recursive: true }); | ||
| if (dist) mkdirSync(path.join(pkgDir, "dist"), { recursive: true }); | ||
| copyFileSync(devcheckSrc, path.join(pkgDir, "devcheck.mjs")); | ||
| return path.join(pkgDir, "devcheck.mjs"); | ||
| } | ||
|
|
||
| // nodeArgs are passed on the node CLI (i.e. become process.execArgv); env is a | ||
| // from-scratch environment (only PATH plus whatever is given). | ||
| function runDevcheck(fixtureOpts, { env = {}, nodeArgs = [] } = {}) { | ||
| const devcheck = makeFixture(fixtureOpts); | ||
| const result = spawnSync(process.execPath, [...nodeArgs, devcheck], { | ||
| env: { PATH: process.env.PATH, ...env }, | ||
| encoding: "utf8" | ||
| }); | ||
| return { status: result.status, stderr: result.stderr || "" }; | ||
| } | ||
|
|
||
| describe("devcheck", () => { | ||
| test("nags in a source checkout when the holdmytask-dev condition is not set", () => { | ||
| const { status, stderr } = runDevcheck({ src: true }); | ||
| expect(status).toBe(1); | ||
| expect(stderr).toContain("Development environment not properly configured"); | ||
| expect(stderr).toContain("--conditions=holdmytask-dev"); | ||
| }); | ||
|
|
||
| test("stays silent when the condition is set via NODE_OPTIONS", () => { | ||
| const { status, stderr } = runDevcheck({ src: true }, { env: { NODE_OPTIONS: "--conditions=holdmytask-dev" } }); | ||
| expect(status).toBe(0); | ||
| expect(stderr).toBe(""); | ||
| }); | ||
|
|
||
| test("stays silent when the condition is passed on the node CLI (execArgv, = form)", () => { | ||
| // vitest passes --conditions to workers this way, so devcheck must detect it here too. | ||
| const { status, stderr } = runDevcheck({ src: true }, { nodeArgs: ["--conditions=holdmytask-dev"] }); | ||
| expect(status).toBe(0); | ||
| expect(stderr).toBe(""); | ||
| }); | ||
|
|
||
| test("stays silent when the condition is passed space-separated (--conditions holdmytask-dev)", () => { | ||
| const { status, stderr } = runDevcheck({ src: true }, { nodeArgs: ["--conditions", "holdmytask-dev"] }); | ||
| expect(status).toBe(0); | ||
| expect(stderr).toBe(""); | ||
| }); | ||
|
|
||
| test("stays silent when holdmytask-dev is one of several repeated --conditions flags", () => { | ||
| const { status } = runDevcheck({ src: true }, { nodeArgs: ["--conditions=foo", "--conditions=holdmytask-dev"] }); | ||
| expect(status).toBe(0); | ||
| }); | ||
|
|
||
| test("stays silent via the -C short flag (Node's alias for --conditions)", () => { | ||
| // Node accepts `-C <value>` (space form) but rejects `-C=<value>`, so only the | ||
| // space form is a real input to detect. | ||
| const { status, stderr } = runDevcheck({ src: true }, { nodeArgs: ["-C", "holdmytask-dev"] }); | ||
| expect(status).toBe(0); | ||
| expect(stderr).toBe(""); | ||
| }); | ||
|
|
||
| test("NODE_ENV=development alone does NOT silence it (only the condition selects src/)", () => { | ||
| // Keying off NODE_ENV would be a false negative: dev env set but no condition means | ||
| // the package is still resolving to dist/, which is exactly what should be flagged. | ||
| const { status } = runDevcheck({ src: true }, { env: { NODE_ENV: "development" } }); | ||
| expect(status).toBe(1); | ||
| }); | ||
|
|
||
| test("STILL nags when dist/ has been built but the condition is not set", () => { | ||
| // A build must NOT silence the check: with src/ present the developer should be on | ||
| // src/ via the condition, not the stale dist/. | ||
| const { status } = runDevcheck({ src: true, dist: true }); | ||
| expect(status).toBe(1); | ||
| }); | ||
|
|
||
| test("does NOT accept a generic development condition (namespacing)", () => { | ||
| const { status } = runDevcheck({ src: true }, { nodeArgs: ["--conditions=development"] }); | ||
| expect(status).toBe(1); | ||
| }); | ||
|
|
||
| test("does NOT match a condition that merely contains 'holdmytask-dev' as a substring", () => { | ||
| // Exact-value match, not substring: --conditions=not-holdmytask-dev must NOT silence it. | ||
| const { status } = runDevcheck({ src: true }, { nodeArgs: ["--conditions=not-holdmytask-dev"] }); | ||
| expect(status).toBe(1); | ||
| }); | ||
|
|
||
| test("does NOT treat a comma-joined value as separate conditions", () => { | ||
| // Node does not split --conditions on `,`: `foo,holdmytask-dev,bar` is one literal | ||
| // condition, so holdmytask-dev is NOT enabled and devcheck must still nag. | ||
| const { status } = runDevcheck({ src: true }, { nodeArgs: ["--conditions=foo,holdmytask-dev,bar"] }); | ||
| expect(status).toBe(1); | ||
| }); | ||
|
|
||
| test("does NOT treat a pipe-joined value as separate conditions", () => { | ||
| // Likewise Node does not split on `|` (it's a valid condition character, e.g. | ||
| // Vite's `development|production`): `holdmytask-dev|production` does not enable it. | ||
| const { status } = runDevcheck({ src: true }, { nodeArgs: ["--conditions=holdmytask-dev|production"] }); | ||
| expect(status).toBe(1); | ||
| }); | ||
|
|
||
| test("skips in CI", () => { | ||
| const { status, stderr } = runDevcheck({ src: true }, { env: { CI: "true" } }); | ||
| expect(status).toBe(0); | ||
| expect(stderr).toBe(""); | ||
| }); | ||
|
|
||
| test("skips when installed as a scoped dependency (node_modules/@cldmv/holdmytask)", () => { | ||
| const { status, stderr } = runDevcheck({ src: true, installed: true }); | ||
| expect(status).toBe(0); | ||
| expect(stderr).toBe(""); | ||
| }); | ||
|
|
||
| test("does nothing when there is no src/ (published dist-only layout)", () => { | ||
| const { status, stderr } = runDevcheck({ src: false, dist: true }); | ||
| expect(status).toBe(0); | ||
| expect(stderr).toBe(""); | ||
| }); | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.