|
| 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 | +}); |
0 commit comments