Skip to content
Merged
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
2 changes: 1 addition & 1 deletion src/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 [];
}

Expand Down
12 changes: 12 additions & 0 deletions tests/test-cases/completion/integration.test.ts
Original file line number Diff line number Diff line change
@@ -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)/);
});
7 changes: 5 additions & 2 deletions vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
},
Expand All @@ -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",
},
},
Expand Down
Loading