Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
"tsdown": "^0.22.14",
"tsdown-preset-sxzz": "^0.7.0",
"typescript": "^6.0.3",
"vite-node": "^6.0.0",
"vitest": "^4.1.11"
},
"husky": {
Expand Down
29 changes: 29 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 28 additions & 0 deletions tests/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,34 @@ snapshotOutput({
args: ['build'],
})

test('parse() with no explicit argv under an alternative runtime (vite-node)', async () => {
// Regression test for https://github.com/cacjs/cac/issues/158.
// `.parse()` with no explicit argv falls back to `runtimeProcessArgs`
// (captured from `process.argv` in src/runtime.ts). Every other test in
// this file exercises that fallback only via a plain `node` subprocess;
// this runs the same fixture through vite-node, which executes the file
// in its own SSR/module context, to confirm the fallback still resolves
// to the real CLI args (not vite-node's own) when invoked as
// `vite-node basic-usage.ts foo bar --type ok command`.
const { stdout } = await x('npx', [
'vite-node',
example('basic-usage.ts'),
'foo',
'bar',
'--type',
'ok',
'command',
])

expect(JSON.parse(stdout)).toEqual({
args: ['foo', 'bar', 'command'],
options: {
'--': [],
type: 'ok',
},
})
})

test('negated option', () => {
const cli = cac()

Expand Down