Skip to content

Commit 7a6b58b

Browse files
committed
refactor(create): address round-2 simplify review
Four small quality wins plus the big one — shared snap-test helper: - `packages/tools/src/snap-test.ts`: expose `SNAP_CASES_DIR` as an env var pointing at the source cases directory. Lets fixtures reference shared helper scripts under `<casesDir>/.shared/` without duplicating them into every fixture. The dot-prefix keeps the shared dir invisible to the test iterator (which already skips dotfiles). - Collapse the 4 byte-identical `mock-server.mjs` copies (89 LOC each) into a single `packages/cli/snap-tests/.shared/mock-npm-registry.mjs`. Each fixture's `steps.json` now invokes it via `node $SNAP_CASES_DIR/.shared/mock-npm-registry.mjs -- vp create ...`. Bug fixes to the mock registry now apply to all consumers at once. - `org-picker.ts`: drop the hard-coded "inside a monorepo" message from the empty-filter branch. Move the context-specific info note to the caller (`org-resolve.ts`), gated on the exact predicate that produced the empty filter. Keeps the picker context-agnostic so future filters don't need to update picker internals. - `templates/bundled.ts`: drop the "@org/create package" presumption from the ENOENT error message. The executor is generic — it only knows about `localPath` — so the message follows suit. - `org-picker.spec.ts`: simplify the escape-hatch round-trip assertion by dropping the externally-captured `escapeValue` variable. The mockImplementation return value is sufficient on its own. Snaps regenerated (only the command line in the first row changed to reference the shared helper via $SNAP_CASES_DIR); output bodies byte-identical; full unit suite still 263/263. Net: -267 LOC across 17 files.
1 parent ea02286 commit 7a6b58b

17 files changed

Lines changed: 32 additions & 299 deletions

File tree

packages/cli/snap-tests/create-org-bundled/mock-server.mjs renamed to packages/cli/snap-tests/.shared/mock-npm-registry.mjs

File renamed without changes.

packages/cli/snap-tests/create-org-bundled/snap.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
> node mock-server.mjs -- vp create @your-org/demo --no-interactive --directory my-demo-app # bundled template: extract tarball, copy subdir
1+
> node $SNAP_CASES_DIR/.shared/mock-npm-registry.mjs -- vp create @your-org/demo --no-interactive --directory my-demo-app # bundled template: extract tarball, copy subdir
22

33
selected 'demo' from @your-org/create
44
◇ Scaffolded my-demo-app

packages/cli/snap-tests/create-org-bundled/steps.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"commands": [
3-
"node mock-server.mjs -- vp create @your-org/demo --no-interactive --directory my-demo-app # bundled template: extract tarball, copy subdir",
3+
"node $SNAP_CASES_DIR/.shared/mock-npm-registry.mjs -- vp create @your-org/demo --no-interactive --directory my-demo-app # bundled template: extract tarball, copy subdir",
44
"cat my-demo-app/package.json # verify package.json name was rewritten",
55
"cat my-demo-app/src/index.ts # verify bundled source copied",
66
"ls my-demo-app/README.md # verify README copied"

packages/cli/snap-tests/create-org-invalid-manifest/mock-server.mjs

Lines changed: 0 additions & 89 deletions
This file was deleted.

packages/cli/snap-tests/create-org-invalid-manifest/snap.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
[1]> node mock-server.mjs -- vp create @your-org --no-interactive # invalid manifest -> schema error
1+
[1]> node $SNAP_CASES_DIR/.shared/mock-npm-registry.mjs -- vp create @your-org --no-interactive # invalid manifest -> schema error
22

33
@your-org/create: vp.templates[0].template must be a non-empty string
44
Failed to resolve org template manifest
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"commands": [
3-
"node mock-server.mjs -- vp create @your-org --no-interactive # invalid manifest -> schema error"
3+
"node $SNAP_CASES_DIR/.shared/mock-npm-registry.mjs -- vp create @your-org --no-interactive # invalid manifest -> schema error"
44
]
55
}

packages/cli/snap-tests/create-org-monorepo-filter/mock-server.mjs

Lines changed: 0 additions & 89 deletions
This file was deleted.

packages/cli/snap-tests/create-org-monorepo-filter/snap.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
[1]> node mock-server.mjs -- vp create @your-org --no-interactive # inside monorepo, hides monorepo:true entries + shows omitted footer
1+
[1]> node $SNAP_CASES_DIR/.shared/mock-npm-registry.mjs -- vp create @your-org --no-interactive # inside monorepo, hides monorepo:true entries + shows omitted footer
22
error: vp create @your-org requires a template selection in non-interactive mode.
33

44
available templates from @your-org/create:
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"commands": [
3-
"node mock-server.mjs -- vp create @your-org --no-interactive # inside monorepo, hides monorepo:true entries + shows omitted footer"
3+
"node $SNAP_CASES_DIR/.shared/mock-npm-registry.mjs -- vp create @your-org --no-interactive # inside monorepo, hides monorepo:true entries + shows omitted footer"
44
]
55
}

packages/cli/snap-tests/create-org-no-interactive-error/mock-server.mjs

Lines changed: 0 additions & 89 deletions
This file was deleted.

0 commit comments

Comments
 (0)