Skip to content

Commit 5915e94

Browse files
committed
feat(tests): alias testing for CSS/SCSS @imports
1 parent 01ad668 commit 5915e94

File tree

2 files changed

+70
-4
lines changed

2 files changed

+70
-4
lines changed

src/test/css/navigation.test.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { colorFrom256RGB, colorFromHSL, colorFromHWB } from '../../languageFacts
1212

1313
import {
1414
TextDocument, DocumentHighlightKind, Range, Position, TextEdit, Color,
15-
ColorInformation, DocumentLink, SymbolKind, SymbolInformation, Location, LanguageService, Stylesheet, getCSSLanguageService, DocumentSymbol,
15+
ColorInformation, DocumentLink, SymbolKind, SymbolInformation, Location, LanguageService, Stylesheet, getCSSLanguageService, DocumentSymbol, LanguageSettings,
1616
} from '../../cssLanguageService';
1717

1818
import { URI } from 'vscode-uri';
@@ -184,6 +184,17 @@ function getCSSLS() {
184184
return getCSSLanguageService({ fileSystemProvider: getFsProvider() });
185185
}
186186

187+
function aliasSettings(): LanguageSettings {
188+
return {
189+
"alias": {
190+
"paths": {
191+
"@SingleStylesheet": "/src/assets/styles.css",
192+
"@AssetsDir/*": "/src/assets/*",
193+
}
194+
}
195+
};
196+
}
197+
187198
suite('CSS - Navigation', () => {
188199

189200
suite('Scope', () => {
@@ -364,6 +375,16 @@ suite('CSS - Navigation', () => {
364375
]);
365376
});
366377

378+
test('aliased @import links', async function () {
379+
const settings = aliasSettings();
380+
const ls = getCSSLS();
381+
ls.configure(settings);
382+
383+
await assertLinks(ls, '@import "@SingleStylesheet"', [{ range: newRange(8, 27), target: "test://test/src/assets/styles.css"}]);
384+
385+
await assertLinks(ls, '@import "@AssetsDir/styles.css"', [{ range: newRange(8, 31), target: "test://test/src/assets/styles.css"}]);
386+
});
387+
367388
test('links in rulesets', async () => {
368389
const ls = getCSSLS();
369390
await assertLinks(ls, `body { background-image: url(./foo.jpg)`, [

src/test/scss/scssNavigation.test.ts

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,35 @@
66

77
import * as nodes from '../../parser/cssNodes';
88
import { assertSymbolsInScope, assertScopesAndSymbols, assertHighlights, assertColorSymbols, assertLinks, newRange, getTestResource, assertDocumentSymbols } from '../css/navigation.test';
9-
import { getSCSSLanguageService, DocumentLink, TextDocument, SymbolKind } from '../../cssLanguageService';
9+
import { getSCSSLanguageService, DocumentLink, TextDocument, SymbolKind, LanguageSettings } from '../../cssLanguageService';
1010
import * as assert from 'assert';
1111
import * as path from 'path';
12-
import { URI, Utils } from 'vscode-uri';
12+
import { URI } from 'vscode-uri';
1313
import { getFsProvider } from '../testUtil/fsProvider';
1414
import { getDocumentContext } from '../testUtil/documentContext';
1515

1616
function getSCSSLS() {
1717
return getSCSSLanguageService({ fileSystemProvider: getFsProvider() });
1818
}
1919

20-
async function assertDynamicLinks(docUri: string, input: string, expected: DocumentLink[]) {
20+
function aliasSettings(): LanguageSettings {
21+
return {
22+
"alias": {
23+
"paths": {
24+
"@SassStylesheet": "/src/assets/styles.scss",
25+
"@NoUnderscoreDir/*": "/noUnderscore/*",
26+
"@UnderscoreDir/*": "/underscore/*",
27+
"@BothDir/*": "/both/*",
28+
}
29+
}
30+
};
31+
}
32+
33+
async function assertDynamicLinks(docUri: string, input: string, expected: DocumentLink[], settings?: LanguageSettings) {
2134
const ls = getSCSSLS();
35+
if (settings) {
36+
ls.configure(settings);
37+
}
2238
const document = TextDocument.create(docUri, 'scss', 0, input);
2339

2440
const stylesheet = ls.parseStylesheet(document);
@@ -177,6 +193,35 @@ suite('SCSS - Navigation', () => {
177193

178194
});
179195

196+
test('SCSS aliased links', async function () {
197+
const fixtureRoot = path.resolve(__dirname, '../../../../src/test/scss/linkFixture');
198+
const getDocumentUri = (relativePath: string) => {
199+
return URI.file(path.resolve(fixtureRoot, relativePath)).toString(true);
200+
};
201+
202+
const settings = aliasSettings();
203+
const ls = getSCSSLS();
204+
ls.configure(settings);
205+
206+
await assertLinks(ls, '@import "@SassStylesheet"', [{ range: newRange(8, 25), target: "test://test/src/assets/styles.scss"}]);
207+
208+
await assertDynamicLinks(getDocumentUri('./'), `@import '@NoUnderscoreDir/foo'`, [
209+
{ range: newRange(8, 30), target: getDocumentUri('./noUnderscore/foo.scss') }
210+
], settings);
211+
212+
await assertDynamicLinks(getDocumentUri('./'), `@import '@UnderscoreDir/foo'`, [
213+
{ range: newRange(8, 28), target: getDocumentUri('./underscore/_foo.scss') }
214+
], settings);
215+
216+
await assertDynamicLinks(getDocumentUri('./'), `@import '@BothDir/foo'`, [
217+
{ range: newRange(8, 22), target: getDocumentUri('./both/foo.scss') }
218+
], settings);
219+
220+
await assertDynamicLinks(getDocumentUri('./'), `@import '@BothDir/_foo'`, [
221+
{ range: newRange(8, 23), target: getDocumentUri('./both/_foo.scss') }
222+
], settings);
223+
});
224+
180225
test('SCSS module file links', async () => {
181226
const fixtureRoot = path.resolve(__dirname, '../../../../src/test/scss/linkFixture/module');
182227
const getDocumentUri = (relativePath: string) => {

0 commit comments

Comments
 (0)