Skip to content

Commit 1b1e828

Browse files
Added tests for the new host.ci property
1 parent 033c934 commit 1b1e828

File tree

2 files changed

+65
-6
lines changed

2 files changed

+65
-6
lines changed

test/specs/ci.spec.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
"use strict";
2+
3+
const { host } = require("../../");
4+
const { expect } = require("chai");
5+
6+
describe("CI/CD host", () => {
7+
8+
if (typeof window === "undefined" && process.env.GITHUB_ACTIONS === "true") {
9+
10+
it("host.ci should be an object", () => {
11+
expect(host.ci).to.be.an("object");
12+
});
13+
14+
it("host.ci.name should be a string", () => {
15+
expect(host.ci.name).to.be.a("string").with.length.above(0);
16+
});
17+
18+
it("host.ci.pr should be a boolean", () => {
19+
expect(host.ci.name).to.be.a("boolean");
20+
});
21+
22+
it("all other properties should be CI/CD constants", () => {
23+
let keys = Object.keys(host.ci);
24+
25+
// Remove other properties
26+
for (let key of ["name", "pr", "isPR"]) {
27+
keys.splice(keys.indexOf(key), 1);
28+
}
29+
30+
for (let key of keys) {
31+
expect(key).to.match(/[A-Z]+(_[A-Z]+)*/);
32+
expect(host.ci[key]).to.be.a("boolean", `Invalid CI/CD constant: ${key}`);
33+
}
34+
});
35+
36+
}
37+
else {
38+
39+
it("host.ci should be false", () => {
40+
expect(host.ci).to.equal(false);
41+
});
42+
43+
}
44+
45+
});

test/specs/exports.spec.js

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,26 @@ describe("package exports", () => {
88

99
function isHostObject (host) {
1010
expect(host).to.be.an("object");
11-
expect(host).to.have.property("global");
12-
expect(host).to.have.property("os");
13-
expect(host).to.have.property("env");
14-
expect(host).to.have.property("node");
15-
expect(host).to.have.property("browser");
16-
expect(host).to.have.property("toJSON");
11+
12+
let keys = Object.keys(host);
13+
14+
// Ignore the default and named exports
15+
for (let key of ["default", "host"]) {
16+
if (keys.indexOf(key) >= 0) {
17+
keys.splice(keys.indexOf(key), 1);
18+
}
19+
}
20+
21+
expect(keys).to.have.same.members([
22+
"global",
23+
"os",
24+
"env",
25+
"ci",
26+
"node",
27+
"browser",
28+
"merge",
29+
"toJSON",
30+
]);
1731

1832
return true;
1933
}

0 commit comments

Comments
 (0)