From dccf4610752c122ca75ed1cce855f2d1ec9105d5 Mon Sep 17 00:00:00 2001 From: Natalie Weizenbaum Date: Thu, 11 Apr 2024 15:33:08 -0700 Subject: [PATCH] Add a test for an importer without a base URL (#1972) Closes #1970 --- js-api-spec/importer.test.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/js-api-spec/importer.test.ts b/js-api-spec/importer.test.ts index f2bd97154..a9658b2c8 100644 --- a/js-api-spec/importer.test.ts +++ b/js-api-spec/importer.test.ts @@ -560,6 +560,23 @@ describe("compileString()'s importer option", () => { expect(result.css).toBe('a {\n result: "foo/baz/qux/bang";\n}'); }); + it('loads relative imports without an entrypoint URL', () => { + const result = compileString('@import "orange";', { + importer: { + canonicalize: (url: string) => { + expect(url).toBe('orange'); + return new URL('u:orange'); + }, + load: (url: typeof URL) => { + const color = url.pathname; + return {contents: `.${color} {color: ${color}}`, syntax: 'scss'}; + }, + }, + }); + + expect(result.css).toBe('.orange {\n color: orange;\n}'); + }); + it('takes precedence over the importer list for relative URLs', () => { const result = compileString('@import "other";', { importers: [