fix: --completion outputs wrong script name when run via Bun (#1826)

This commit is contained in:
Paul Goulpié
2026-04-16 09:50:35 +02:00
committed by GitHub
parent fe3304c37d
commit ac02922b9e
3 changed files with 18 additions and 3 deletions
+1 -1
View File
@@ -30,7 +30,7 @@ export async function handler (args: any, writeStreams: WriteStreams, jobs: Job[
let parser: Parser;
if (argv.completion) {
yargs(process.argv.slice(2)).showCompletionScript();
yargs(process.argv.slice(2)).scriptName("gitlab-ci-local").showCompletionScript();
return [];
}
@@ -0,0 +1,12 @@
import {execSync} from "child_process";
// Runs the CLI as a subprocess to reliably capture console.log output,
// which Bun implements natively and cannot be intercepted with vi.spyOn.
test("--completion outputs gitlab-ci-local as script name", () => {
const output = execSync("bun src/index.ts --completion", {encoding: "utf8", stdio: ["pipe", "pipe", "pipe"]});
expect(output).toContain("###-begin-gitlab-ci-local-completions-###");
expect(output).toContain("###-end-gitlab-ci-local-completions-###");
expect(output).toContain("gitlab-ci-local --get-yargs-completions");
expect(output).not.toMatch(/###-begin-(?!gitlab-ci-local)/);
});
+5 -2
View File
@@ -7,7 +7,10 @@ export default defineConfig({
extends: true,
test: {
name: "forks",
include: ["tests/test-cases/argv-cwd/**/*.test.ts"],
include: [
"tests/test-cases/argv-cwd/**/*.test.ts",
"tests/test-cases/completion/**/*.test.ts",
],
pool: "forks",
},
},
@@ -16,7 +19,7 @@ export default defineConfig({
test: {
name: "threads",
include: ["tests/**/*.test.ts"],
exclude: [...configDefaults.exclude, "**/.gitlab-ci-local*/**", "tests/test-cases/argv-cwd/**/*.test.ts"],
exclude: [...configDefaults.exclude, "**/.gitlab-ci-local*/**", "tests/test-cases/argv-cwd/**/*.test.ts", "tests/test-cases/completion/**/*.test.ts"],
pool: "threads",
},
},