Skip to content

Commit

Permalink
test(cli): precises (and denoises) e2e test emitting to stdout
Browse files Browse the repository at this point in the history
  • Loading branch information
sverweij committed Dec 29, 2023
1 parent daa8a1e commit fbba9ea
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions test/cli/index.spec.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { readFileSync, unlinkSync } from "node:fs";
import { doesNotThrow, equal, throws } from "node:assert/strict";
import { doesNotThrow, equal, throws, match } from "node:assert/strict";
// path.posix instead of path because otherwise on win32 the resulting
// outputTo would contain \\ instead of / which for this unit test doesn't matter
import { join, posix as path } from "node:path";
Expand Down Expand Up @@ -239,12 +239,14 @@ describe("[E] cli/index", () => {

describe("[E] specials", () => {
let lChalkLevel = chalk.level;
const lOriginalStdoutWrite = process.stdout.write;

before("disable chalk coloring", () => {
chalk.level = 0;
});
after("enable chalk coloring again", () => {
chalk.level = lChalkLevel;
process.stdout.write = lOriginalStdoutWrite;
});
it("dependency-cruises multiple files and folders in one go", async () => {
const lOutputFileName = "multiple-in-one-go.json";
Expand Down Expand Up @@ -341,11 +343,17 @@ describe("[E] cli/index", () => {
});

it("dependency-cruise test/cli/__fixtures__ without rules will report no dependency violations on stdout", async () => {
const lExitCode = await cli(["test/cli/__fixtures__"], null, {
stdout: new UnCalledWritableTestStream(),
stderr: new WritableTestStream(/no dependency violations found/),
});

let lFeedback = "";
process.stdout.write = (pChunk) => {
lFeedback = pChunk;
};
const lExitCode = await cli(["test/cli/__fixtures__"]);
process.stdout.write = lOriginalStdoutWrite;

match(
lFeedback,
/no dependency violations found \(102 modules, 57 dependencies cruised\)/,
);
equal(lExitCode, 0);
});

Expand Down

0 comments on commit fbba9ea

Please sign in to comment.