feat(language-service): provide diagnostics for invalid styleUrls (#32674)

Similar to diagnostics for invalid templateUrls, check that styleUrls
actually point to a valid Url.

Closes #32564.

PR Close #32674
This commit is contained in:
ayazhafiz
2019-09-13 13:58:01 -05:00
committed by Andrew Kushnir
parent cd4021ba41
commit 4c168ed9ba
2 changed files with 54 additions and 4 deletions

View File

@ -507,6 +507,37 @@ describe('diagnostics', () => {
diagnostics.find(d => d.messageText === 'URL does not point to a valid file');
expect(urlDiagnostic).toBeUndefined();
});
it('should report errors for invalid styleUrls', () => {
const fileName = mockHost.addCode(`
@Component({
styleUrls: ['«notAFile»'],
})
export class MyComponent {}`);
const marker = mockHost.getReferenceMarkerFor(fileName, 'notAFile');
const diagnostics = ngLS.getDiagnostics(fileName) !;
const urlDiagnostic =
diagnostics.find(d => d.messageText === 'URL does not point to a valid file');
expect(urlDiagnostic).toBeDefined();
const {start, length} = urlDiagnostic !;
expect(start).toBe(marker.start);
expect(length).toBe(marker.length);
});
it('should not report errors for valid styleUrls', () => {
const fileName = '/app/app.component.ts';
mockHost.override(fileName, `
@Component({
styleUrls: ['./test.css', './test.css'],
})
export class MyComponent {}`);
const diagnostics = ngLS.getDiagnostics(fileName) !;
expect(diagnostics.length).toBe(0);
});
});
// https://github.com/angular/vscode-ng-language-service/issues/235