Skip to content

Commit 8a5974e

Browse files
committed
Close all text editors after each test.
1 parent 3e16d35 commit 8a5974e

12 files changed

+103
-45
lines changed

test/integrationTests/buildDiagnostics.integration.test.ts

+11-4
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,28 @@
44
*--------------------------------------------------------------------------------------------*/
55

66
import * as vscode from 'vscode';
7-
import { describe, test, expect, beforeAll, afterAll } from '@jest/globals';
7+
import { describe, test, expect, beforeAll, afterAll, beforeEach, afterEach } from '@jest/globals';
88
import testAssetWorkspace from './testAssets/testAssetWorkspace';
99
import { AnalysisSetting, BuildDiagnosticsService } from '../../src/lsptoolshost/buildDiagnosticsService';
1010
import * as integrationHelpers from './integrationHelpers';
1111
import path = require('path');
12-
describe(`Build and live diagnostics dedupe ${testAssetWorkspace.description}`, function () {
13-
beforeAll(async function () {
14-
await integrationHelpers.openFileInWorkspaceAsync(path.join('src', 'app', 'inlayHints.cs'));
12+
describe(`Build and live diagnostics dedupe ${testAssetWorkspace.description}`, () => {
13+
beforeAll(async () => {
1514
await integrationHelpers.activateCSharpExtension();
1615
});
1716

17+
beforeEach(async () => {
18+
await integrationHelpers.openFileInWorkspaceAsync(path.join('src', 'app', 'inlayHints.cs'));
19+
});
20+
1821
afterAll(async () => {
1922
await testAssetWorkspace.cleanupWorkspace();
2023
});
2124

25+
afterEach(async () => {
26+
await integrationHelpers.closeAllEditorsAsync();
27+
});
28+
2229
test('OpenFiles diagnostics', async () => {
2330
await setBackgroundAnalysisSetting(
2431
/*analyzer*/ AnalysisSetting.OpenFiles,

test/integrationTests/codelens.integration.test.ts

+14-5
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,21 @@
66
import * as lsp from 'vscode-languageserver-protocol';
77
import * as vscode from 'vscode';
88
import * as path from 'path';
9-
import { describe, beforeAll, beforeEach, afterAll, test, expect } from '@jest/globals';
9+
import { describe, beforeAll, beforeEach, afterAll, test, expect, afterEach } from '@jest/globals';
1010
import testAssetWorkspace from './testAssets/testAssetWorkspace';
11-
import { activateCSharpExtension, getCodeLensesAsync, openFileInWorkspaceAsync } from './integrationHelpers';
11+
import {
12+
activateCSharpExtension,
13+
closeAllEditorsAsync,
14+
getCodeLensesAsync,
15+
openFileInWorkspaceAsync,
16+
} from './integrationHelpers';
1217

13-
describe(`[${testAssetWorkspace.description}] Test CodeLens`, function () {
14-
beforeAll(async function () {
18+
describe(`[${testAssetWorkspace.description}] Test CodeLens`, () => {
19+
beforeAll(async () => {
1520
await activateCSharpExtension();
1621
});
1722

18-
beforeEach(async function () {
23+
beforeEach(async () => {
1924
const fileName = path.join('src', 'app', 'reference.cs');
2025
await openFileInWorkspaceAsync(fileName);
2126
});
@@ -24,6 +29,10 @@ describe(`[${testAssetWorkspace.description}] Test CodeLens`, function () {
2429
await testAssetWorkspace.cleanupWorkspace();
2530
});
2631

32+
afterEach(async () => {
33+
await closeAllEditorsAsync();
34+
});
35+
2736
test('CodeLens references are displayed', async () => {
2837
const codeLenses = await getCodeLensesAsync();
2938
expect(codeLenses).toHaveLength(4);

test/integrationTests/commandEnablement.integration.test.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,16 @@ import { activateCSharpExtension } from './integrationHelpers';
99
import testAssetWorkspace from './testAssets/testAssetWorkspace';
1010
import { CommonCommands, OmniSharpCommands, RoslynCommands } from './expectedCommands';
1111

12-
describe(`Command Enablement: ${testAssetWorkspace.description}`, function () {
13-
beforeAll(async function () {
12+
describe(`Command Enablement: ${testAssetWorkspace.description}`, () => {
13+
beforeAll(async () => {
1414
await activateCSharpExtension();
1515
});
1616

1717
afterAll(async () => {
1818
await testAssetWorkspace.cleanupWorkspace();
1919
});
2020

21-
test('Roslyn commands are available', async function () {
21+
test('Roslyn commands are available', async () => {
2222
const commands = await vscode.commands.getCommands(true);
2323

2424
// Ensure the standalone Roslyn commands are available.

test/integrationTests/completion.integration.test.ts

+9-5
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@
55

66
import * as vscode from 'vscode';
77
import * as path from 'path';
8-
import { describe, beforeAll, beforeEach, afterAll, test, expect } from '@jest/globals';
8+
import { describe, beforeAll, beforeEach, afterAll, test, expect, afterEach } from '@jest/globals';
99
import testAssetWorkspace from './testAssets/testAssetWorkspace';
10-
import { activateCSharpExtension, openFileInWorkspaceAsync } from './integrationHelpers';
10+
import { activateCSharpExtension, closeAllEditorsAsync, openFileInWorkspaceAsync } from './integrationHelpers';
1111

12-
describe(`[${testAssetWorkspace.description}] Test Completion`, function () {
13-
beforeAll(async function () {
12+
describe(`[${testAssetWorkspace.description}] Test Completion`, () => {
13+
beforeAll(async () => {
1414
await activateCSharpExtension();
1515
});
1616

17-
beforeEach(async function () {
17+
beforeEach(async () => {
1818
const fileName = path.join('src', 'app', 'completion.cs');
1919
await openFileInWorkspaceAsync(fileName);
2020
});
@@ -23,6 +23,10 @@ describe(`[${testAssetWorkspace.description}] Test Completion`, function () {
2323
await testAssetWorkspace.cleanupWorkspace();
2424
});
2525

26+
afterEach(async () => {
27+
await closeAllEditorsAsync();
28+
});
29+
2630
test('Returns completion items', async () => {
2731
const completionList = await getCompletionsAsync(new vscode.Position(8, 12), undefined, 10);
2832
expect(completionList.items.length).toBeGreaterThan(0);

test/integrationTests/documentDiagnostics.integration.test.ts

+9-4
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@
44
*--------------------------------------------------------------------------------------------*/
55

66
import * as vscode from 'vscode';
7-
import { describe, test, beforeAll, afterAll, expect } from '@jest/globals';
7+
import { describe, test, beforeAll, afterAll, expect, beforeEach, afterEach } from '@jest/globals';
88
import testAssetWorkspace from './testAssets/testAssetWorkspace';
99
import { AnalysisSetting } from '../../src/lsptoolshost/buildDiagnosticsService';
1010
import * as integrationHelpers from './integrationHelpers';
1111
import path = require('path');
1212
import { getCode, setBackgroundAnalysisScopes, waitForExpectedDiagnostics } from './diagnosticsHelpers';
13-
describe(`[${testAssetWorkspace.description}] Test diagnostics`, function () {
14-
beforeAll(async function () {
13+
14+
describe(`[${testAssetWorkspace.description}] Test diagnostics`, () => {
15+
beforeAll(async () => {
1516
await integrationHelpers.activateCSharpExtension();
1617
});
1718

@@ -21,10 +22,14 @@ describe(`[${testAssetWorkspace.description}] Test diagnostics`, function () {
2122

2223
describe('Open document diagnostics', () => {
2324
let file: vscode.Uri;
24-
beforeAll(async () => {
25+
beforeEach(async () => {
2526
file = await integrationHelpers.openFileInWorkspaceAsync(path.join('src', 'app', 'diagnostics.cs'));
2627
});
2728

29+
afterEach(async () => {
30+
await integrationHelpers.closeAllEditorsAsync();
31+
});
32+
2833
test('Compiler and analyzer diagnostics reported for open file when set to OpenFiles', async () => {
2934
await setBackgroundAnalysisScopes({
3035
compiler: AnalysisSetting.OpenFiles,

test/integrationTests/documentSymbolProvider.integration.test.ts

+12-5
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,20 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6-
import { expect, test, beforeAll, afterAll, describe } from '@jest/globals';
6+
import { expect, test, beforeAll, afterAll, describe, afterEach, beforeEach } from '@jest/globals';
77
import * as vscode from 'vscode';
88
import * as path from 'path';
99
import testAssetWorkspace from './testAssets/testAssetWorkspace';
10-
import { activateCSharpExtension, openFileInWorkspaceAsync } from './integrationHelpers';
10+
import { activateCSharpExtension, closeAllEditorsAsync, openFileInWorkspaceAsync } from './integrationHelpers';
1111

12-
describe(`DocumentSymbolProvider: ${testAssetWorkspace.description}`, function () {
12+
describe(`DocumentSymbolProvider: ${testAssetWorkspace.description}`, () => {
1313
let fileUri: vscode.Uri;
1414

15-
beforeAll(async function () {
15+
beforeAll(async () => {
1616
await activateCSharpExtension();
17+
});
18+
19+
beforeEach(async () => {
1720
const relativePath = path.join('src', 'app', 'documentSymbols.cs');
1821
fileUri = await openFileInWorkspaceAsync(relativePath);
1922
});
@@ -22,7 +25,11 @@ describe(`DocumentSymbolProvider: ${testAssetWorkspace.description}`, function (
2225
await testAssetWorkspace.cleanupWorkspace();
2326
});
2427

25-
test('Returns all elements', async function () {
28+
afterEach(async () => {
29+
await closeAllEditorsAsync();
30+
});
31+
32+
test('Returns all elements', async () => {
2633
const symbols = await GetDocumentSymbols(fileUri);
2734

2835
expect(symbols).toHaveLength(5);

test/integrationTests/gotoDefinition.integration.test.ts

+9-5
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,26 @@
66
import * as vscode from 'vscode';
77
import * as path from 'path';
88
import testAssetWorkspace from './testAssets/testAssetWorkspace';
9-
import { activateCSharpExtension, openFileInWorkspaceAsync } from './integrationHelpers';
10-
import { describe, beforeAll, beforeEach, afterAll, test, expect } from '@jest/globals';
9+
import { activateCSharpExtension, closeAllEditorsAsync, openFileInWorkspaceAsync } from './integrationHelpers';
10+
import { describe, beforeAll, beforeEach, afterAll, test, expect, afterEach } from '@jest/globals';
1111

12-
describe(`[${testAssetWorkspace.description}] Test Go To Definition`, function () {
13-
beforeAll(async function () {
12+
describe(`[${testAssetWorkspace.description}] Test Go To Definition`, () => {
13+
beforeAll(async () => {
1414
await activateCSharpExtension();
1515
});
1616

17-
beforeEach(async function () {
17+
beforeEach(async () => {
1818
await openFileInWorkspaceAsync(path.join('src', 'app', 'definition.cs'));
1919
});
2020

2121
afterAll(async () => {
2222
await testAssetWorkspace.cleanupWorkspace();
2323
});
2424

25+
afterEach(async () => {
26+
await closeAllEditorsAsync();
27+
});
28+
2529
test('Navigates to definition in same file', async () => {
2630
const requestPosition = new vscode.Position(10, 31);
2731
const definitionList = <vscode.Location[]>(

test/integrationTests/integrationHelpers.ts

+4
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ export async function openFileInWorkspaceAsync(relativeFilePath: string): Promis
6060
return uri;
6161
}
6262

63+
export async function closeAllEditorsAsync(): Promise<void> {
64+
await vscode.commands.executeCommand('workbench.action.closeAllEditors');
65+
}
66+
6367
/**
6468
* Reverts any unsaved changes to the active file.
6569
* Useful to reset state between tests without fully reloading everything.

test/integrationTests/lspInlayHints.integration.test.ts

+11-4
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55

66
import * as path from 'path';
77
import * as vscode from 'vscode';
8-
import { describe, beforeAll, afterAll, test, expect } from '@jest/globals';
8+
import { describe, beforeAll, afterAll, test, expect, beforeEach, afterEach } from '@jest/globals';
99
import testAssetWorkspace from './testAssets/testAssetWorkspace';
1010
import * as integrationHelpers from './integrationHelpers';
1111
import { InlayHint, InlayHintKind, Position } from 'vscode-languageserver-protocol';
1212

13-
describe(`[${testAssetWorkspace.description}] Test LSP Inlay Hints `, function () {
14-
beforeAll(async function () {
13+
describe(`[${testAssetWorkspace.description}] Test LSP Inlay Hints `, () => {
14+
beforeAll(async () => {
1515
const editorConfig = vscode.workspace.getConfiguration('editor');
1616
await editorConfig.update('inlayHints.enabled', true);
1717
const dotnetConfig = vscode.workspace.getConfiguration('dotnet');
@@ -30,14 +30,21 @@ describe(`[${testAssetWorkspace.description}] Test LSP Inlay Hints `, function (
3030
await csharpConfig.update('inlayHints.enableInlayHintsForLambdaParameterTypes', true);
3131
await csharpConfig.update('inlayHints.enableInlayHintsForImplicitObjectCreation', true);
3232

33-
await integrationHelpers.openFileInWorkspaceAsync(path.join('src', 'app', 'inlayHints.cs'));
3433
await integrationHelpers.activateCSharpExtension();
3534
});
3635

36+
beforeEach(async () => {
37+
await integrationHelpers.openFileInWorkspaceAsync(path.join('src', 'app', 'inlayHints.cs'));
38+
});
39+
3740
afterAll(async () => {
3841
await testAssetWorkspace.cleanupWorkspace();
3942
});
4043

44+
afterEach(async () => {
45+
await integrationHelpers.closeAllEditorsAsync();
46+
});
47+
4148
test('Hints retrieved for region', async () => {
4249
const range = new vscode.Range(new vscode.Position(4, 8), new vscode.Position(15, 85));
4350
const activeDocument = vscode.window.activeTextEditor?.document.uri;

test/integrationTests/onAutoInsert.integration.test.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,26 @@ import * as path from 'path';
88
import testAssetWorkspace from './testAssets/testAssetWorkspace';
99
import {
1010
activateCSharpExtension,
11+
closeAllEditorsAsync,
1112
openFileInWorkspaceAsync,
1213
revertActiveFile,
1314
sleep,
1415
waitForExpectedResult,
1516
} from './integrationHelpers';
1617
import { describe, beforeAll, beforeEach, afterAll, test, expect, afterEach } from '@jest/globals';
1718

18-
describe(`[${testAssetWorkspace.description}] Test OnAutoInsert`, function () {
19-
beforeAll(async function () {
19+
describe(`[${testAssetWorkspace.description}] Test OnAutoInsert`, () => {
20+
beforeAll(async () => {
2021
await activateCSharpExtension();
2122
});
2223

23-
beforeEach(async function () {
24+
beforeEach(async () => {
2425
await openFileInWorkspaceAsync(path.join('src', 'app', 'DocComments.cs'));
2526
});
2627

2728
afterEach(async () => {
2829
await revertActiveFile();
30+
await closeAllEditorsAsync();
2931
});
3032

3133
afterAll(async () => {

test/integrationTests/unitTests.integration.test.ts

+14-5
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,22 @@
55

66
import * as vscode from 'vscode';
77
import * as path from 'path';
8-
import { describe, beforeAll, beforeEach, afterAll, test, expect } from '@jest/globals';
8+
import { describe, beforeAll, beforeEach, afterAll, test, expect, afterEach } from '@jest/globals';
99
import testAssetWorkspace from './testAssets/testAssetWorkspace';
10-
import { activateCSharpExtension, getCodeLensesAsync, openFileInWorkspaceAsync } from './integrationHelpers';
10+
import {
11+
activateCSharpExtension,
12+
closeAllEditorsAsync,
13+
getCodeLensesAsync,
14+
openFileInWorkspaceAsync,
15+
} from './integrationHelpers';
1116
import { TestProgress } from '../../src/lsptoolshost/roslynProtocol';
1217

13-
describe(`[${testAssetWorkspace.description}] Test Unit Testing`, function () {
14-
beforeAll(async function () {
18+
describe(`[${testAssetWorkspace.description}] Test Unit Testing`, () => {
19+
beforeAll(async () => {
1520
await activateCSharpExtension();
1621
});
1722

18-
beforeEach(async function () {
23+
beforeEach(async () => {
1924
vscode.workspace
2025
.getConfiguration()
2126
.update('dotnet.unitTests.runSettingsPath', undefined, vscode.ConfigurationTarget.Workspace);
@@ -27,6 +32,10 @@ describe(`[${testAssetWorkspace.description}] Test Unit Testing`, function () {
2732
await testAssetWorkspace.cleanupWorkspace();
2833
});
2934

35+
afterEach(async () => {
36+
await closeAllEditorsAsync();
37+
});
38+
3039
test('Unit test code lens items are displayed', async () => {
3140
const codeLenses = await getCodeLensesAsync();
3241
expect(codeLenses).toHaveLength(9);

test/integrationTests/workspaceDiagnostics.integration.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import testAssetWorkspace from './testAssets/testAssetWorkspace';
99
import { AnalysisSetting } from '../../src/lsptoolshost/buildDiagnosticsService';
1010
import * as integrationHelpers from './integrationHelpers';
1111
import { getCode, setBackgroundAnalysisScopes, waitForExpectedDiagnostics } from './diagnosticsHelpers';
12-
describe(`[${testAssetWorkspace.description}] Test diagnostics`, function () {
13-
beforeAll(async function () {
12+
describe(`[${testAssetWorkspace.description}] Test diagnostics`, () => {
13+
beforeAll(async () => {
1414
await integrationHelpers.activateCSharpExtension();
1515
});
1616

0 commit comments

Comments
 (0)