Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1613c44

Browse files
committed
Setup some tests
1 parent c5679b7 commit 1613c44

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

tests/index.test.ts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import { exec } from "child_process";
2+
import { promisify } from "util";
3+
import { expect, use } from "chai";
4+
import chaiAsPromised = require("chai-as-promised");
5+
6+
use(chaiAsPromised);
7+
8+
/**
9+
* Returns a boolean indicating whether the given command ran successfully or not.
10+
* @param args
11+
*/
12+
async function runCommandWithArgs(args: string[]): Promise<boolean> {
13+
const childProcPromise = promisify(exec)(
14+
["node", "dist/index.js", ...args].join(" ")
15+
);
16+
try {
17+
await childProcPromise;
18+
} catch (e: unknown) {
19+
return false;
20+
}
21+
22+
return true;
23+
}
24+
25+
async function runCommandWithArgsForOutput(
26+
args: string[]
27+
): Promise<{ stdout: string; stderr: string }> {
28+
const childProcPromise = promisify(exec)(
29+
["node", "dist/index.js", ...args].join(" ")
30+
);
31+
try {
32+
return await childProcPromise;
33+
} catch (e: any) {
34+
// Error object has stdout/stderr
35+
return e;
36+
}
37+
}
38+
39+
describe("github-run-script base tests", () => {
40+
it("should not run with no arguments", () =>
41+
expect(runCommandWithArgs([])).to.eventually.equal(false));
42+
it("should do nothing", () =>
43+
expect(runCommandWithArgs(["env"])).to.eventually.equal(true));
44+
it("should have the repo name", () =>
45+
expect(
46+
runCommandWithArgsForOutput(["env", "PythonCoderAS/github-run-script"])
47+
)
48+
.to.eventually.have.property("stdout")
49+
.which.contain("PythonCoderAS/github-run-script"));
50+
});

0 commit comments

Comments
 (0)