Skip to content
This repository was archived by the owner on Jan 10, 2023. It is now read-only.

Commit dcf3a00

Browse files
BjørnBjørn
authored andcommitted
Add tests.
Test detect module. Test buildkite service detector. Edit snap service detector test to cover all paths.
1 parent 2aeb508 commit dcf3a00

3 files changed

Lines changed: 54 additions & 1 deletion

File tree

test/detect.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
var detect = require("../lib/detect");
3+
var execSync = require('child_process').execSync;
4+
if (!execSync) {
5+
var exec = require('execSync').exec;
6+
var execSync = function(cmd){
7+
return exec(cmd).stdout;
8+
};
9+
}
10+
11+
describe("Codecov", function(){
12+
13+
it("can detect existing appveyor service", function(){
14+
process.env.APPVEYOR = "true";
15+
16+
expect(detect().service).to.eql("appveyor");
17+
});
18+
19+
it("can select local git service if no service is found", function(){
20+
process.env.APPVEYOR = "";
21+
22+
expect(detect().commit).to.match(/^\w{40}$/);
23+
expect(detect().commit).to.eql(execSync("git rev-parse HEAD || hg id -i --debug | tr -d '+'").toString().trim());
24+
})
25+
});

test/services/buildkite.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
var buildkite = require("../../lib/services/buildkite");
2+
3+
describe("Buildkite CI Provider", function(){
4+
5+
it ("can detect buildkite", function(){
6+
process.env.BUILDKITE = "true";
7+
expect(buildkite.detect()).to.be(true);
8+
});
9+
10+
it ("can get buildkite env info", function(){
11+
process.env.BUILDKITE_BUILD_NUMBER = "1";
12+
process.env.BUILDKITE_BUILD_URL = "url";
13+
process.env.BUILDKITE_COMMIT = "commit";
14+
process.env.BUILDKITE_BRANCH = "branch";
15+
process.env.BUILDKITE_PROJECT_SLUG = "slug";
16+
17+
expect(buildkite.configuration()).to.eql({
18+
service : 'buildkite',
19+
build : "1",
20+
build_url : "url",
21+
commit : "commit",
22+
branch : "branch",
23+
slug : "slug"
24+
});
25+
});
26+
27+
});

test/services/snap.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,11 @@ describe("Snap CI Provider", function(){
2323
});
2424

2525
it ("can get snap env info get_commit_status for pull requests", function(){
26+
process.env.SNAP_COMMIT = '';
2627
process.env.SNAP_BRANCH = '';
2728
process.env.SNAP_CI = "true";
2829
process.env.SNAP_PIPELINE_COUNTER = '1234';
29-
process.env.SNAP_COMMIT = '5678';
30+
process.env.SNAP_UPSTREAM_COMMIT = '5678';
3031
process.env.SNAP_UPSTREAM_BRANCH = 'upstream-branch';
3132
process.env.SNAP_PULL_REQUEST_NUMBER = 'blah';
3233
expect(snap.configuration()).to.eql({

0 commit comments

Comments
 (0)