This repository has been archived by the owner on Aug 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathmain.test.ts
75 lines (63 loc) · 2.19 KB
/
main.test.ts
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
import fs from "fs";
import slash from "slash";
import { main } from "../lib/main";
describe("main", () => {
beforeEach(() => {
// Only mock the write, so the example files can still be read.
fs.writeFileSync = jest.fn();
console.log = jest.fn(); // avoid console logs showing up
});
test("generates types for all .less files when the pattern is a directory", async () => {
const pattern = `${__dirname}`;
await main(pattern, {
watch: false,
ignoreInitial: false,
exportType: "named",
exportTypeName: "ClassNames",
exportTypeInterface: "Styles",
listDifferent: false,
ignore: [],
quoteType: "single",
logLevel: "verbose"
});
const expectedDirname = slash(__dirname);
expect(fs.writeFileSync).toBeCalledTimes(5);
expect(fs.writeFileSync).toBeCalledWith(
`${expectedDirname}/complex.less.d.ts`,
"export const someStyles: string;\nexport const nestedClass: string;\nexport const nestedAnother: string;\n"
);
expect(fs.writeFileSync).toBeCalledWith(
`${expectedDirname}/style.less.d.ts`,
"export const someClass: string;\n"
);
});
test("generates types for all .less files and ignores files that match the ignore pattern", async () => {
const pattern = `${__dirname}`;
await main(pattern, {
watch: false,
ignoreInitial: false,
exportType: "named",
exportTypeName: "ClassNames",
exportTypeInterface: "Styles",
listDifferent: false,
ignore: ["**/style.less"],
quoteType: "single",
logLevel: "verbose"
});
expect(fs.writeFileSync).toBeCalledTimes(3);
const expectedDirname = slash(__dirname);
expect(fs.writeFileSync).toBeCalledWith(
`${expectedDirname}/complex.less.d.ts`,
"export const someStyles: string;\nexport const nestedClass: string;\nexport const nestedAnother: string;\n"
);
// Files that should match the ignore pattern.
expect(fs.writeFileSync).not.toBeCalledWith(
`${expectedDirname}/style.less.d.ts`,
expect.anything()
);
expect(fs.writeFileSync).not.toBeCalledWith(
`${expectedDirname}/nested-styles/style.less.d.ts`,
expect.anything()
);
});
});