Skip to content

Commit a75501c

Browse files
authored
test scss‑navigation : verify scheme‑prefixed @import paths remain absolute
Adds `schemeImportLinks.test.ts` with four mocha cases covering `http://`, `https://`, `file://`, and `vscode-resource://` URLs
1 parent 1d6f462 commit a75501c

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import * as assert from 'assert';
2+
import { getSCSSLanguageService } from '../../scssLanguageService';
3+
import { TextDocument } from 'vscode-languageserver-textdocument';
4+
import { DocumentContext } from '../../cssLanguageTypes';
5+
6+
function createDocument(contents: string, uri = 'file:///test.scss') {
7+
return TextDocument.create(uri, 'scss', 0, contents);
8+
}
9+
10+
const dummyContext: DocumentContext = {
11+
resolveReference: (ref: string, _base: string) => ref
12+
};
13+
14+
const ls = getSCSSLanguageService();
15+
16+
async function getLinks(contents: string) {
17+
const doc = createDocument(contents);
18+
const stylesheet = ls.parseStylesheet(doc);
19+
return ls.findDocumentLinks2(doc, stylesheet, dummyContext);
20+
}
21+
22+
describe('SCSS Navigation – scheme URL imports', () => {
23+
it('http scheme import is treated as absolute URL, not bare import', async () => {
24+
const links = await getLinks(`@import "http://example.com/foo.css";`);
25+
assert.strictEqual(links.length, 1);
26+
assert.strictEqual(links[0].target, 'http://example.com/foo.css');
27+
});
28+
29+
it('https scheme import is treated as absolute URL, not bare import', async () => {
30+
const links = await getLinks(`@import "https://cdn.example.com/reset.css";`);
31+
assert.strictEqual(links.length, 1);
32+
assert.strictEqual(links[0].target, 'https://cdn.example.com/reset.css');
33+
});
34+
35+
it('file scheme import is treated as absolute URL, not bare import', async () => {
36+
const links = await getLinks(`@import "file:///Users/test/project/styles/base.scss";`);
37+
assert.strictEqual(links.length, 1);
38+
assert.strictEqual(links[0].target, 'file:///Users/test/project/styles/base.scss');
39+
});
40+
41+
it('custom scheme import (vscode-resource) is treated as absolute URL, not bare import', async () => {
42+
const links = await getLinks(`@import "vscode-resource://file/some.css";`);
43+
assert.strictEqual(links.length, 1);
44+
assert.strictEqual(links[0].target, 'vscode-resource://file/some.css');
45+
});
46+
});

0 commit comments

Comments
 (0)