-
Notifications
You must be signed in to change notification settings - Fork 510
/
Copy pathRunCode.test.ts
59 lines (48 loc) · 2.03 KB
/
RunCode.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
import * as assert from "assert";
import * as fs from "fs";
import * as path from "path";
import rewire = require("rewire");
import vscode = require("vscode");
import utils = require("../utils");
import { sleep } from "../../src/utils";
// Setup function that is not exported.
const customViews = rewire("../../src/features/RunCode");
const createLaunchConfig = customViews.__get__("createLaunchConfig");
enum LaunchType {
Debug,
Run,
}
describe("RunCode feature", function () {
before(utils.ensureEditorServicesIsConnected);
it("Creates the launch config", function () {
const commandToRun: string = "Invoke-Build";
const args: string[] = ["Clean"];
const expected: object = {
request: "launch",
type: "PowerShell",
name: "PowerShell Run Code",
script: commandToRun,
args,
internalConsoleOptions: "neverOpen",
noDebug: false,
createTemporaryIntegratedConsole: false,
cwd: vscode.workspace.rootPath,
};
const actual: object = createLaunchConfig(LaunchType.Debug, commandToRun, args);
assert.deepStrictEqual(actual, expected);
});
it("Runs Pester tests from a file", async function () {
const pesterTests = path.resolve(__dirname, "../../../examples/Tests/SampleModule.Tests.ps1");
assert(fs.existsSync(pesterTests));
// Open the PowerShell file with Pester tests and then wait a while for
// the extension to finish connecting to the server.
await vscode.commands.executeCommand("vscode.open", vscode.Uri.file(pesterTests));
// Now run the Pester tests, check the debugger started, wait a bit for
// it to run, and then kill it for safety's sake.
assert(await vscode.commands.executeCommand("PowerShell.RunPesterTestsFromFile"));
assert(vscode.debug.activeDebugSession !== undefined);
await vscode.debug.stopDebugging();
});
});