Skip to content

Commit 9aab76e

Browse files
committed
Add extension unit testing infrastructure
This change enables Mocha-based unit tests for the PowerShell extension using VS Code's embedded test running mode.
1 parent 88e8e90 commit 9aab76e

12 files changed

+42
-15
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ vscode-powershell.zip
1111
vscps-preview.zip
1212
*.vsix
1313
npm-debug.log
14+
.vscode-test/

.vscode/launch.json

+13-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"args": [ "--extensionDevelopmentPath=${workspaceRoot}" ],
1010
"stopOnEntry": false,
1111
"sourceMaps": true,
12-
"outFiles": ["${workspaceRoot}/out"],
12+
"outFiles": ["${workspaceRoot}/out/src/**/*.js"],
1313
"preLaunchTask": "BuildAll"
1414
},
1515
{
@@ -20,7 +20,18 @@
2020
"args": [ "--extensionDevelopmentPath=${workspaceRoot}" ],
2121
"stopOnEntry": false,
2222
"sourceMaps": true,
23-
"outFiles": ["${workspaceRoot}/out"],
23+
"outFiles": ["${workspaceRoot}/out/src/**/*.js"],
24+
"preLaunchTask": "Build"
25+
},
26+
{
27+
"name": "Launch Extension Tests",
28+
"type": "extensionHost",
29+
"request": "launch",
30+
"runtimeExecutable": "${execPath}",
31+
"args": ["--extensionDevelopmentPath=${workspaceRoot}", "--extensionTestsPath=${workspaceRoot}/out/test" ],
32+
"stopOnEntry": false,
33+
"sourceMaps": true,
34+
"outFiles": ["${workspaceRoot}/out/test/**/*.js"],
2435
"preLaunchTask": "Build"
2536
},
2637
{

.vscodeignore

+3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
.vscode/**
2+
.vscode-test/**
23
vscode-powershell.build.ps1
34
typings/**
45
**/*.ts
@@ -10,5 +11,7 @@ bin/DebugAdapter.log
1011
bin/*.vshost.*
1112
bin/PowerShell/**
1213
logs/**
14+
out/test/**
15+
test/**
1316
sessions/**
1417
scripts/Install-VSCode.ps1

package.json

+7-4
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"type": "git",
2525
"url": "https://github.com/PowerShell/vscode-powershell.git"
2626
},
27-
"main": "./out/main",
27+
"main": "./out/src/main",
2828
"activationEvents": [
2929
"onLanguage:powershell",
3030
"onCommand:PowerShell.NewProjectFromTemplate",
@@ -41,15 +41,18 @@
4141
"@types/node": "^6.0.40",
4242
"typescript": "^2.0.3",
4343
"vsce": "^1.18.0",
44-
"vscode": "^1.1.0"
44+
"vscode": "^1.1.0",
45+
"mocha": "^2.3.3",
46+
"@types/mocha": "^2.2.32"
4547
},
4648
"extensionDependencies": [
4749
"vscode.powershell"
4850
],
4951
"scripts": {
5052
"compile": "tsc -p ./",
5153
"compile-watch": "tsc -watch -p ./",
52-
"postinstall": "node ./node_modules/vscode/bin/install"
54+
"postinstall": "node ./node_modules/vscode/bin/install",
55+
"test": "node ./node_modules/vscode/bin/test"
5356
},
5457
"contributes": {
5558
"keybindings": [
@@ -188,7 +191,7 @@
188191
"powershell"
189192
]
190193
},
191-
"program": "./out/debugAdapter.js",
194+
"program": "./out/src/debugAdapter.js",
192195
"runtime": "node",
193196
"variables": {
194197
"PickPSHostProcess": "PowerShell.PickPSHostProcess",

src/debugAdapter.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { Logger } from './logging';
1414
// named pipes or a network protocol). It is purely a naive data
1515
// relay between the two transports.
1616

17-
var logBasePath = path.resolve(__dirname, "../logs");
17+
var logBasePath = path.resolve(__dirname, "../../logs");
1818

1919
var debugAdapterLogWriter =
2020
fs.createWriteStream(

src/features/Examples.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export class ExamplesFeature implements IFeature {
1212
private examplesPath: string;
1313

1414
constructor() {
15-
this.examplesPath = path.resolve(__dirname, "../../examples");
15+
this.examplesPath = path.resolve(__dirname, "../../../examples");
1616
this.command = vscode.commands.registerCommand('PowerShell.OpenExamplesFolder', () => {
1717
vscode.commands.executeCommand(
1818
"vscode.openFolder",

src/logging.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export class Logger {
2929
constructor() {
3030
this.logChannel = vscode.window.createOutputChannel("PowerShell Extension Logs");
3131

32-
this.logBasePath = path.resolve(__dirname, "../logs");
32+
this.logBasePath = path.resolve(__dirname, "../../logs");
3333
utils.ensurePathExists(this.logBasePath);
3434

3535
this.commands = [

src/main.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ function checkForUpdatedVersion(context: vscode.ExtensionContext) {
161161
if (choice === showReleaseNotes) {
162162
vscode.commands.executeCommand(
163163
'markdown.showPreview',
164-
vscode.Uri.file(path.resolve(__dirname, "../CHANGELOG.md")));
164+
vscode.Uri.file(path.resolve(__dirname, "../../CHANGELOG.md")));
165165
}
166166
});
167167
}

src/process.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export class PowerShellProcess {
4040
let startScriptPath =
4141
path.resolve(
4242
__dirname,
43-
'../scripts/Start-EditorServices.ps1');
43+
'../../scripts/Start-EditorServices.ps1');
4444

4545
var editorServicesLogPath = this.log.getLogFilePath(logFileName);
4646

@@ -77,7 +77,7 @@ export class PowerShellProcess {
7777
// NOTE: This batch file approach is needed temporarily until VS Code's
7878
// createTerminal API gets an argument for setting environment variables
7979
// on the launched process.
80-
var batScriptPath = path.resolve(__dirname, '../sessions/powershell.bat');
80+
var batScriptPath = path.resolve(__dirname, '../../sessions/powershell.bat');
8181
fs.writeFileSync(
8282
batScriptPath,
8383
`@set DEVPATH=${path.dirname(powerShellExePath)}\r\n@${powerShellExePath} %*`);

src/session.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -121,15 +121,15 @@ export class SessionManager implements Middleware {
121121

122122
if (this.powerShellExePath) {
123123

124-
var bundledModulesPath = path.resolve(__dirname, "../modules");
124+
var bundledModulesPath = path.resolve(__dirname, "../../modules");
125125

126126
if (this.inDevelopmentMode) {
127127
var devBundledModulesPath =
128128
// this.sessionSettings.developer.bundledModulesPath ||
129129
path.resolve(
130130
__dirname,
131131
this.sessionSettings.developer.bundledModulesPath ||
132-
"../../PowerShellEditorServices/module");
132+
"../../../PowerShellEditorServices/module");
133133

134134
// Make sure the module's bin path exists
135135
if (fs.existsSync(path.join(devBundledModulesPath, "PowerShellEditorServices/bin"))) {

src/utils.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export interface WaitForSessionFileCallback {
5252
(details: EditorServicesSessionDetails, error: string): void;
5353
}
5454

55-
let sessionsFolder = path.resolve(__dirname, "..", "sessions/");
55+
let sessionsFolder = path.resolve(__dirname, "..", "..", "sessions/");
5656
let sessionFilePathPrefix = path.resolve(sessionsFolder, "PSES-VSCode-" + process.env.VSCODE_PID);
5757

5858
// Create the sessions path if it doesn't exist already

test/index.ts

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
var testRunner = require('vscode/lib/testrunner');
2+
3+
// See https://github.com/mochajs/mocha/wiki/Using-mocha-programmatically#set-options for options
4+
testRunner.configure({
5+
ui: 'tdd', // the TDD UI is being used in extension.test.ts (suite, test, etc.)
6+
useColors: true // colored output from test results
7+
});
8+
9+
module.exports = testRunner;

0 commit comments

Comments
 (0)