Skip to content

Commit 51a2d7f

Browse files
escapedcatclaude
andauthored
test(cli): verify --cwd redirects config resolution (#997) (#4796)
Adds a CLI test asserting that --cwd changes where config is resolved from, not just that the directory is valid: the same message is rejected by the process directory's config but accepted once --cwd points at a directory whose config allows it. Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 8069048 commit 51a2d7f

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

@commitlint/cli/src/cli.test.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,25 @@ test("should succeed when --cwd references an existing directory", async () => {
7272
expect(result.exitCode).toBe(ExitCode.CommitlintDefault);
7373
});
7474

75+
test("should resolve config from --cwd instead of the process working directory", async () => {
76+
// The process runs in a fixture whose config requires type "outer",
77+
// so "bar: baz" is rejected when that config is used.
78+
const processCwd = await gitBootstrap("fixtures/outer-scope");
79+
// --cwd points at a fixture whose config only forbids type "foo",
80+
// so "bar: baz" is accepted when that config is used.
81+
const targetCwd = await gitBootstrap("fixtures/default");
82+
83+
// Sanity check: without --cwd the process directory's config applies and rejects the message.
84+
const withoutCwd = cli([], { cwd: processCwd })("bar: baz");
85+
await withoutCwd;
86+
expect(withoutCwd.exitCode).toBe(ExitCode.CommitlintErrorDefault);
87+
88+
// With --cwd config resolution is redirected to the target directory, which accepts the message.
89+
const withCwd = cli(["--cwd", targetCwd], { cwd: processCwd })("bar: baz");
90+
await withCwd;
91+
expect(withCwd.exitCode).toBe(ExitCode.CommitlintDefault);
92+
});
93+
7594
test("should throw when called without [input]", async () => {
7695
const cwd = await gitBootstrap("fixtures/default");
7796
const result = cli([], { cwd })();

0 commit comments

Comments
 (0)