|
1 | 1 | import spawn from "cross-spawn"
|
2 | 2 | import { pathExists } from "path-exists"
|
3 |
| -import { join } from "path/posix" |
4 |
| -import { addExeExt } from "patha" |
| 3 | +import { addExeExt, join } from "patha" |
5 | 4 | import which from "which"
|
6 | 5 |
|
7 | 6 | export async function testBin(
|
8 | 7 | name: string,
|
9 | 8 | args: string[] | null = ["--version"],
|
10 | 9 | binDir: string | undefined = undefined,
|
11 | 10 | ) {
|
12 |
| - try { |
13 |
| - let bin = name |
14 |
| - if (typeof binDir === "string") { |
15 |
| - console.log(`Testing the existence of ${binDir}`) |
16 |
| - expect(binDir).toBeDefined() |
17 |
| - expect(binDir).not.toHaveLength(0) |
18 |
| - expect(await pathExists(binDir)).toBeTruthy() |
19 |
| - bin = join(binDir, addExeExt(name)) |
20 |
| - } |
21 |
| - |
22 |
| - if (args !== null) { |
23 |
| - console.log(`Running ${bin} ${args.join(" ")}`) |
24 |
| - const { status } = spawn.sync(bin, args, { stdio: "inherit" }) |
25 |
| - expect(status).toBe(0) |
26 |
| - } |
| 11 | + let bin = name |
| 12 | + if (typeof binDir === "string") { |
| 13 | + console.log(`Testing the existence of ${binDir}`) |
| 14 | + expect(binDir).toBeDefined() |
| 15 | + expect(binDir).not.toHaveLength(0) |
| 16 | + expect(await pathExists(binDir)).toBeTruthy() |
| 17 | + bin = join(binDir, addExeExt(name)) |
| 18 | + } |
27 | 19 |
|
28 |
| - expect((await which(name, { nothrow: true }))?.includes(bin)) |
29 |
| - } catch (err) { |
30 |
| - throw new Error(`Failed to test bin ${name}: ${err}`) |
| 20 | + if (args !== null) { |
| 21 | + console.log(`Running ${bin} ${args.join(" ")}`) |
| 22 | + const { status } = spawn.sync(bin, args, { stdio: "inherit" }) |
| 23 | + expect(status).toBe(0) |
31 | 24 | }
|
| 25 | + |
| 26 | + expect((await which(name, { nothrow: true }))?.includes(bin)) |
32 | 27 | }
|
0 commit comments