Skip to content

Commit

Permalink
test: more (#1026)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-akait authored Feb 15, 2022
1 parent c8dae87 commit f670635
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ function getDefaultSassImplementation() {

try {
require.resolve("sass");
} catch (error) {
} catch (ignoreError) {
try {
require.resolve("node-sass");
sassImplPkg = "node-sass";
} catch (error) {
} catch (_ignoreError) {
try {
require.resolve("sass-embedded");
sassImplPkg = "sass-embedded";
} catch (ignoreError) {
} catch (__ignoreError) {
sassImplPkg = "sass";
}
}
Expand Down
9 changes: 9 additions & 0 deletions test/__snapshots__/implementation-option.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,12 @@ Cannot find module 'unresolved' from 'src/utils.js'",
`;

exports[`implementation option should throw error when unresolved package: warnings 1`] = `Array []`;

exports[`implementation option should try to load using valid order: errors 1`] = `
Array [
"ModuleError: Module Error (from ../src/cjs.js):
Some error sass",
]
`;

exports[`implementation option should try to load using valid order: warnings 1`] = `Array []`;
38 changes: 38 additions & 0 deletions test/implementation-option.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,44 @@ describe("implementation option", () => {
expect(getErrors(stats)).toMatchSnapshot("errors");
});

it("should try to load using valid order", async () => {
jest.doMock("sass", () => {
const error = new Error("Some error sass");

error.code = "MODULE_NOT_FOUND";
error.stack = null;

throw error;
});

jest.doMock("node-sass", () => {
const error = new Error("Some error node-sass");

error.code = "MODULE_NOT_FOUND";
error.stack = null;

throw error;
});

jest.doMock("sass-embedded", () => {
const error = new Error("Some error sass-embedded");

error.code = "MODULE_NOT_FOUND";
error.stack = null;

throw error;
});

const testId = getTestId("language", "scss");
const options = {};

const compiler = getCompiler(testId, { loader: { options } });
const stats = await compile(compiler);

expect(getWarnings(stats)).toMatchSnapshot("warnings");
expect(getErrors(stats)).toMatchSnapshot("errors");
});

it("should not swallow an error when trying to load a sass implementation", async () => {
jest.doMock("node-sass", () => {
const error = new Error("Some error");
Expand Down

0 comments on commit f670635

Please sign in to comment.