fix: spawn the bin in the tests

This commit is contained in:
Amin Yahyaabadi 2021-09-14 09:04:39 -05:00
parent 9bf59efb6c
commit 4824306aab
3 changed files with 17 additions and 2 deletions

View File

@ -1,6 +1,8 @@
import { setupCmake } from "../cmake"
import { spawnSync as spawn } from "child_process"
import { setupTmpDir, cleanupTmpDir } from "../../utils/tests/test-helpers"
import { addBinExtension } from "../../utils/setup/setupBin"
import { join } from "path"
jest.setTimeout(100000)
@ -19,7 +21,9 @@ describe("setup-cmake", () => {
expect(cmakePath).toBeDefined()
expect(cmakePath).not.toHaveLength(0)
const { status, error } = spawn(cmakePath, ["--version"], {
const cmakeBin = join(cmakePath, addBinExtension("cmake"))
const { status, error } = spawn(cmakeBin, ["--version"], {
encoding: "utf8",
})
expect(error).toBeUndefined()

View File

@ -1,6 +1,8 @@
import { setupNinja } from "../ninja"
import { spawnSync as spawn } from "child_process"
import { setupTmpDir, cleanupTmpDir } from "../../utils/tests/test-helpers"
import { addBinExtension } from "../../utils/setup/setupBin"
import { join } from "path"
jest.setTimeout(100000)
@ -19,7 +21,9 @@ describe("setup-ninja", () => {
expect(ninjaPath).toBeDefined()
expect(ninjaPath).not.toHaveLength(0)
const { status } = spawn(ninjaPath, ["--version"], {
const ninjaBin = join(ninjaPath, addBinExtension("ninja"))
const { status } = spawn(ninjaBin, ["--version"], {
encoding: "utf8",
})
expect(status).toBe(0)

View File

@ -75,3 +75,10 @@ export async function setupPackage(
return installDir
}
/** Add bin extension to a binary. This will be `.exe` on Windows. */
export function addBinExtension(name: string) {
if (process.platform === "win32") {
return `${name}.exe`
}
return name
}