Skip to content

Commit 94812e7

Browse files
committed
Use DevKit for testing
1 parent fba3ffc commit 94812e7

File tree

7 files changed

+42
-23
lines changed

7 files changed

+42
-23
lines changed

tasks/testTasks.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,10 @@ function createIntegrationTestSubTasks() {
7676

7777
for (const projectName of razorIntegrationTestProjects) {
7878
gulp.task(`test:integration:razor:${projectName}`, async () =>
79-
runIntegrationTest(
79+
// Run DevKit tests because razor doesn't gracefully handle roslyn restarting
80+
// in tests. DevKit prevents that behavior by handling project restore without
81+
// requiring it.
82+
runDevKitIntegrationTests(
8083
projectName,
8184
path.join('razor', 'razorIntegrationTests'),
8285
`Razor Test Integration ${projectName}`

test/lsptoolshost/integrationTests/integrationHelpers.ts

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,7 @@ import testAssetWorkspace from './testAssets/testAssetWorkspace';
1313
import { EOL, platform } from 'os';
1414
import { describe, expect, test } from '@jest/globals';
1515

16-
export async function activateRazorExtension(): Promise<void> {
17-
// Razor requires statefulness in the extension and server to communicate
18-
// properly with CSharp. That means allowing a restart of the CSharp server
19-
// will improperly break that state. This will be fixed in cohosting and
20-
// could be potentially fixed now but I timeboxed to unblock adding more tests.
21-
// Without this the symptoms in a test will be that all razor files are considered
22-
// in the misc workspace.
23-
await activateCSharpExtension(false);
24-
}
25-
26-
export async function activateCSharpExtension(allowRestart?: boolean): Promise<void> {
27-
allowRestart = allowRestart ?? true;
28-
16+
export async function activateCSharpExtension(): Promise<void> {
2917
const csharpExtension = vscode.extensions.getExtension<CSharpExtensionExports>('ms-dotnettools.csharp');
3018
if (!csharpExtension) {
3119
throw new Error('Failed to find installation of ms-dotnettools.csharp');
@@ -62,7 +50,7 @@ export async function activateCSharpExtension(allowRestart?: boolean): Promise<v
6250
console.log('ms-dotnettools.csharp activated');
6351
console.log(`Extension Log Directory: ${csharpExtension.exports.logDirectory}`);
6452

65-
if (shouldRestart && allowRestart) {
53+
if (shouldRestart) {
6654
await restartLanguageServer();
6755
}
6856
}
@@ -271,6 +259,16 @@ export async function expectText(document: vscode.TextDocument, expectedLines: s
271259
expect(document.getText()).toBe(expectedText);
272260
}
273261

262+
export function expectPath(expected: vscode.Uri, actual: vscode.Uri) {
263+
if (isLinux()) {
264+
expect(actual.path).toBe(expected.path);
265+
} else {
266+
const actualPath = actual.path.toLowerCase();
267+
const expectedPath = expected.path.toLocaleLowerCase();
268+
expect(actualPath).toBe(expectedPath);
269+
}
270+
}
271+
274272
export const describeIfCSharp = describeIf(!usingDevKit());
275273
export const describeIfDevKit = describeIf(usingDevKit());
276274
export const describeIfNotMacOS = describeIf(!isMacOS());
@@ -297,3 +295,7 @@ function isWindows() {
297295
const currentPlatform = platform();
298296
return currentPlatform === 'win32';
299297
}
298+
299+
function isLinux() {
300+
return !(isMacOS() || isWindows());
301+
}

test/razor/razorIntegrationTests/formatting.integration.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { beforeAll, afterAll, test, expect, beforeEach } from '@jest/globals';
99
import testAssetWorkspace from './testAssets/testAssetWorkspace';
1010
import * as integrationHelpers from '../../lsptoolshost/integrationTests/integrationHelpers';
1111

12-
integrationHelpers.describeIfWindows(`Razor Formatting ${testAssetWorkspace.description}`, function () {
12+
integrationHelpers.describeIfDevKit(`Razor Formatting ${testAssetWorkspace.description}`, function () {
1313
beforeAll(async function () {
1414
if (!integrationHelpers.isRazorWorkspace(vscode.workspace)) {
1515
return;

test/razor/razorIntegrationTests/hover.integration.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { beforeAll, afterAll, test, expect, beforeEach } from '@jest/globals';
99
import testAssetWorkspace from './testAssets/testAssetWorkspace';
1010
import * as integrationHelpers from '../../lsptoolshost/integrationTests/integrationHelpers';
1111

12-
integrationHelpers.describeIfWindows(`Razor Hover ${testAssetWorkspace.description}`, function () {
12+
integrationHelpers.describeIfDevKit(`Razor Hover ${testAssetWorkspace.description}`, function () {
1313
beforeAll(async function () {
1414
if (!integrationHelpers.isRazorWorkspace(vscode.workspace)) {
1515
return;

test/razor/razorIntegrationTests/reference.integration.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ import { beforeAll, afterAll, test, expect, beforeEach } from '@jest/globals';
99
import testAssetWorkspace from './testAssets/testAssetWorkspace';
1010
import * as integrationHelpers from '../../lsptoolshost/integrationTests/integrationHelpers';
1111

12-
integrationHelpers.describeIfWindows(`Razor References ${testAssetWorkspace.description}`, function () {
12+
integrationHelpers.describeIfDevKit(`Razor References ${testAssetWorkspace.description}`, function () {
1313
beforeAll(async function () {
1414
if (!integrationHelpers.isRazorWorkspace(vscode.workspace)) {
1515
return;
1616
}
1717

18-
await integrationHelpers.activateRazorExtension();
18+
await integrationHelpers.activateCSharpExtension();
1919
});
2020

2121
beforeEach(async function () {
@@ -151,9 +151,9 @@ integrationHelpers.describeIfWindows(`Razor References ${testAssetWorkspace.desc
151151
const razorFile = integrationHelpers.getFilePath(path.join('Pages', 'References.razor'));
152152
const csharpFile = integrationHelpers.getFilePath(path.join('Pages', 'References.razor.cs'));
153153

154-
expect(sortedLocations[0].uri.path).toBe(razorFile.path);
155-
expect(sortedLocations[1].uri.path).toBe(csharpFile.path);
156-
expect(sortedLocations[2].uri.path).toBe(csharpFile.path);
154+
integrationHelpers.expectPath(razorFile, sortedLocations[0].uri);
155+
integrationHelpers.expectPath(csharpFile, sortedLocations[1].uri);
156+
integrationHelpers.expectPath(csharpFile, sortedLocations[2].uri);
157157
}
158158
);
159159
});

test/razor/razorIntegrationTests/rename.integration.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { beforeAll, afterAll, test, expect, beforeEach } from '@jest/globals';
99
import testAssetWorkspace from './testAssets/testAssetWorkspace';
1010
import * as integrationHelpers from '../../lsptoolshost/integrationTests/integrationHelpers';
1111

12-
integrationHelpers.describeIfWindows(`Razor Rename ${testAssetWorkspace.description}`, function () {
12+
integrationHelpers.describeIfDevKit(`Razor Rename ${testAssetWorkspace.description}`, function () {
1313
beforeAll(async function () {
1414
if (!integrationHelpers.isRazorWorkspace(vscode.workspace)) {
1515
return;
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"folders": [
3+
{
4+
"path": ".."
5+
}
6+
],
7+
"settings": {
8+
"dotnet.defaultSolution": "RazorApp.sln",
9+
"dotnet.server.useOmnisharp": false,
10+
"omnisharp.enableLspDriver": false,
11+
"razor.server.trace": "Trace",
12+
"dotnet.preferCSharpExtension": false
13+
}
14+
}

0 commit comments

Comments
 (0)