UNPKG

1.44 kBPlain TextView Raw
1import * as fs from "fs-extra";
2import * as path from "path";
3import execa = require("execa");
4import { setupFixture } from "backfill-utils-test";
5
6import { findPathToBackfill } from "./helper";
7import { sideEffectWarningString, noSideEffectString } from "../audit";
8
9describe("Audit", () => {
10 let pathToBackfill: string;
11 let backfillOutput: execa.ExecaReturnValue | undefined;
12
13 beforeAll(async () => {
14 pathToBackfill = await findPathToBackfill();
15 });
16
17 beforeEach(async () => {
18 backfillOutput = undefined;
19
20 const monorepoPath = await setupFixture("monorepo");
21
22 // Create a .git folder to help `--audit` identify the boundaries of the repo
23 fs.mkdirpSync(".git");
24
25 const packageAPath = path.join(monorepoPath, "packages", "package-a");
26 process.chdir(packageAPath);
27 });
28
29 it("correctly returns success when there are no side-effects", async () => {
30 backfillOutput = await execa(
31 "node",
32 [pathToBackfill, "--audit", "npm run compile"],
33 { all: true }
34 );
35
36 expect(backfillOutput.all).toMatch(noSideEffectString);
37 });
38
39 it("correctly warns about side-effects", async () => {
40 backfillOutput = await execa(
41 "node",
42 [pathToBackfill, "--audit", "npm run compile && npm run side-effect"],
43 { all: true }
44 );
45
46 expect(backfillOutput.all).toMatch(sideEffectWarningString);
47 expect(backfillOutput.all).toMatch(path.join("packages", "DONE"));
48 });
49});