Skip to content

Commit 089bb14

Browse files
committed
test(main): add test coverage for main 🎉 🎉
1 parent d2eb412 commit 089bb14

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

__tests__/main.test.ts

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import fs from "fs";
2+
3+
import { main } from "../lib/main";
4+
5+
describe("main", () => {
6+
beforeEach(() => {
7+
// Only mock the write, so the example files can still be read.
8+
fs.writeFileSync = jest.fn();
9+
console.log = jest.fn(); // avoid console logs showing up
10+
});
11+
12+
test("generates types for all .scss files when the pattern is a directory", async () => {
13+
const pattern = `${__dirname}`;
14+
15+
await main(pattern, {
16+
watch: false,
17+
exportType: "named"
18+
});
19+
20+
// Three files should match but one is empty
21+
expect(fs.writeFileSync).toBeCalledTimes(2);
22+
23+
expect(fs.writeFileSync).toBeCalledWith(
24+
`${__dirname}/complex.scss.d.ts`,
25+
"export const someStyles: string;\nexport const nestedClass: string;\nexport const nestedAnother: string;\n"
26+
);
27+
expect(fs.writeFileSync).toBeCalledWith(
28+
`${__dirname}/style.scss.d.ts`,
29+
"export const someClass: string;\n"
30+
);
31+
});
32+
});

lib/main.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import path from "path";
33

44
import { watch, MainOptions, generate } from "./core";
55

6-
export const main = (pattern: string, options: MainOptions): void => {
6+
export const main = async (pattern: string, options: MainOptions) => {
77
// When the provided pattern is a directory construct the proper glob to find
88
// all .scss files within that directory. Also, add the directory to the
99
// included paths so any imported with a path relative to the root of the
@@ -22,6 +22,6 @@ export const main = (pattern: string, options: MainOptions): void => {
2222
if (options.watch) {
2323
watch(pattern, options);
2424
} else {
25-
generate(pattern, options);
25+
await generate(pattern, options);
2626
}
2727
};

0 commit comments

Comments
 (0)