Skip to content

Commit

Permalink
Test compilations in callbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
jerivas committed Nov 21, 2023
1 parent 36db21b commit 7c17ae5
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions js-api-spec/compiler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,20 @@ describe('Compiler', () => {
expect(logger.debug).toHaveBeenCalledTimes(1);
});

it('performs compilations in callbacks', () => {
const nestedImporter = {
canonicalize: (url: string) => new URL(`u:${url}`),
load: (url: typeof URL) => ({

Check warning on line 72 in js-api-spec/compiler.test.ts

View workflow job for this annotation

GitHub Actions / Static analysis

'url' is defined but never used
contents: compiler.compileString('x {y: z}').css,
syntax: 'scss' as const,
}),
};
const result = compiler.compileString('@import "nested"; a {b: c}', {
importers: [nestedImporter],
});
expect(result.css).toEqualIgnoringWhitespace('x {y: z;} a {b: c;}');
});

it('throws after being disposed', () => {
compiler.dispose();
expect(() => compiler.compileString('$a: b; c {d: $a}')).toThrowError();
Expand All @@ -88,6 +102,23 @@ describe('Compiler', () => {
expect(logger.debug).toHaveBeenCalledTimes(1);
}));

it('performs compilations in callbacks', () =>
sandbox(dir => {
dir.write({'input-nested.scss': 'x {y: z}'});
const nestedImporter = {
canonicalize: (url: string) => new URL(`u:${url}`),
load: (url: typeof URL) => ({

Check warning on line 110 in js-api-spec/compiler.test.ts

View workflow job for this annotation

GitHub Actions / Static analysis

'url' is defined but never used
contents: compiler.compile(dir('input-nested.scss')).css,
syntax: 'scss' as const,
}),
};
dir.write({'input.scss': '@import "nested"; a {b: c}'});
const result = compiler.compile(dir('input.scss'), {
importers: [nestedImporter],
});
expect(result.css).toEqualIgnoringWhitespace('x {y: z;} a {b: c;}');
}));

it('throws after being disposed', () =>
sandbox(dir => {
dir.write({'input.scss': '$a: b; c {d: $a}'});
Expand Down

0 comments on commit 7c17ae5

Please sign in to comment.