|
| 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