import * as vscode from 'vscode' ; import { IActionContext } from 'vscode-azureextensionui' ; import { ApiOperationTreeItem } from "../explorer/ApiOperationTreeItem" ; import { ext } from '../extensionVariables' ; import { createTemporaryFile } from "../utils/fsUtil" ; import { nameUtil } from '../utils/nameUtil' ; import { writeToEditor } from '../utils/vscodeUtils' ; export async function testOperation ( context , node ? ) { if ( ! node ) { node = < ApiOperationTreeItem > await ext . tree . showTreeItemPicker ( ApiOperationTreeItem . contextValue , context ) ; } await createOperationTestFile ( node ! , OperationRunMode . test ) ; } export async function createOperationTestFile ( node , mode ) { const fileName = `${ nameUtil ( node . root ) }.http` ; const localFilePath = await createTemporaryFile ( fileName ) ; let data ; if ( mode === OperationRunMode . debug ) { data = await node . getOperationDebugInfo ( ) ; } else { data = await node . getOperationTestInfo ( ) ; } const document = await vscode . workspace . openTextDocument ( localFilePath ) ; const textEditor = await vscode . window . showTextDocument ( document ) ; await writeToEditor ( textEditor , data ) ; await textEditor . document . save ( ) ; return textEditor ; } export enum OperationRunMode { debug = "debug" , test = "test" }