Skip to content
This repository was archived by the owner on Sep 16, 2024. It is now read-only.

Commit 017a851

Browse files
committed
Add tests
1 parent 05a337f commit 017a851

File tree

3 files changed

+45
-43
lines changed

3 files changed

+45
-43
lines changed

package-lock.json

Lines changed: 0 additions & 41 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,9 @@
2828
},
2929
"devDependencies": {
3030
"@types/chai": "^4.3.1",
31-
"@types/chai-as-promised": "^7.1.5",
3231
"@types/mocha": "^9.1.1",
3332
"@types/node": "^18.0.0",
3433
"chai": "^4.3.6",
35-
"chai-as-promised": "^7.1.1",
3634
"eslint": "^8.19.0",
3735
"eslint-config-prettier": "^8.5.0",
3836
"eslint-config-pythoncoderas-combo": "^1.1.2",

tests/index.test.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import { expect } from "chai";
2+
import getToken from "../src";
3+
4+
const starterEnvVars = process.env;
5+
6+
describe("get-github-token tests", () => {
7+
beforeEach("reset environment variables", () => {
8+
process.env = starterEnvVars;
9+
})
10+
11+
it("should find token from environment variable", () => {
12+
process.env["GITHUB_TOKEN"] = "token";
13+
expect(getToken()).to.equal("token");
14+
});
15+
16+
it("should find token from environment variable and explicitly nullish param", () => {
17+
process.env["GITHUB_TOKEN"] = "token";
18+
expect(getToken(undefined)).to.equal("token");
19+
expect(getToken(null)).to.equal("token");
20+
});
21+
22+
it("should find token from environment variable and alternate name", () => {
23+
process.env["TEST_TOKEN"] = "token";
24+
expect(getToken(undefined, "TEST_TOKEN")).to.equal("token");
25+
expect(getToken(null, "TEST_TOKEN")).to.equal("token");
26+
});
27+
28+
it("should find token from command line argument", () => {
29+
expect(getToken("token")).to.equal("token");
30+
})
31+
32+
it("should find token from command line argument and alternate name", () => {
33+
expect(getToken("token", "TEST_TOKEN")).to.equal("token");
34+
})
35+
36+
it("should find token from command line argument even with conflicting environment variable", () => {
37+
process.env["GITHUB_TOKEN"] = "token2";
38+
expect(getToken("token")).to.equal("token");
39+
})
40+
41+
it("should find token from command line argument even with conflicting environment variable and alternate name", () => {
42+
process.env["TEST_TOKEN"] = "token2";
43+
expect(getToken("token", "TEST_TOKEN")).to.equal("token");
44+
})
45+
})

0 commit comments

Comments
 (0)