@@ -2,15 +2,17 @@ import {escape} from 'querystring';
22import test from 'ava' ;
33import { stat } from 'fs-extra' ;
44import nock from 'nock' ;
5- import { stub , match } from 'sinon' ;
5+ import { stub } from 'sinon' ;
6+ import tempy from 'tempy' ;
67import publish from '../lib/publish' ;
78import { authenticate , upload } from './helpers/mock-github' ;
89
910/* eslint camelcase: ["error", {properties: "never"}] */
1011
12+ // Save the current process.env
13+ const envBackup = Object . assign ( { } , process . env ) ;
14+
1115test . beforeEach ( t => {
12- // Save the current process.env
13- t . context . env = Object . assign ( { } , process . env ) ;
1416 // Delete env variables in case they are on the machine running the tests
1517 delete process . env . GH_TOKEN ;
1618 delete process . env . GITHUB_TOKEN ;
@@ -24,9 +26,9 @@ test.beforeEach(t => {
2426 t . context . logger = { log : t . context . log , error : t . context . error } ;
2527} ) ;
2628
27- test . afterEach . always ( t => {
29+ test . afterEach . always ( ( ) => {
2830 // Restore process.env
29- process . env = Object . assign ( { } , t . context . env ) ;
31+ process . env = envBackup ;
3032 // Clear nock
3133 nock . cleanAll ( ) ;
3234} ) ;
@@ -58,7 +60,7 @@ test.serial('Publish a release', async t => {
5860
5961 await publish ( pluginConfig , options , nextRelease , t . context . logger ) ;
6062
61- t . true ( t . context . log . calledWith ( match . string , releaseUrl ) ) ;
63+ t . deepEqual ( t . context . log . args [ 0 ] , [ 'Published Github release: %s' , releaseUrl ] ) ;
6264 t . true ( github . isDone ( ) ) ;
6365} ) ;
6466
@@ -87,7 +89,7 @@ test.serial('Publish a release with an existing tag', async t => {
8789
8890 await publish ( pluginConfig , options , nextRelease , t . context . logger ) ;
8991
90- t . true ( t . context . log . calledWith ( match . string , releaseUrl ) ) ;
92+ t . deepEqual ( t . context . log . args [ 0 ] , [ 'Published Github release: %s' , releaseUrl ] ) ;
9193 t . true ( github . isDone ( ) ) ;
9294} ) ;
9395
@@ -129,8 +131,8 @@ test.serial('Publish a release with one asset', async t => {
129131
130132 await publish ( pluginConfig , options , nextRelease , t . context . logger ) ;
131133
132- t . true ( t . context . log . calledWith ( match . string , releaseUrl ) ) ;
133- t . true ( t . context . log . calledWith ( match . string , assetUrl ) ) ;
134+ t . deepEqual ( t . context . log . args [ 0 ] , [ 'Published Github release: %s' , releaseUrl ] ) ;
135+ t . deepEqual ( t . context . log . args [ 1 ] , [ 'Published file %s' , assetUrl ] ) ;
134136 t . true ( github . isDone ( ) ) ;
135137 t . true ( githubUpload . isDone ( ) ) ;
136138} ) ;
@@ -183,8 +185,8 @@ test.serial('Publish a release with one asset and custom github url', async t =>
183185
184186 await publish ( pluginConfig , options , nextRelease , t . context . logger ) ;
185187
186- t . true ( t . context . log . calledWith ( match . string , releaseUrl ) ) ;
187- t . true ( t . context . log . calledWith ( match . string , assetUrl ) ) ;
188+ t . deepEqual ( t . context . log . args [ 0 ] , [ 'Published Github release: %s' , releaseUrl ] ) ;
189+ t . deepEqual ( t . context . log . args [ 1 ] , [ 'Published file %s' , assetUrl ] ) ;
188190 t . true ( github . isDone ( ) ) ;
189191 t . true ( githubUpload . isDone ( ) ) ;
190192} ) ;
@@ -193,9 +195,10 @@ test.serial('Publish a release with an array of missing assets', async t => {
193195 const owner = 'test_user' ;
194196 const repo = 'test_repo' ;
195197 const githubToken = 'github_token' ;
198+ const emptyDirectory = tempy . directory ( ) ;
196199 const pluginConfig = {
197200 githubToken,
198- assets : [ 'test/fixtures/empty' , { path : 'test/fixtures/missing.txt' , name : 'missing.txt' } ] ,
201+ assets : [ emptyDirectory , { path : 'test/fixtures/missing.txt' , name : 'missing.txt' } ] ,
199202 } ;
200203 const nextRelease = { version : '1.0.0' , gitHead : '123' , gitTag : 'v1.0.0' , notes : 'Test release note body' } ;
201204 const options = { branch : 'master' , repositoryUrl : `https://github.com/${ owner } /${ repo } .git` } ;
@@ -219,9 +222,12 @@ test.serial('Publish a release with an array of missing assets', async t => {
219222
220223 await publish ( pluginConfig , options , nextRelease , t . context . logger ) ;
221224
222- t . true ( t . context . log . calledWith ( match . string , releaseUrl ) ) ;
223- t . true ( t . context . error . calledWith ( match . string , 'test/fixtures/missing.txt' ) ) ;
224- t . true ( t . context . error . calledWith ( match . string , 'test/fixtures/empty' ) ) ;
225+ t . deepEqual ( t . context . log . args [ 0 ] , [ 'Published Github release: %s' , releaseUrl ] ) ;
226+ t . deepEqual ( t . context . error . args [ 0 ] , [
227+ 'The asset %s cannot be read, and will be ignored.' ,
228+ 'test/fixtures/missing.txt' ,
229+ ] ) ;
230+ t . deepEqual ( t . context . error . args [ 1 ] , [ 'The asset %s is not a file, and will be ignored.' , emptyDirectory ] ) ;
225231 t . true ( github . isDone ( ) ) ;
226232} ) ;
227233
0 commit comments