Skip to content

Commit 3ce71ad

Browse files
committed
chore: add test showing dart-sass @use
1 parent d0959b6 commit 3ce71ad

File tree

3 files changed

+69
-0
lines changed

3 files changed

+69
-0
lines changed
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import fs from "fs";
2+
import path from "path";
3+
import slash from "slash";
4+
5+
import { alerts } from "../../lib/core";
6+
import { main } from "../../lib/main";
7+
8+
describe("dart-sass", () => {
9+
let writeFileSyncSpy: jest.SpyInstance;
10+
11+
beforeEach(() => {
12+
// Only mock the writes, so the example files can still be read.
13+
writeFileSyncSpy = jest.spyOn(fs, "writeFileSync").mockImplementation();
14+
15+
// Avoid creating directories while running tests.
16+
jest.spyOn(fs, "mkdirSync").mockImplementation();
17+
18+
// Avoid console logs showing up.
19+
jest.spyOn(console, "log").mockImplementation();
20+
21+
jest.spyOn(alerts, "error").mockImplementation();
22+
});
23+
24+
afterEach(() => {
25+
writeFileSyncSpy.mockReset();
26+
});
27+
28+
test("@use support", async () => {
29+
const pattern = `${__dirname}`;
30+
31+
await main(pattern, {
32+
banner: "",
33+
watch: false,
34+
ignoreInitial: false,
35+
exportType: "named",
36+
exportTypeName: "ClassNames",
37+
exportTypeInterface: "Styles",
38+
listDifferent: false,
39+
ignore: [],
40+
implementation: "sass",
41+
quoteType: "single",
42+
updateStaleOnly: false,
43+
logLevel: "verbose",
44+
additionalData: "$global-red: red;",
45+
aliases: {
46+
"~fancy-import": "complex",
47+
"~another": "style",
48+
},
49+
aliasPrefixes: {
50+
"~": "nested-styles/",
51+
},
52+
});
53+
54+
expect(alerts.error).not.toHaveBeenCalled();
55+
expect(fs.writeFileSync).toBeCalledTimes(1);
56+
57+
const expectedDirname = slash(__dirname);
58+
expect(fs.writeFileSync).toBeCalledWith(
59+
`${expectedDirname}/use.scss.d.ts`,
60+
"export declare const foo: string;\n"
61+
);
62+
});
63+
});

__tests__/dart-sass/use.scss

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
@use "variables";
2+
3+
.foo {
4+
color: variables.$red;
5+
}

__tests__/dart-sass/variables.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
$red: red;

0 commit comments

Comments
 (0)