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
|
import {
compile,
getCodeFromBundle,
getCodeFromLess,
getCompiler,
getErrors,
getWarnings,
} from "./helpers";
describe('"implementation" option', () => {
it("should work", async () => {
const testId = "./basic.less";
const compiler = getCompiler(testId, {
// eslint-disable-next-line global-require
implementation: require("less"),
});
const stats = await compile(compiler);
const codeFromBundle = getCodeFromBundle(stats, compiler);
const codeFromLess = await getCodeFromLess(testId);
expect(codeFromBundle.css).toBe(codeFromLess.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.less";
const compiler = getCompiler(testId, {
implementation: require.resolve("less"),
});
const stats = await compile(compiler);
const codeFromBundle = getCodeFromBundle(stats, compiler);
const codeFromLess = await getCodeFromLess(testId);
expect(codeFromBundle.css).toBe(codeFromLess.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.less";
const compiler = getCompiler(testId, {
implementation: "unresolved",
});
const stats = await compile(compiler);
expect(getWarnings(stats)).toMatchSnapshot("warnings");
expect(getErrors(stats)).toMatchSnapshot("errors");
});
});
|