-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.spec.js
91 lines (73 loc) · 2.4 KB
/
index.spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import shelljs from "shelljs";
import { commit, execOrFail, gitignore, logEnd, logStart } from "./helpers";
import { addPrettier } from "./prettier";
import { addStylelint } from "./stylelint";
import { execFileSync } from "child_process";
import { addEslint } from "./eslint/index.js";
import { addLefthook } from "./lefthook/index.js";
jest.mock("shelljs", () => ({
__esModule: true,
default: {
cd: jest.fn(),
},
}));
jest.mock("./eslint/index.js", () => ({
__esModule: true,
addEslint: jest.fn(),
}));
jest.mock("./helpers/index.js", () => ({
execOrFail: jest.fn(),
logEnd: jest.fn(),
logStart: jest.fn(),
commit: jest.fn(),
gitignore: jest.fn(),
}));
jest.mock("./lefthook/index.js", () => ({
addLefthook: jest.fn(),
}));
jest.mock("./prettier/index.js", () => ({
addPrettier: jest.fn(),
}));
jest.mock("./stylelint/index.js", () => ({
addStylelint: jest.fn(),
}));
jest.mock("child_process", () => ({
execFileSync: jest.fn(),
}));
describe("index.js", () => {
it("should pass the flow", async () => {
process.argv = ["node", "index.js", "test-app"];
await import("./index.js");
expect(logStart).toBeCalledWith("Scaffolding Angular application...");
expect(execFileSync).toBeCalledWith(
"npx",
["@angular/cli@18", "new", "test-app", "--style", "scss"],
{
stdio: "inherit",
},
);
expect(logEnd).toBeCalledWith("Angular application scaffolded");
expect(shelljs.cd).toBeCalledWith("test-app");
expect(addEslint).toBeCalled();
expect(commit).toBeCalledWith("Add ESLint");
expect(gitignore).toBeCalledWith(`# lint caches
.eslintcache`);
expect(commit).toBeCalledWith("Add .eslintcache to .gitignore");
expect(addPrettier).toHaveBeenCalled();
expect(commit).toBeCalledWith("Add Prettier");
expect(addStylelint).toHaveBeenCalled();
expect(commit).toBeCalledWith("Add Stylelint");
expect(gitignore).toBeCalledWith(`.stylelintcache`);
expect(commit).toBeCalledWith("Add .stylelintcache to .gitignore");
expect(execOrFail).toHaveBeenCalledWith({
cmd: "npm i -D svgo@3",
startMsg: "Installing svgo",
errorMsg: "Error during svgo installation",
endMsg: "svgo installed",
});
expect(commit).toBeCalledWith("Add SVGo");
expect(addLefthook).toHaveBeenCalled();
expect(commit).toBeCalledWith("Add Lefthook");
expect(logEnd).toHaveBeenCalledWith("Ready to work!");
});
});