Skip to content

Commit 5b756cb

Browse files
committed
fixed tests
1 parent fceb74f commit 5b756cb

3 files changed

Lines changed: 44 additions & 25 deletions

File tree

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,6 @@ build/Release
2525
# Dependency directory
2626
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git
2727
node_modules
28+
29+
.nyc_output
30+
package-lock.json

package.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
{
22
"name": "node-pre-gyp-github",
3-
"version": "1.4.0",
3+
"version": "1.4.1",
44
"description": "A node-pre-gyp module which provides the ability to publish to GitHub releases.",
55
"bin": "./bin/node-pre-gyp-github.js",
66
"main": "index.js",
77
"scripts": {
8-
"test": "mocha test",
9-
"coverage": "istanbul cover ./node_modules/mocha/bin/_mocha --report text-lcov -- -R spec | node ./node_modules/coveralls/bin/coveralls.js"
8+
"test": "nyc --reporter=html --reporter=text mocha",
9+
"coverage": "nyc report --reporter=text-lcov | coveralls"
1010
},
1111
"repository": {
1212
"type": "git",
@@ -26,15 +26,15 @@
2626
],
2727
"dependencies": {
2828
"@octokit/rest": "^15.9.5",
29-
"commander": "^2.9.0",
29+
"commander": "^2.17.0",
3030
"mime-types": "^2.1.19",
3131
"sinon": "^6.1.4"
3232
},
3333
"devDependencies": {
3434
"chai": "^3.5.0",
35-
"coveralls": "^2.11.9",
36-
"istanbul": "^0.4.3",
37-
"mocha": "^2.5.3"
35+
"coveralls": "^3.0.2",
36+
"mocha": "^5.2.0",
37+
"nyc": "^12.0.2"
3838
},
3939
"author": "Bill Christo",
4040
"license": "MIT",

test/test.js

Lines changed: 34 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ var reset_index = function(index_string_ref) {
1616
var sandbox = sinon.createSandbox();
1717

1818
var reset_mocks = function() {
19-
sandbox.restore();
19+
sandbox.restore();
2020
process.env.NODE_PRE_GYP_GITHUB_TOKEN = "secret";
2121
fs = reset_index('fs');
2222
fs.readFileSync = function(){return '{"name":"test","version":"0.0.1","repository": {"url":"git+https://github.com/test/test.git"},"binary":{"host":"https://github.com/test/test/releases/download/","remote_path":"{version}"}}';};
2323
index.stage_dir = stage_dir;
24-
Index.prototype.octokit = function() {return octokit;};
24+
Index.prototype.octokit = function() {return octokit;};
2525
sandbox.stub(octokit, 'authenticate');
2626
sandbox.stub(octokit.repos, 'getReleases').callsFake(function(options, cb){
2727
cb(null, {data: [{"tag_name":"0.0.0","assets":[{"name":"filename"}]}]});
@@ -39,24 +39,40 @@ describe("Publishes packages to GitHub Releases", function() {
3939

4040
describe("Publishes without an error under all options", function() {
4141

42-
it("should publish a non-draft release without an error", function() {
43-
var options = {'draft': false, 'verbose': false};
42+
it("should publish without error in all scenarios", function() {
43+
var log = console.log;
4444
reset_mocks();
4545
fs.readdir = function(filename, cb) {
4646
cb(null,["filename"]);
4747
};
48-
fs.statSync = function() {return 0;}
49-
index.publish(options)
50-
expect(function(){ index.publish(options); }).to.not.throw();
51-
});
52-
53-
it("should publish a draft release without an error", function() {
54-
var options = {'draft': true, 'verbose': false};
55-
reset_mocks();
56-
fs.readdir = function(filename, cb) {
57-
cb(null,["filename"]);
48+
fs.statSync = function() {return 0;}
49+
console.log = function() {};
50+
51+
// testing scenario when a release already exists
52+
expect(function(){ index.publish(); }).to.not.throw();
53+
expect(function(){ index.publish({'draft': false, 'verbose': false}); }).to.not.throw();
54+
expect(function(){ index.publish({'draft': false, 'verbose': true}); }).to.not.throw();
55+
expect(function(){ index.publish({'draft': true, 'verbose': false}); }).to.not.throw();
56+
expect(function(){ index.publish({'draft': true, 'verbose': true}); }).to.not.throw();
57+
58+
// testing scenario when a release does not already exist
59+
octokit.repos.getReleases = function(options, cb){
60+
cb(null,{data: []});
5861
};
59-
expect(function(){ index.publish(options); }).to.not.throw();
62+
octokit.repos.createRelease = function(options, cb){
63+
cb(null, { data: { draft: false} });
64+
};
65+
expect(function(){ index.publish(); }).to.not.throw();
66+
expect(function(){ index.publish({'draft': false, 'verbose': false}); }).to.not.throw();
67+
expect(function(){ index.publish({'draft': false, 'verbose': true}); }).to.not.throw();
68+
octokit.repos.createRelease = function(options, cb){
69+
cb(null, { data: { draft: true} });
70+
};
71+
expect(function(){ index.publish({'draft': true, 'verbose': false}); }).to.not.throw();
72+
expect(function(){ index.publish({'draft': true, 'verbose': true}); }).to.not.throw();
73+
fs.readFileSync = function(){return '{"version":"0.0.1","repository": {"url":"git+https://github.com/test/test.git"},"binary":{"host":"https://github.com/test/test/releases/download/","remote_path":"{version}"}}';};
74+
expect(function(){ index.publish(); }).to.not.throw();
75+
console.log = log;
6076
});
6177

6278
});
@@ -103,13 +119,13 @@ describe("Publishes packages to GitHub Releases", function() {
103119
reset_mocks();
104120

105121
octokit.repos.getReleases.restore();
106-
sandbox.stub(octokit.repos, 'getReleases').callsFake(function(options, cb){
122+
sandbox.stub(octokit.repos, 'getReleases').callsFake(function(options, cb){
107123
cb(new Error('getReleases error'));
108124
});
109125
expect(function(){ index.publish(options); }).to.throw('getReleases error');
110126
});
111127

112-
it("should throw an error when github.releases.createRelease returns an error", function() {
128+
it("should throw an error when octokit.repos.createRelease returns an error", function() {
113129
var options = {'draft': true, 'verbose': false};
114130
reset_mocks();
115131
octokit.repos.getReleases = function(options, cb){
@@ -174,7 +190,7 @@ describe("Publishes packages to GitHub Releases", function() {
174190
fs.readdir = function(filename, cb) {
175191
cb(null,["filename"]);
176192
};
177-
fs.statSync = function() {return 0;}
193+
fs.statSync = function() {return 0;}
178194
octokit.reposcreateRelease = function(options, cb){
179195
cb(null,{data: {"tag_name":"0.0.1","draft":false,"assets":[{}]}});
180196
};

0 commit comments

Comments
 (0)