Skip to content

Commit

Permalink
Add regression test for sass/dart-sass#2208
Browse files Browse the repository at this point in the history
  • Loading branch information
ntkme committed Apr 4, 2024
1 parent 3aae845 commit 5bed6e1
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
26 changes: 26 additions & 0 deletions js-api-spec/importer.node.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// MIT-style license that can be found in the LICENSE file or at
// https://opensource.org/licenses/MIT.

import * as p from 'path';

Check warning on line 5 in js-api-spec/importer.node.test.ts

View workflow job for this annotation

GitHub Actions / Static analysis

'p' is defined but never used
import {URL} from 'url';
import {
compile,
Expand All @@ -12,6 +13,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 +368,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
Original file line number Diff line number Diff line change
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 5bed6e1

Please sign in to comment.