Skip to content
Merged
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
19 changes: 19 additions & 0 deletions @commitlint/cli/src/cli.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,25 @@ test("should succeed when --cwd references an existing directory", async () => {
expect(result.exitCode).toBe(ExitCode.CommitlintDefault);
});

test("should resolve config from --cwd instead of the process working directory", async () => {
// The process runs in a fixture whose config requires type "outer",
// so "bar: baz" is rejected when that config is used.
const processCwd = await gitBootstrap("fixtures/outer-scope");
// --cwd points at a fixture whose config only forbids type "foo",
// so "bar: baz" is accepted when that config is used.
const targetCwd = await gitBootstrap("fixtures/default");

// Sanity check: without --cwd the process directory's config applies and rejects the message.
const withoutCwd = cli([], { cwd: processCwd })("bar: baz");
await withoutCwd;
expect(withoutCwd.exitCode).toBe(ExitCode.CommitlintErrorDefault);

// With --cwd config resolution is redirected to the target directory, which accepts the message.
const withCwd = cli(["--cwd", targetCwd], { cwd: processCwd })("bar: baz");
await withCwd;
expect(withCwd.exitCode).toBe(ExitCode.CommitlintDefault);
});

test("should throw when called without [input]", async () => {
const cwd = await gitBootstrap("fixtures/default");
const result = cli([], { cwd })();
Expand Down
Loading