import { extensionId , extSuffix } from '../constants' ; import { Settings } from "../enums" ; import { Commands } from "../enums" ; import * as assert from 'assert' ; import * as vscode from 'vscode' ; interface ICommand { title : string ; command : string ; category : string ; } interface IConfiguration { type : string ; title : string ; properties : any ; } export type EnumIndexer = { [ Key ] : string ; } ; suite ( "Extension Tests" , function ( ) { let extension ; setup ( function ( ) { const ext = vscode . extensions . getExtension ( extensionId ) ; if ( ! ext ) { throw new Error ( 'Extension was not found.' ) ; } if ( ext ) { extension = ext ; } } ) ; /**
     * Because we are waiting on a process to complete in the background
     * we use the `done` function to inform mocha that this test run is
     * complete.
     */ test ( "Extension loads in VSCode and is active" , function ( done ) { setTimeout ( function ( ) { assert . equal ( extension . isActive , true ) ; done ( ) ; } , 200 ) ; } ) ; test ( "constants.Commands exist in package.json" , function ( ) { const commandCollection = extension . packageJSON . contributes . commands ; for ( let command in Commands ) { const result = commandCollection . some ( c => c . command === ( Commands as any ) [ command ] ) ; assert . ok ( result ) ; } } ) ; test ( "constants.Settings exist in package.json" , function ( ) { const config = extension . packageJSON . contributes . configuration ; const properties = Object . keys ( config . properties ) ; for ( let setting in Settings ) { const result = properties . some ( property => property === `${ extSuffix }.${ ( Settings as any ) [ setting ] }` ) ; assert . ok ( result ) ; } } ) ; test ( 'package.json commands registered in extension' , function ( done ) { const commandStrings = extension . packageJSON . contributes . commands . map ( ( c ) => c . command ) ; vscode . commands . getCommands ( true ) . then ( ( allCommands ) => { const commands = allCommands . filter ( c => c . startsWith ( `${ extSuffix }.` ) ) ; commands . forEach ( command => { const result = commandStrings . some ( c => c === command ) ; assert . ok ( result ) ; } ) ; done ( ) ; } ) ; } ) ; } ) ;