Skip to content

Commit 9db2543

Browse files
test: added
1 parent ad5b193 commit 9db2543

File tree

4 files changed

+72
-2
lines changed

4 files changed

+72
-2
lines changed

package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
],
4444
"peerDependencies": {
4545
"@rspack/core": "0.x || 1.x",
46-
"node-sass": "^4.0.0 || ^5.0.0 || ^6.0.0 || ^7.0.0 || ^8.0.0 || ^9.0.0",
4746
"sass": "^1.3.0",
4847
"sass-embedded": "*",
4948
"webpack": "^5.0.0"
@@ -96,7 +95,6 @@
9695
"lint-staged": "^15.2.0",
9796
"material-components-web": "^9.0.0",
9897
"memfs": "^4.7.7",
99-
"node-sass": "^9.0.0",
10098
"node-sass-glob-importer": "^5.3.2",
10199
"npm-run-all": "^4.1.5",
102100
"prettier": "^3.2.2",

test/__snapshots__/implementation-option.test.js.no-node-sass.snap

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ exports[`implementation option not specify: errors 1`] = `[]`;
4848

4949
exports[`implementation option not specify: warnings 1`] = `[]`;
5050

51+
exports[`implementation option should dispose redundant compilers for \`modern-compiler\`: errors 1`] = `[]`;
52+
53+
exports[`implementation option should dispose redundant compilers for \`modern-compiler\`: warnings 1`] = `[]`;
54+
5155
exports[`implementation option should not swallow an error when trying to load a sass implementation: errors 1`] = `
5256
[
5357
"ModuleBuildError: Module build failed (from ../src/cjs.js):

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ exports[`implementation option not specify: errors 1`] = `[]`;
5252

5353
exports[`implementation option not specify: warnings 1`] = `[]`;
5454

55+
exports[`implementation option should dispose redundant compilers for \`modern-compiler\`: errors 1`] = `[]`;
56+
57+
exports[`implementation option should dispose redundant compilers for \`modern-compiler\`: warnings 1`] = `[]`;
58+
5559
exports[`implementation option should not swallow an error when trying to load a sass implementation: errors 1`] = `
5660
[
5761
"ModuleBuildError: Module build failed (from ../src/cjs.js):

test/implementation-option.test.js

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,70 @@ describe("implementation option", () => {
398398
await close(compiler);
399399
});
400400

401+
it("should dispose redundant compilers for `modern-compiler`", async () => {
402+
sassEmbeddedCompilerSpies.mockRestore();
403+
404+
let isInRace = false;
405+
406+
let firstDisposeSpy;
407+
let secondDisposeSpy;
408+
409+
const actualFn = sassEmbedded.initAsyncCompiler.bind(sassEmbedded);
410+
411+
const initSpy = jest
412+
.spyOn(sassEmbedded, "initAsyncCompiler")
413+
.mockImplementation(async () => {
414+
const compiler = await actualFn();
415+
416+
if (!isInRace) {
417+
firstDisposeSpy = jest.spyOn(compiler, "dispose");
418+
isInRace = true;
419+
420+
return new Promise((resolve) => {
421+
const interval = setInterval(() => {
422+
if (!isInRace) {
423+
clearInterval(interval);
424+
resolve(compiler);
425+
}
426+
});
427+
});
428+
}
429+
430+
isInRace = false;
431+
secondDisposeSpy = jest.spyOn(compiler, "dispose");
432+
433+
return compiler;
434+
});
435+
436+
const testId1 = getTestId("language", "scss");
437+
const testId2 = getTestId("language", "sass");
438+
const options = { api: "modern-compiler" };
439+
440+
// eslint-disable-next-line no-undefined
441+
const compiler = getCompiler(undefined, {
442+
entry: {
443+
one: `./${testId1}`,
444+
two: `./${testId2}`,
445+
},
446+
loader: { options },
447+
});
448+
const stats = await compile(compiler);
449+
450+
expect(getWarnings(stats)).toMatchSnapshot("warnings");
451+
expect(getErrors(stats)).toMatchSnapshot("errors");
452+
expect(initSpy).toHaveBeenCalledTimes(2);
453+
454+
await close(compiler);
455+
456+
initSpy.mockRestore();
457+
458+
expect(firstDisposeSpy).toHaveBeenCalledTimes(1);
459+
firstDisposeSpy.mockRestore();
460+
461+
expect(secondDisposeSpy).toHaveBeenCalledTimes(1);
462+
secondDisposeSpy.mockRestore();
463+
});
464+
401465
it("should try to load using valid order", async () => {
402466
jest.doMock("sass", () => {
403467
const error = new Error("Some error sass");

0 commit comments

Comments
 (0)