diff --git a/js-api-spec/importer.node.test.ts b/js-api-spec/importer.node.test.ts index a240ccc27..e03ad18fb 100644 --- a/js-api-spec/importer.node.test.ts +++ b/js-api-spec/importer.node.test.ts @@ -12,6 +12,7 @@ import { } from 'sass'; import {sandbox} from './sandbox'; +import {spy} from './utils'; it('avoids importer when canonicalize() returns null', () => sandbox(dir => { @@ -366,6 +367,30 @@ describe('FileImporter', () => { ).toThrowSassException({line: 0}); }); }); + + // Regression test for sass/dart-sass#2208. + it('imports the same relative url from different base urls as different files', () => + sandbox(dir => { + const findFileUrl = spy((url, context) => { + return url === 'y' ? new URL('x.scss', context.containingUrl) : null; + }); + + dir.write({ + 'main.scss': '@import "sub1/test"; @import "sub1/sub2/test"', + 'sub1/test.scss': '@import "y"', + 'sub1/x.scss': 'x { from: sub1; }', + 'sub1/sub2/test.scss': '@import "y"', + 'sub1/sub2/x.scss': 'x { from: sub2; }', + }); + + expect( + compile(dir('main.scss'), { + importers: [{findFileUrl}], + }).css.toString() + ).toEqualIgnoringWhitespace('x { from: sub1; } x { from: sub2; }'); + + expect(findFileUrl).toHaveBeenCalledTimes(2); + })); }); it( diff --git a/js-api-spec/legacy/importer.node.test.ts b/js-api-spec/legacy/importer.node.test.ts index 081d36f53..43f567fc2 100644 --- a/js-api-spec/legacy/importer.node.test.ts +++ b/js-api-spec/legacy/importer.node.test.ts @@ -178,6 +178,36 @@ describe('with contents', () => { }), }).stats.includedFiles ).toContain(p.resolve('bar'))); + + // Regression test for sass/dart-sass#2208. + it('imports the same relative url from different base urls as different files', () => + sandbox(dir => { + const importer = spy((url: string, prev: string) => { + return url === 'x' + ? { + contents: `x {from: ${p.basename(p.dirname(prev))}}`, + file: p.resolve(p.dirname(prev), 'x.scss'), + } + : null; + }); + + dir.write({ + 'main.scss': '@import "sub1/test"; @import "sub1/sub2/test"', + 'sub1/test.scss': '@import "x"', + 'sub1/sub2/test.scss': '@import "x"', + }); + + expect( + sass + .renderSync({ + file: dir('main.scss'), + importer, + }) + .css.toString() + ).toEqualIgnoringWhitespace('x { from: sub1; } x { from: sub2; }'); + + expect(importer).toHaveBeenCalledTimes(2); + })); }); describe('with a file redirect', () => {