/
implementation-option.test.js
58 lines (50 loc) · 1.76 KB
/
implementation-option.test.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
/**
* @jest-environment node
*/
import {
compile,
getCodeFromBundle,
getCodeFromStylus,
getCompiler,
getErrors,
getWarnings,
} from "./helpers";
jest.setTimeout(30000);
describe("implementation option", () => {
it("should work", async () => {
const testId = "./basic.styl";
const compiler = getCompiler(testId, {
// eslint-disable-next-line global-require
implementation: require("stylus"),
});
const stats = await compile(compiler);
const codeFromBundle = getCodeFromBundle(stats, compiler);
const codeFromStylus = await getCodeFromStylus(testId);
expect(codeFromBundle.css).toBe(codeFromStylus.css);
expect(codeFromBundle.css).toMatchSnapshot("css");
expect(getWarnings(stats)).toMatchSnapshot("warnings");
expect(getErrors(stats)).toMatchSnapshot("errors");
});
it("should work when implementation option is string", async () => {
const testId = "./basic.styl";
const compiler = getCompiler(testId, {
implementation: require.resolve("stylus"),
});
const stats = await compile(compiler);
const codeFromBundle = getCodeFromBundle(stats, compiler);
const codeFromStylus = await getCodeFromStylus(testId);
expect(codeFromBundle.css).toBe(codeFromStylus.css);
expect(codeFromBundle.css).toMatchSnapshot("css");
expect(getWarnings(stats)).toMatchSnapshot("warnings");
expect(getErrors(stats)).toMatchSnapshot("errors");
});
it("should throw error when unresolved package", async () => {
const testId = "./basic.styl";
const compiler = getCompiler(testId, {
implementation: "unresolved",
});
const stats = await compile(compiler);
expect(getWarnings(stats)).toMatchSnapshot("warnings");
expect(getErrors(stats)).toMatchSnapshot("errors");
});
});