|
| 1 | +/*--------------------------------------------------------- |
| 2 | + * Copyright (C) Microsoft Corporation. All rights reserved. |
| 3 | + *--------------------------------------------------------*/ |
| 4 | + |
| 5 | +import vscode = require('vscode'); |
| 6 | +import utils = require('../utils'); |
| 7 | +import Window = vscode.window; |
| 8 | +import ChildProcess = require('child_process'); |
| 9 | +import { SessionManager } from '../session'; |
| 10 | +import { IFeature, LanguageClient } from '../feature'; |
| 11 | + |
| 12 | +export class PesterTestsFeature implements IFeature { |
| 13 | + |
| 14 | + private command: vscode.Disposable; |
| 15 | + private languageClient: LanguageClient; |
| 16 | + |
| 17 | + constructor(private sessionManager: SessionManager) { |
| 18 | + this.command = vscode.commands.registerCommand( |
| 19 | + 'PowerShell.RunPesterTests', |
| 20 | + (uriString, runInDebugger, describeBlockName?) => { |
| 21 | + this.launchTests(uriString, runInDebugger, describeBlockName); |
| 22 | + }); |
| 23 | + } |
| 24 | + |
| 25 | + public setLanguageClient(languageClient: LanguageClient) { |
| 26 | + this.languageClient = languageClient; |
| 27 | + } |
| 28 | + |
| 29 | + public dispose() { |
| 30 | + this.command.dispose(); |
| 31 | + } |
| 32 | + |
| 33 | + private launchTests(uriString, runInDebugger, describeBlockName?) { |
| 34 | + var uri = vscode.Uri.parse(uriString); |
| 35 | + let currentDocument = vscode.window.activeTextEditor.document; |
| 36 | + |
| 37 | + let launchConfig = { |
| 38 | + request: "launch", |
| 39 | + type: "PowerShell", |
| 40 | + script: "Invoke-Pester", |
| 41 | + args: [ |
| 42 | + `-Script "${uri.fsPath}"`, |
| 43 | + describeBlockName |
| 44 | + ? `-TestName "${describeBlockName}"` |
| 45 | + : "" |
| 46 | + ], |
| 47 | + internalConsoleOptions: "neverOpen", |
| 48 | + noDebug: !runInDebugger, |
| 49 | + cwd: |
| 50 | + currentDocument.isUntitled |
| 51 | + ? vscode.workspace.rootPath |
| 52 | + : currentDocument.fileName |
| 53 | + } |
| 54 | + |
| 55 | + // Create or show the interactive console |
| 56 | + // TODO #367: Check if "newSession" mode is configured |
| 57 | + vscode.commands.executeCommand('PowerShell.ShowSessionConsole', true); |
| 58 | + |
| 59 | + // Write out temporary debug session file |
| 60 | + utils.writeSessionFile( |
| 61 | + utils.getDebugSessionFilePath(), |
| 62 | + this.sessionManager.getSessionDetails()); |
| 63 | + |
| 64 | + vscode.commands.executeCommand('vscode.startDebug', launchConfig); |
| 65 | + } |
| 66 | +} |
0 commit comments