Skip to content

Commit f670635

Browse files
test: more (#1026)
1 parent c8dae87 commit f670635

File tree

3 files changed

+50
-3
lines changed

3 files changed

+50
-3
lines changed

src/utils.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@ function getDefaultSassImplementation() {
1111

1212
try {
1313
require.resolve("sass");
14-
} catch (error) {
14+
} catch (ignoreError) {
1515
try {
1616
require.resolve("node-sass");
1717
sassImplPkg = "node-sass";
18-
} catch (error) {
18+
} catch (_ignoreError) {
1919
try {
2020
require.resolve("sass-embedded");
2121
sassImplPkg = "sass-embedded";
22-
} catch (ignoreError) {
22+
} catch (__ignoreError) {
2323
sassImplPkg = "sass";
2424
}
2525
}

test/__snapshots__/implementation-option.test.js.snap

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,3 +80,12 @@ Cannot find module 'unresolved' from 'src/utils.js'",
8080
`;
8181

8282
exports[`implementation option should throw error when unresolved package: warnings 1`] = `Array []`;
83+
84+
exports[`implementation option should try to load using valid order: errors 1`] = `
85+
Array [
86+
"ModuleError: Module Error (from ../src/cjs.js):
87+
Some error sass",
88+
]
89+
`;
90+
91+
exports[`implementation option should try to load using valid order: warnings 1`] = `Array []`;

test/implementation-option.test.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,44 @@ describe("implementation option", () => {
246246
expect(getErrors(stats)).toMatchSnapshot("errors");
247247
});
248248

249+
it("should try to load using valid order", async () => {
250+
jest.doMock("sass", () => {
251+
const error = new Error("Some error sass");
252+
253+
error.code = "MODULE_NOT_FOUND";
254+
error.stack = null;
255+
256+
throw error;
257+
});
258+
259+
jest.doMock("node-sass", () => {
260+
const error = new Error("Some error node-sass");
261+
262+
error.code = "MODULE_NOT_FOUND";
263+
error.stack = null;
264+
265+
throw error;
266+
});
267+
268+
jest.doMock("sass-embedded", () => {
269+
const error = new Error("Some error sass-embedded");
270+
271+
error.code = "MODULE_NOT_FOUND";
272+
error.stack = null;
273+
274+
throw error;
275+
});
276+
277+
const testId = getTestId("language", "scss");
278+
const options = {};
279+
280+
const compiler = getCompiler(testId, { loader: { options } });
281+
const stats = await compile(compiler);
282+
283+
expect(getWarnings(stats)).toMatchSnapshot("warnings");
284+
expect(getErrors(stats)).toMatchSnapshot("errors");
285+
});
286+
249287
it("should not swallow an error when trying to load a sass implementation", async () => {
250288
jest.doMock("node-sass", () => {
251289
const error = new Error("Some error");

0 commit comments

Comments
 (0)