Skip to content

Commit 3697572

Browse files
committed
Fix race condition in RunPesterTestsFromFile test
1 parent c67256e commit 3697572

File tree

2 files changed

+25
-11
lines changed

2 files changed

+25
-11
lines changed

src/features/PesterTests.ts

+5-6
Original file line numberDiff line numberDiff line change
@@ -132,18 +132,17 @@ export class PesterTestsFeature implements vscode.Disposable {
132132
private async launch(launchConfig): Promise<boolean> {
133133
// Create or show the interactive console
134134
// TODO: #367 Check if "newSession" mode is configured
135-
vscode.commands.executeCommand("PowerShell.ShowSessionConsole", true);
135+
await vscode.commands.executeCommand("PowerShell.ShowSessionConsole", true);
136136

137137
// Write out temporary debug session file
138138
utils.writeSessionFile(
139139
utils.getDebugSessionFilePath(),
140140
this.sessionManager.getSessionDetails());
141141

142142
// TODO: Update to handle multiple root workspaces.
143-
//
144-
// Ensure the necessary script exists (for testing). The debugger will
145-
// start regardless, but we also pass its success along.
146-
return utils.fileExists(this.invokePesterStubScriptPath)
147-
&& vscode.debug.startDebugging(vscode.workspace.workspaceFolders[0], launchConfig);
143+
await vscode.debug.startDebugging(vscode.workspace.workspaceFolders[0], launchConfig);
144+
145+
// Ensure the necessary script exists (for testing).
146+
return utils.fileExists(this.invokePesterStubScriptPath);
148147
}
149148
}

test/features/RunCode.test.ts

+20-5
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@
44
import * as assert from "assert";
55
import * as fs from "fs";
66
import * as path from "path";
7-
import { suiteSetup } from "mocha";
87
import rewire = require("rewire");
98
import vscode = require("vscode");
109
import utils = require("../utils");
10+
import { sleep } from "../../src/utils";
11+
import { IPowerShellExtensionClient } from "../../src/features/ExternalApi";
1112

1213
// Setup function that is not exported.
1314
const customViews = rewire("../../src/features/RunCode");
@@ -19,8 +20,6 @@ enum LaunchType {
1920
}
2021

2122
suite("RunCode tests", () => {
22-
suiteSetup(utils.ensureExtensionIsActivated);
23-
2423
test("Can create the launch config", () => {
2524
const commandToRun: string = "Invoke-Build";
2625
const args: string[] = ["Clean"];
@@ -45,8 +44,24 @@ suite("RunCode tests", () => {
4544
test("Can run Pester tests from file", async () => {
4645
const pesterTests = path.resolve(__dirname, "../../../examples/Tests/SampleModule.Tests.ps1");
4746
assert(fs.existsSync(pesterTests));
47+
48+
// Get interface to extension.
49+
const extension = await utils.ensureExtensionIsActivated();
50+
const client = extension!.exports as IPowerShellExtensionClient;
51+
const sessionId = client.registerExternalExtension(utils.extensionId);
52+
53+
// Force PowerShell extension to finish connecting. This is necessary
54+
// because we can't start the PowerShell debugger until the session is
55+
// connected, which is different from the extension being activated. We
56+
// also need to open the file so the command has it as its argument.
4857
await vscode.commands.executeCommand("vscode.open", vscode.Uri.file(pesterTests));
58+
await client.getPowerShellVersionDetails(sessionId);
59+
60+
// Now run the Pester tests.
4961
assert(await vscode.commands.executeCommand("PowerShell.RunPesterTestsFromFile"));
50-
// Start up can take some time...so set the timeout to 30 seconds.
51-
}).timeout(30000);
62+
assert(vscode.debug.activeDebugSession !== undefined);
63+
await sleep(5000);
64+
await vscode.debug.stopDebugging(vscode.debug.activeDebugSession);
65+
// PowerShell can take a while, so set the timeout to a full minute.
66+
}).timeout(60000);
5267
});

0 commit comments

Comments
 (0)