import * as functionsJsonData from "./test-data.json" ; import { pingTestServer , sendTestResults } from "office-addin-test-helpers" ; import { closeWorkbook , sleep } from "./test-helpers" ; const customFunctionsData = ( < any > functionsJsonData ) . functions ; const port = 4201 ; let testValues = [ ] ; Office . initialize = async ( ) => { document . getElementById ( "sideload-msg" ) . style . display = "none" ; document . getElementById ( "app-body" ) . style . display = "flex" ; document . getElementById ( "run" ) . onclick = run ; const testServerResponse = await pingTestServer ( port ) ; if ( testServerResponse [ "status" ] === 200 ) { await runCfTests ( ) ; await sendTestResults ( testValues , port ) ; await closeWorkbook ( ) ; } } ; async function runCfTests ( ) { await Excel . run ( async ( context ) => { for ( let key in customFunctionsData ) { const formula = customFunctionsData [ key ] . formula ; const range = context . workbook . getSelectedRange ( ) ; range . formulas = [ [ formula ] ] ; await context . sync ( ) ; await sleep ( 5000 ) ; await readCFData ( key , customFunctionsData [ key ] . streaming != undefined ? 2 : 1 ) ; } } ) ; } export async function readCFData ( cfName , readCount ) { await Excel . run ( async ( context ) => { for ( let i = 0 ; i < readCount ; i ++ ) { try { const range = context . workbook . getSelectedRange ( ) ; range . load ( "values" ) ; await context . sync ( ) ; await sleep ( 5000 ) ; addTestResult ( cfName , range . values [ 0 ] [ 0 ] ) ; Promise . resolve ( ) ; } catch { Promise . reject ( ) ; } } } ) ; } function addTestResult ( resultName , resultValue ) { var data = { } ; var nameKey = "Name" ; var valueKey = "Value" ; data [ nameKey ] = resultName ; data [ valueKey ] = resultValue ; testValues . push ( data ) ; }