Skip to content

Commit 2d4907e

Browse files
Improve integration test stability and add tests for code lens options
1 parent d90593c commit 2d4907e

7 files changed

+89
-15
lines changed

test/integrationTests/codeLensProvider.integration.test.ts

+75-1
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,14 @@ suite(`CodeLensProvider: ${testAssetWorkspace.description}`, function () {
2323
await activateCSharpExtension();
2424

2525
let fileName = 'Program.cs';
26-
let projectDirectory = path.dirname(testAssetWorkspace.projects[0].projectDirectoryPath);
26+
let projectDirectory = testAssetWorkspace.projects[0].projectDirectoryPath;
2727
let filePath = path.join(projectDirectory, fileName);
2828
fileUri = vscode.Uri.file(filePath);
2929

30+
let csharpConfig = vscode.workspace.getConfiguration('csharp');
31+
await csharpConfig.update('referencesCodeLens.enabled', true);
32+
await csharpConfig.update('testsCodeLens.enabled', true);
33+
3034
await vscode.commands.executeCommand("vscode.open", fileUri);
3135
});
3236

@@ -56,6 +60,76 @@ suite(`CodeLensProvider: ${testAssetWorkspace.description}`, function () {
5660
});
5761
});
5862

63+
suite(`CodeLensProvider options: ${testAssetWorkspace.description}`, function() {
64+
let fileUri: vscode.Uri;
65+
66+
suiteSetup(async function () {
67+
should();
68+
69+
// These tests only run on the slnWithCsproj solution
70+
if (vscode.workspace.rootPath.split(path.sep).pop() !== 'slnWithCsproj') {
71+
this.skip();
72+
}
73+
else
74+
{
75+
await testAssetWorkspace.restore();
76+
await activateCSharpExtension();
77+
78+
let fileName = 'UnitTest1.cs';
79+
let projectDirectory = testAssetWorkspace.projects[2].projectDirectoryPath;
80+
let filePath = path.join(projectDirectory, fileName);
81+
fileUri = vscode.Uri.file(filePath);
82+
83+
await vscode.commands.executeCommand("vscode.open", fileUri);
84+
}
85+
});
86+
87+
suiteTeardown(async () => {
88+
await testAssetWorkspace.cleanupWorkspace();
89+
});
90+
91+
test("Returns no references code lenses when 'csharp.referencesCodeLens.enabled' option is set to false", async function () {
92+
let csharpConfig = vscode.workspace.getConfiguration('csharp');
93+
await csharpConfig.update('referencesCodeLens.enabled', false);
94+
await csharpConfig.update('testsCodeLens.enabled', true);
95+
96+
let codeLenses = await GetCodeLenses(fileUri, 100);
97+
expect(codeLenses.length).to.equal(4);
98+
99+
for (let codeLens of codeLenses) {
100+
expect(codeLens.isResolved).to.be.true;
101+
expect(codeLens.command).not.to.be.undefined;
102+
expect(codeLens.command.command).to.be.oneOf(['dotnet.test.run', 'dotnet.classTests.run', 'dotnet.test.debug', 'dotnet.classTests.debug']);
103+
expect(codeLens.command.title).to.be.oneOf(['Run Test', 'Run All Tests', 'Debug Test', 'Debug All Tests']);
104+
}
105+
});
106+
107+
test("Returns no test code lenses when 'csharp.testsCodeLens.enabled' option is set to false", async function () {
108+
let csharpConfig = vscode.workspace.getConfiguration('csharp');
109+
await csharpConfig.update('referencesCodeLens.enabled', true);
110+
await csharpConfig.update('testsCodeLens.enabled', false);
111+
112+
let codeLenses = await GetCodeLenses(fileUri, 100);
113+
expect(codeLenses.length).to.equal(2);
114+
115+
for (let codeLens of codeLenses) {
116+
expect(codeLens.isResolved).to.be.true;
117+
expect(codeLens.command).not.to.be.undefined;
118+
expect(codeLens.command.command).to.be.equal('editor.action.showReferences');
119+
expect(codeLens.command.title).to.equal('0 references');
120+
}
121+
});
122+
123+
test("Returns no code lenses when 'csharp.referencesCodeLens.enabled' and 'csharp.testsCodeLens.enabled' options are set to false", async function () {
124+
let csharpConfig = vscode.workspace.getConfiguration('csharp');
125+
await csharpConfig.update('referencesCodeLens.enabled', false);
126+
await csharpConfig.update('testsCodeLens.enabled', false);
127+
128+
let codeLenses = await GetCodeLenses(fileUri, 100);
129+
expect(codeLenses.length).to.equal(0);
130+
});
131+
});
132+
59133
async function GetCodeLenses(fileUri: vscode.Uri, resolvedItemCount?: number) {
60134
return <vscode.CodeLens[]>await vscode.commands.executeCommand("vscode.executeCodeLensProvider", fileUri, resolvedItemCount);
61135
}

test/integrationTests/documentSymbolProvider.integration.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ suite(`DocumentSymbolProvider: ${testAssetWorkspace.description}`, function () {
2323
await activateCSharpExtension();
2424

2525
let fileName = 'documentSymbols.cs';
26-
let projectDirectory = path.dirname(testAssetWorkspace.projects[0].projectDirectoryPath);
26+
let projectDirectory = testAssetWorkspace.projects[0].projectDirectoryPath;
2727
let filePath = path.join(projectDirectory, fileName);
2828
fileUri = vscode.Uri.file(filePath);
2929

test/integrationTests/hoverProvider.integration.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ suite(`Hover Provider: ${testAssetWorkspace.description}`, function () {
2727

2828
test("Hover returns structured documentation with proper newlines", async function () {
2929
let fileName = 'hover.cs';
30-
let dir = path.dirname(testAssetWorkspace.projects[0].projectDirectoryPath);
30+
let dir = testAssetWorkspace.projects[0].projectDirectoryPath;
3131
let loc = path.join(dir, fileName);
3232
let fileUri = vscode.Uri.file(loc);
3333

test/integrationTests/signatureHelp.integration.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ suite(`SignatureHelp: ${testAssetWorkspace.description}`, function () {
2323
await activateCSharpExtension();
2424

2525
let fileName = 'sigHelp.cs';
26-
let dir = path.dirname(testAssetWorkspace.projects[0].projectDirectoryPath);
26+
let dir = testAssetWorkspace.projects[0].projectDirectoryPath;
2727
let loc = path.join(dir, fileName);
2828
fileUri = vscode.Uri.file(loc);
2929
await vscode.commands.executeCommand("vscode.open", fileUri);

test/integrationTests/testAssets/singleCsproj.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { ITestAssetWorkspace } from "./testAssets";
88
let workspace: ITestAssetWorkspace = {
99
description: "single csproj at root of workspace",
1010
projects: [{
11-
relativePath: "singleCsproj.csproj"
11+
relativeFilePath: "singleCsproj.csproj"
1212
}]
1313
};
1414

test/integrationTests/testAssets/slnWithCsproj.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ import { ITestAssetWorkspace } from "./testAssets";
88
let workspace: ITestAssetWorkspace = {
99
description: "sln with several csproj's",
1010
projects: [{
11-
relativePath: "src/app/app.csproj"
11+
relativeFilePath: "src/app/app.csproj"
1212
},{
13-
relativePath: "src/lib/lib.csproj"
13+
relativeFilePath: "src/lib/lib.csproj"
1414
},{
15-
relativePath: "test/test.csproj"
15+
relativeFilePath: "test/test.csproj"
1616
}]
1717
};
1818

test/integrationTests/testAssets/testAssets.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@ import { EventStream } from '../../../src/EventStream';
1212

1313
export class TestAssetProject {
1414
constructor(project: ITestAssetProject) {
15-
this.relativePath = project.relativePath;
15+
this.relativeFilePath = project.relativeFilePath;
1616
}
1717

18-
relativePath: string;
18+
relativeFilePath: string;
1919

2020
get projectDirectoryPath(): string {
2121
return path.join(vscode.workspace.workspaceFolders[0].uri.fsPath,
22-
this.relativePath);
22+
path.dirname(this.relativeFilePath));
2323
}
2424

2525
get binDirectoryPath(): string {
@@ -36,11 +36,11 @@ export class TestAssetProject {
3636
}
3737

3838
async restore(): Promise<void> {
39-
await dotnetRestore(vscode.workspace.rootPath, new EventStream());
39+
await dotnetRestore(this.projectDirectoryPath, new EventStream());
4040
}
4141

4242
async addFileWithContents(fileName: string, contents: string): Promise<vscode.Uri> {
43-
let dir = path.dirname(this.projectDirectoryPath);
43+
let dir = this.projectDirectoryPath;
4444
let loc = path.join(dir, fileName);
4545
await fs.writeTextFile(loc, contents);
4646
return vscode.Uri.file(loc);
@@ -78,7 +78,7 @@ export class TestAssetWorkspace {
7878

7979
async cleanupWorkspace(): Promise<void> {
8080
for (let project of this.projects) {
81-
let wd = path.dirname(project.projectDirectoryPath);
81+
let wd = project.projectDirectoryPath;
8282
await spawnGit(["clean", "-xdf", "."], { cwd: wd });
8383
await spawnGit(["checkout", "--", "."], { cwd: wd });
8484
}
@@ -90,7 +90,7 @@ export class TestAssetWorkspace {
9090
}
9191

9292
export interface ITestAssetProject {
93-
relativePath: string;
93+
relativeFilePath: string;
9494
}
9595

9696
export interface ITestAssetWorkspace {

0 commit comments

Comments
 (0)