import * as assert from "assert" ; import * as vscode from "vscode" ; import { configuration } from "../common/configuration" ; import { timeout } from "../common/utils" ; import { TaskExplorerApi } from "../extension" ; import * as log from "../common/log" ; export let teApi ; suite ( "Extension Tests" , ( ) => { setup ( async ( ) => { } ) ; teardown ( ( ) => { } ) ; test ( "Enable required testing options" , async function ( ) { this . timeout ( 10 * 1000 ) ; assert . ok ( vscode . extensions . getExtension ( "spmeesseman.vscode-taskexplorer" ) ) ; await initSettings ( ) ; await vscode . workspace . getConfiguration ( ) . update ( "terminal.integrated.shell.windows" , "C:\\Windows\\System32\\cmd.exe" , vscode . ConfigurationTarget . Workspace ) ; log . setWriteToConsole ( false ) ; } ) ; test ( "Get active extension" , async function ( ) { let wait = 0 ; const maxWait = 15 ; this . timeout ( 20 * 1000 ) ; const ext = vscode . extensions . getExtension ( "spmeesseman.vscode-taskexplorer" ) ; assert ( ext , "Could not find extension" ) ; if ( ! ext . isActive ) { console . log ( "        Manually activating extension for full coverage" ) ; try { teApi = await ext . activate ( ) ; } catch ( e ) { assert . fail ( "Failed to activate extension" ) ; } console . log ( "         ✔ Extension activated" ) ; } else { console . log ( "         ℹ Extension is already activated, coverage will not occur" ) ; console . log ( "         ℹ Remove the activation event from package.json before running tests" ) ; while ( ! ext . isActive && wait < maxWait * 10 ) { wait += 1 ; await timeout ( 100 ) ; } assert ( ! ext . isActive || wait < maxWait * 10 , "Extension did not finish activation within " + maxWait + " seconds" ) ; if ( ! teApi ) { console . log ( "         ℹ Reset Api" ) ; teApi = ext . exports ; } } assert ( teApi , "Exported API is empty" ) ; } ) ; test ( "Check tree providers" , function ( done ) { if ( ! teApi . explorerProvider ) { assert . fail ( "        ✘ Task Explorer tree instance does not exist" ) ; } if ( ! teApi . sidebarProvider ) { assert . fail ( "        ✘ Task Explorer sidebar tree instance does not exist" ) ; } done ( ) ; } ) ; test ( "Show log" , async function ( ) { await vscode . commands . executeCommand ( "taskExplorer.showOutput" , false ) ; await vscode . commands . executeCommand ( "taskExplorer.showOutput" , true ) ; } ) ; test ( "Cover pre-init cases" , async function ( ) { if ( ! teApi || ! teApi . explorerProvider ) { assert . fail ( "        ✘ Task Explorer tree instance does not exist" ) ; } await initSettings ( false ) ; teApi . explorerProvider . showSpecialTasks ( true ) ; teApi . explorerProvider . showSpecialTasks ( true , true ) ; await teApi . explorerProvider . refresh ( "tests" ) ; await initSettings ( ) ; } ) ; test ( "Check settings" , function ( done ) { if ( configuration . get < boolean > ( "enableAnt" ) === false ) { console . log ( "THE SETTINGS DID NOT TAKE!!!" ) ; } done ( ) ; } ) ; async function initSettings ( enable = true ) { await configuration . updateWs ( "enableExplorerView" , true ) ; await configuration . updateWs ( "enableSideBar" , true ) ; await configuration . updateWs ( "includeAnt" , [ "**/test.xml" , "**/emptytarget.xml" , "**/emtyproject.xml" , "**/hello.xml" ] ) ; await configuration . update ( "debug" , true ) ; await configuration . update ( "debugLevel" , 3 ) ; await configuration . updateWs ( "debug" , true ) ; await configuration . updateWs ( "debugLevel" , 3 ) ; await configuration . updateWs ( "useGulp" , false ) ; await configuration . updateWs ( "useAnt" , false ) ; await configuration . updateWs ( "groupSeparator" , "-" ) ; await configuration . updateWs ( "numLastTasks" , 10 ) ; await configuration . updateWs ( "groupMaxLevel" , 1 ) ; await configuration . updateWs ( "clickAction" , "Open" ) ; await configuration . updateWs ( "enableAnt" , enable ) ; await configuration . updateWs ( "enableAppPublisher" , enable ) ; await configuration . updateWs ( "enableBash" , enable ) ; await configuration . updateWs ( "enableBatch" , enable ) ; await configuration . updateWs ( "enableGradle" , enable ) ; await configuration . updateWs ( "enableGrunt" , enable ) ; await configuration . updateWs ( "enableGulp" , enable ) ; await configuration . updateWs ( "enableMake" , enable ) ; await configuration . updateWs ( "enableMaven" , enable ) ; await configuration . updateWs ( "enableNpm" , enable ) ; await configuration . updateWs ( "enableNsis" , enable ) ; await configuration . updateWs ( "enablePowershell" , enable ) ; await configuration . updateWs ( "enablePerl" , enable ) ; await configuration . updateWs ( "enablePython" , enable ) ; await configuration . updateWs ( "enablePipenv" , enable ) ; await configuration . updateWs ( "enableRuby" , enable ) ; await configuration . updateWs ( "enableTsc" , enable ) ; await configuration . updateWs ( "enableWorkspace" , enable ) ; await configuration . updateWs ( "groupWithSeparator" , enable ) ; await configuration . updateWs ( "groupSeparator" , "-" ) ; await configuration . updateWs ( "showLastTasks" , enable ) ; await configuration . updateWs ( "keepTermOnStop" , false ) ; await configuration . updateWs ( "readUserTasks" , enable ) ; await configuration . updateWs ( "showFavoritesButton" , enable ) ; await configuration . updateWs ( "showRunningTask" , enable ) ; } } ) ;