import * as process from 'process' ; import * as cp from 'child_process' ; import * as path from 'path' ; import * as io from '@actions/io' ; jest . setTimeout ( 15 * 1000 ) ; const tempDirectory = path . join ( __dirname , "temp Directory" ) ; const assetDirectory = path . join ( __dirname , 'theAssets' ) ; const buildDirectory = path . join ( assetDirectory , "builds" ) ; const testScript = path . join ( __dirname , '..' , 'dist' , 'index.js' ) ; const toolchainFile = path . join ( assetDirectory , 'toolchain.cmake' ) ; jest . setTimeout ( 15 * 1000 ) ; function envTest ( useShell , envVarValue ? ) { const TOOLCHAINFILE = "TOOLCHAINFILE" ; process . env [ TOOLCHAINFILE ] = envVarValue ; process . env . INPUT_USESHELL = useShell ? 'true' : 'false' ; process . env . INPUT_CMAKELISTSTXTPATH = path . join ( assetDirectory , 'CMakeLists.txt' ) ; process . env . INPUT_CONFIGUREPRESET = "default-toolchain" ; const options = { env : process . env , stdio : "inherit" , } ; console . log ( cp . execSync ( `node ${ testScript }` , options ) ?. toString ( ) ) ; } describe ( 'run-cmake functional tests' , ( ) => { beforeEach ( async ( ) => { await io . rmRF ( buildDirectory ) ; await io . rmRF ( tempDirectory ) ; await io . mkdirP ( buildDirectory ) ; await io . mkdirP ( tempDirectory ) ; Object . keys ( process . env ) . filter ( ( key ) => key . match ( /^INPUT_/ ) ) . forEach ( ( key ) => { delete process . env [ key ] ; } ) ; process . env . GITHUB_WORKSPACE = assetDirectory ; } , 300000 ) ; afterAll ( async ( ) => { try { await io . rmRF ( buildDirectory ) ; await io . rmRF ( tempDirectory ) ; } catch { console . log ( 'Failed to remove test directories' ) ; } } , 100000 ) ; test ( 'configure with Ninja Multi-Config' , ( ) => { process . env . INPUT_CONFIGUREPRESET = "default-multi" ; process . env . INPUT_CMAKELISTSTXTPATH = path . join ( assetDirectory , 'CMakeLists.txt' ) ; const options = { env : process . env , stdio : "inherit" } ; console . log ( cp . execSync ( `node ${ testScript }` , options ) ?. toString ( ) ) ; } ) ; test ( 'configure with Ninja' , ( ) => { process . env . INPUT_CONFIGUREPRESET = "default" ; process . env . INPUT_CMAKELISTSTXTPATH = path . join ( assetDirectory , 'CMakeLists.txt' ) ; const options = { env : process . env , stdio : "inherit" } ; console . log ( cp . execSync ( `node ${ testScript }` , options ) ?. toString ( ) ) ; } ) ; test ( 'configure and build and test with Ninja' , ( ) => { process . env . INPUT_CONFIGUREPRESET = "default" ; process . env . INPUT_BUILDPRESET = "default" ; process . env . INPUT_TESTPRESET = "default" ; process . env . INPUT_CMAKELISTSTXTPATH = path . join ( assetDirectory , 'CMakeLists.txt' ) ; const options = { env : process . env , stdio : "inherit" } ; console . log ( cp . execSync ( `node ${ testScript }` , options ) ?. toString ( ) ) ; } ) ; test ( 'configure and build test with Ninja (Multi-Config)' , ( ) => { process . env . INPUT_CONFIGUREPRESET = "default-multi" ; process . env . INPUT_BUILDPRESET = "default-multi" ; process . env . INPUT_TESTPRESET = "default-multi" ; process . env . INPUT_CMAKELISTSTXTPATH = path . join ( assetDirectory , 'CMakeLists.txt' ) ; const options = { env : process . env , stdio : "inherit" } ; console . log ( cp . execSync ( `node ${ testScript }` , options ) ?. toString ( ) ) ; } ) ; test ( 'basic test for environment variables in input, no shell, it must throw' , ( ) => { expect ( ( ) => envTest ( false , undefined ) ) . toThrow ( ) ; } ) ; test ( 'basic test for environment variables in input, with shell' , ( ) => { envTest ( true , toolchainFile ) ; } ) ; } ) ;