@@ -16,12 +16,12 @@ var reset_index = function(index_string_ref) {
1616var sandbox = sinon . createSandbox ( ) ;
1717
1818var 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