Skip to content

Commit 401f402

Browse files
Wxh16144sxzz
andauthoredMar 19, 2025··
fix!: improve debug logging format for command execution (#269)
* test: add unit test * fix: improve debug logging format for command execution * chore: update snap * chore: update * Update test/programmatic/runCli.spec.ts --------- Co-authored-by: Kevin Deng 三咲智子 <sxzz@sxzz.moe>
1 parent cb59993 commit 401f402

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed
 

‎src/runner.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,8 @@ export async function run(fn: Runner, args: string[], options: DetectOptions = {
149149
}
150150

151151
if (debug) {
152-
console.log(command)
152+
const commandStr = [command.command, ...command.args].join(' ')
153+
console.log(commandStr)
153154
return
154155
}
155156

‎test/programmatic/__snapshots__/runCli.spec.ts.snap

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
22

3+
exports[`debug mode > should return command results in plain text format 1`] = `"npm i @antfu/ni"`;
4+
35
exports[`lockfile > bun > na 1`] = `"bun"`;
46

57
exports[`lockfile > bun > na run foo 1`] = `"bun run foo"`;

‎test/programmatic/runCli.spec.ts

+12
Original file line numberDiff line numberDiff line change
@@ -96,3 +96,15 @@ fixtures.forEach(fixture => describe(fixture, () => agents.forEach(agent => desc
9696
expect(infoLog).not.toHaveBeenCalled()
9797
})
9898
}))))
99+
100+
// https://github.com/antfu-collective/ni/issues/266
101+
describe('debug mode', () => {
102+
beforeAll(() => basicLog.mockClear())
103+
104+
it('ni', runCliTest('lockfile', 'npm', parseNi, ['@antfu/ni', '?']))
105+
it('should return command results in plain text format', () => {
106+
expect(basicLog).toHaveBeenCalled()
107+
108+
expect(basicLog.mock.calls[0][0]).toMatchSnapshot()
109+
})
110+
})

0 commit comments

Comments
 (0)
Please sign in to comment.