Skip to content

Commit

Permalink
Add regression test for sass/dart-sass#2208 (#1969)
Browse files Browse the repository at this point in the history
  • Loading branch information
ntkme committed Apr 16, 2024
1 parent dccf461 commit c64eb02
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
25 changes: 25 additions & 0 deletions js-api-spec/importer.node.test.ts
Expand Up @@ -12,6 +12,7 @@ import {
} from 'sass';

import {sandbox} from './sandbox';
import {spy} from './utils';

it('avoids importer when canonicalize() returns null', () =>
sandbox(dir => {
Expand Down Expand Up @@ -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(
Expand Down
30 changes: 30 additions & 0 deletions js-api-spec/legacy/importer.node.test.ts
Expand Up @@ -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', () => {
Expand Down

0 comments on commit c64eb02

Please sign in to comment.