Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Close all text editors after each test. #7343

Merged
merged 1 commit into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions test/integrationTests/buildDiagnostics.integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,28 @@
*--------------------------------------------------------------------------------------------*/

import * as vscode from 'vscode';
import { describe, test, expect, beforeAll, afterAll } from '@jest/globals';
import { describe, test, expect, beforeAll, afterAll, beforeEach, afterEach } from '@jest/globals';
import testAssetWorkspace from './testAssets/testAssetWorkspace';
import { AnalysisSetting, BuildDiagnosticsService } from '../../src/lsptoolshost/buildDiagnosticsService';
import * as integrationHelpers from './integrationHelpers';
import path = require('path');
describe(`Build and live diagnostics dedupe ${testAssetWorkspace.description}`, function () {
beforeAll(async function () {
await integrationHelpers.openFileInWorkspaceAsync(path.join('src', 'app', 'inlayHints.cs'));
describe(`Build and live diagnostics dedupe ${testAssetWorkspace.description}`, () => {
beforeAll(async () => {
await integrationHelpers.activateCSharpExtension();
});

beforeEach(async () => {
await integrationHelpers.openFileInWorkspaceAsync(path.join('src', 'app', 'inlayHints.cs'));
});

afterAll(async () => {
await testAssetWorkspace.cleanupWorkspace();
});

afterEach(async () => {
await integrationHelpers.closeAllEditorsAsync();
});

test('OpenFiles diagnostics', async () => {
await setBackgroundAnalysisSetting(
/*analyzer*/ AnalysisSetting.OpenFiles,
Expand Down
19 changes: 14 additions & 5 deletions test/integrationTests/codelens.integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,21 @@
import * as lsp from 'vscode-languageserver-protocol';
import * as vscode from 'vscode';
import * as path from 'path';
import { describe, beforeAll, beforeEach, afterAll, test, expect } from '@jest/globals';
import { describe, beforeAll, beforeEach, afterAll, test, expect, afterEach } from '@jest/globals';
import testAssetWorkspace from './testAssets/testAssetWorkspace';
import { activateCSharpExtension, getCodeLensesAsync, openFileInWorkspaceAsync } from './integrationHelpers';
import {
activateCSharpExtension,
closeAllEditorsAsync,
getCodeLensesAsync,
openFileInWorkspaceAsync,
} from './integrationHelpers';

describe(`[${testAssetWorkspace.description}] Test CodeLens`, function () {
beforeAll(async function () {
describe(`[${testAssetWorkspace.description}] Test CodeLens`, () => {
beforeAll(async () => {
await activateCSharpExtension();
});

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

afterEach(async () => {
await closeAllEditorsAsync();
});

test('CodeLens references are displayed', async () => {
const codeLenses = await getCodeLensesAsync();
expect(codeLenses).toHaveLength(4);
Expand Down
6 changes: 3 additions & 3 deletions test/integrationTests/commandEnablement.integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@ import { activateCSharpExtension } from './integrationHelpers';
import testAssetWorkspace from './testAssets/testAssetWorkspace';
import { CommonCommands, OmniSharpCommands, RoslynCommands } from './expectedCommands';

describe(`Command Enablement: ${testAssetWorkspace.description}`, function () {
beforeAll(async function () {
describe(`Command Enablement: ${testAssetWorkspace.description}`, () => {
beforeAll(async () => {
await activateCSharpExtension();
});

afterAll(async () => {
await testAssetWorkspace.cleanupWorkspace();
});

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

// Ensure the standalone Roslyn commands are available.
Expand Down
14 changes: 9 additions & 5 deletions test/integrationTests/completion.integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@

import * as vscode from 'vscode';
import * as path from 'path';
import { describe, beforeAll, beforeEach, afterAll, test, expect } from '@jest/globals';
import { describe, beforeAll, beforeEach, afterAll, test, expect, afterEach } from '@jest/globals';
import testAssetWorkspace from './testAssets/testAssetWorkspace';
import { activateCSharpExtension, openFileInWorkspaceAsync } from './integrationHelpers';
import { activateCSharpExtension, closeAllEditorsAsync, openFileInWorkspaceAsync } from './integrationHelpers';

describe(`[${testAssetWorkspace.description}] Test Completion`, function () {
beforeAll(async function () {
describe(`[${testAssetWorkspace.description}] Test Completion`, () => {
beforeAll(async () => {
await activateCSharpExtension();
});

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

afterEach(async () => {
await closeAllEditorsAsync();
});

test('Returns completion items', async () => {
const completionList = await getCompletionsAsync(new vscode.Position(8, 12), undefined, 10);
expect(completionList.items.length).toBeGreaterThan(0);
Expand Down
13 changes: 9 additions & 4 deletions test/integrationTests/documentDiagnostics.integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@
*--------------------------------------------------------------------------------------------*/

import * as vscode from 'vscode';
import { describe, test, beforeAll, afterAll, expect } from '@jest/globals';
import { describe, test, beforeAll, afterAll, expect, beforeEach, afterEach } from '@jest/globals';
import testAssetWorkspace from './testAssets/testAssetWorkspace';
import { AnalysisSetting } from '../../src/lsptoolshost/buildDiagnosticsService';
import * as integrationHelpers from './integrationHelpers';
import path = require('path');
import { getCode, setBackgroundAnalysisScopes, waitForExpectedDiagnostics } from './diagnosticsHelpers';
describe(`[${testAssetWorkspace.description}] Test diagnostics`, function () {
beforeAll(async function () {

describe(`[${testAssetWorkspace.description}] Test diagnostics`, () => {
beforeAll(async () => {
await integrationHelpers.activateCSharpExtension();
});

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

describe('Open document diagnostics', () => {
let file: vscode.Uri;
beforeAll(async () => {
beforeEach(async () => {
file = await integrationHelpers.openFileInWorkspaceAsync(path.join('src', 'app', 'diagnostics.cs'));
});

afterEach(async () => {
await integrationHelpers.closeAllEditorsAsync();
});

test('Compiler and analyzer diagnostics reported for open file when set to OpenFiles', async () => {
await setBackgroundAnalysisScopes({
compiler: AnalysisSetting.OpenFiles,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,20 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { expect, test, beforeAll, afterAll, describe } from '@jest/globals';
import { expect, test, beforeAll, afterAll, describe, afterEach, beforeEach } from '@jest/globals';
import * as vscode from 'vscode';
import * as path from 'path';
import testAssetWorkspace from './testAssets/testAssetWorkspace';
import { activateCSharpExtension, openFileInWorkspaceAsync } from './integrationHelpers';
import { activateCSharpExtension, closeAllEditorsAsync, openFileInWorkspaceAsync } from './integrationHelpers';

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

beforeAll(async function () {
beforeAll(async () => {
await activateCSharpExtension();
});

beforeEach(async () => {
const relativePath = path.join('src', 'app', 'documentSymbols.cs');
fileUri = await openFileInWorkspaceAsync(relativePath);
});
Expand All @@ -22,7 +25,11 @@ describe(`DocumentSymbolProvider: ${testAssetWorkspace.description}`, function (
await testAssetWorkspace.cleanupWorkspace();
});

test('Returns all elements', async function () {
afterEach(async () => {
await closeAllEditorsAsync();
});

test('Returns all elements', async () => {
const symbols = await GetDocumentSymbols(fileUri);

expect(symbols).toHaveLength(5);
Expand Down
14 changes: 9 additions & 5 deletions test/integrationTests/gotoDefinition.integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,26 @@
import * as vscode from 'vscode';
import * as path from 'path';
import testAssetWorkspace from './testAssets/testAssetWorkspace';
import { activateCSharpExtension, openFileInWorkspaceAsync } from './integrationHelpers';
import { describe, beforeAll, beforeEach, afterAll, test, expect } from '@jest/globals';
import { activateCSharpExtension, closeAllEditorsAsync, openFileInWorkspaceAsync } from './integrationHelpers';
import { describe, beforeAll, beforeEach, afterAll, test, expect, afterEach } from '@jest/globals';

describe(`[${testAssetWorkspace.description}] Test Go To Definition`, function () {
beforeAll(async function () {
describe(`[${testAssetWorkspace.description}] Test Go To Definition`, () => {
beforeAll(async () => {
await activateCSharpExtension();
});

beforeEach(async function () {
beforeEach(async () => {
await openFileInWorkspaceAsync(path.join('src', 'app', 'definition.cs'));
});

afterAll(async () => {
await testAssetWorkspace.cleanupWorkspace();
});

afterEach(async () => {
await closeAllEditorsAsync();
});

test('Navigates to definition in same file', async () => {
const requestPosition = new vscode.Position(10, 31);
const definitionList = <vscode.Location[]>(
Expand Down
4 changes: 4 additions & 0 deletions test/integrationTests/integrationHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ export async function openFileInWorkspaceAsync(relativeFilePath: string): Promis
return uri;
}

export async function closeAllEditorsAsync(): Promise<void> {
await vscode.commands.executeCommand('workbench.action.closeAllEditors');
}

/**
* Reverts any unsaved changes to the active file.
* Useful to reset state between tests without fully reloading everything.
Expand Down
15 changes: 11 additions & 4 deletions test/integrationTests/lspInlayHints.integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@

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

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

await integrationHelpers.openFileInWorkspaceAsync(path.join('src', 'app', 'inlayHints.cs'));
await integrationHelpers.activateCSharpExtension();
});

beforeEach(async () => {
await integrationHelpers.openFileInWorkspaceAsync(path.join('src', 'app', 'inlayHints.cs'));
});

afterAll(async () => {
await testAssetWorkspace.cleanupWorkspace();
});

afterEach(async () => {
await integrationHelpers.closeAllEditorsAsync();
});

test('Hints retrieved for region', async () => {
const range = new vscode.Range(new vscode.Position(4, 8), new vscode.Position(15, 85));
const activeDocument = vscode.window.activeTextEditor?.document.uri;
Expand Down
8 changes: 5 additions & 3 deletions test/integrationTests/onAutoInsert.integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,26 @@ import * as path from 'path';
import testAssetWorkspace from './testAssets/testAssetWorkspace';
import {
activateCSharpExtension,
closeAllEditorsAsync,
openFileInWorkspaceAsync,
revertActiveFile,
sleep,
waitForExpectedResult,
} from './integrationHelpers';
import { describe, beforeAll, beforeEach, afterAll, test, expect, afterEach } from '@jest/globals';

describe(`[${testAssetWorkspace.description}] Test OnAutoInsert`, function () {
beforeAll(async function () {
describe(`[${testAssetWorkspace.description}] Test OnAutoInsert`, () => {
beforeAll(async () => {
await activateCSharpExtension();
});

beforeEach(async function () {
beforeEach(async () => {
await openFileInWorkspaceAsync(path.join('src', 'app', 'DocComments.cs'));
});

afterEach(async () => {
await revertActiveFile();
await closeAllEditorsAsync();
});

afterAll(async () => {
Expand Down
19 changes: 14 additions & 5 deletions test/integrationTests/unitTests.integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,22 @@

import * as vscode from 'vscode';
import * as path from 'path';
import { describe, beforeAll, beforeEach, afterAll, test, expect } from '@jest/globals';
import { describe, beforeAll, beforeEach, afterAll, test, expect, afterEach } from '@jest/globals';
import testAssetWorkspace from './testAssets/testAssetWorkspace';
import { activateCSharpExtension, getCodeLensesAsync, openFileInWorkspaceAsync } from './integrationHelpers';
import {
activateCSharpExtension,
closeAllEditorsAsync,
getCodeLensesAsync,
openFileInWorkspaceAsync,
} from './integrationHelpers';
import { TestProgress } from '../../src/lsptoolshost/roslynProtocol';

describe(`[${testAssetWorkspace.description}] Test Unit Testing`, function () {
beforeAll(async function () {
describe(`[${testAssetWorkspace.description}] Test Unit Testing`, () => {
beforeAll(async () => {
await activateCSharpExtension();
});

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

afterEach(async () => {
await closeAllEditorsAsync();
});

test('Unit test code lens items are displayed', async () => {
const codeLenses = await getCodeLensesAsync();
expect(codeLenses).toHaveLength(9);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import testAssetWorkspace from './testAssets/testAssetWorkspace';
import { AnalysisSetting } from '../../src/lsptoolshost/buildDiagnosticsService';
import * as integrationHelpers from './integrationHelpers';
import { getCode, setBackgroundAnalysisScopes, waitForExpectedDiagnostics } from './diagnosticsHelpers';
describe(`[${testAssetWorkspace.description}] Test diagnostics`, function () {
beforeAll(async function () {
describe(`[${testAssetWorkspace.description}] Test diagnostics`, () => {
beforeAll(async () => {
await integrationHelpers.activateCSharpExtension();
});

Expand Down
Loading