Skip to content

Commit d17f863

Browse files
committed
test: allow for lsp tests to work with windows
1 parent e882dd4 commit d17f863

File tree

3 files changed

+12
-6
lines changed

3 files changed

+12
-6
lines changed

integration/lsp/ivy_spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import {NgccProgress, NgccProgressToken, NgccProgressType} from '../../common/pr
1717
import {GetComponentsWithTemplateFile, GetTcbRequest, GetTemplateLocationForComponent, IsInAngularProject} from '../../common/requests';
1818
import {APP_COMPONENT, APP_COMPONENT_URI, FOO_COMPONENT, FOO_COMPONENT_URI, FOO_TEMPLATE, FOO_TEMPLATE_URI, PROJECT_PATH, TSCONFIG} from '../test_constants';
1919

20-
import {createConnection, createTracer, initializeServer, openTextDocument} from './test_utils';
20+
import {convertPathToFileUrl, createConnection, createTracer, initializeServer, openTextDocument} from './test_utils';
2121

2222
const setTimeoutP = promisify(setTimeout);
2323

@@ -603,7 +603,7 @@ function getDiagnosticsForFile(
603603
return new Promise(resolve => {
604604
client.onNotification(
605605
lsp.PublishDiagnosticsNotification.type, (params: lsp.PublishDiagnosticsParams) => {
606-
if (params.uri === `file://${fileName}`) {
606+
if (params.uri === convertPathToFileUrl(fileName)) {
607607
resolve(params.diagnostics);
608608
}
609609
});

integration/lsp/test_utils.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {fork} from 'child_process';
1010
import * as fs from 'fs';
1111
import {createMessageConnection, IPCMessageReader, IPCMessageWriter, MessageConnection} from 'vscode-jsonrpc/node';
1212
import * as lsp from 'vscode-languageserver-protocol';
13+
import {URI} from 'vscode-uri';
1314

1415
import {PROJECT_PATH, SERVER_PATH} from '../test_constants';
1516

@@ -79,14 +80,18 @@ export function openTextDocument(client: MessageConnection, filePath: string, ne
7980
}
8081
client.sendNotification(lsp.DidOpenTextDocumentNotification.type, {
8182
textDocument: {
82-
uri: `file://${filePath}`,
83+
uri: convertPathToFileUrl(filePath),
8384
languageId,
8485
version: 1,
8586
text: newText ?? fs.readFileSync(filePath, 'utf-8'),
8687
},
8788
});
8889
}
8990

91+
export function convertPathToFileUrl(filePath: string): string {
92+
return URI.file(filePath).toString();
93+
}
94+
9095
export function createTracer(): lsp.Tracer {
9196
return {
9297
log(messageOrDataObject: string|any, data?: string) {

integration/test_constants.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import {join, resolve} from 'path';
2+
import {convertPathToFileUrl} from './lsp/test_utils';
23

34
export const PACKAGE_ROOT = resolve(__dirname, '../..');
45
export const SERVER_PATH = join(PACKAGE_ROOT, 'dist', 'npm', 'server', 'index.js');
56
export const PROJECT_PATH = join(PACKAGE_ROOT, 'integration', 'project');
67
export const APP_COMPONENT = join(PROJECT_PATH, 'app', 'app.component.ts');
7-
export const APP_COMPONENT_URI = `file://${APP_COMPONENT}`;
8+
export const APP_COMPONENT_URI = convertPathToFileUrl(APP_COMPONENT);
89
export const FOO_TEMPLATE = join(PROJECT_PATH, 'app', 'foo.component.html');
9-
export const FOO_TEMPLATE_URI = `file://${FOO_TEMPLATE}`;
10+
export const FOO_TEMPLATE_URI = convertPathToFileUrl(FOO_TEMPLATE);
1011
export const FOO_COMPONENT = join(PROJECT_PATH, 'app', 'foo.component.ts');
11-
export const FOO_COMPONENT_URI = `file://${FOO_COMPONENT}`;
12+
export const FOO_COMPONENT_URI = convertPathToFileUrl(FOO_COMPONENT);
1213
export const TSCONFIG = join(PROJECT_PATH, 'tsconfig.json');

0 commit comments

Comments
 (0)