@@ -13,7 +13,6 @@ const envBackup = Object.assign({}, process.env);
1313const cwd = process . cwd ( ) ;
1414// Disable logs during tests
1515stub ( process . stdout , 'write' ) ;
16- stub ( process . stderr , 'write' ) ;
1716
1817test . before ( async ( ) => {
1918 // Start the local NPM registry
@@ -61,7 +60,8 @@ test.serial('Throws error if NPM token is invalid', async t => {
6160 process . env . DEFAULT_NPM_REGISTRY = npmRegistry . url ;
6261 const pkg = { name : 'published' , version : '1.0.0' , publishConfig : { registry : npmRegistry . url } } ;
6362 await outputJson ( './package.json' , pkg ) ;
64- const error = await t . throws ( t . context . m . verifyConditions ( { } , { options : { } , logger : t . context . logger } ) ) ;
63+
64+ const [ error ] = await t . throws ( t . context . m . verifyConditions ( { } , { options : { } , logger : t . context . logger } ) ) ;
6565
6666 t . true ( error instanceof SemanticReleaseError ) ;
6767 t . is ( error . code , 'EINVALIDNPMTOKEN' ) ;
@@ -83,7 +83,7 @@ test.serial('Skip Token validation if the registry configured is not the default
8383
8484test . serial ( 'Verify npm auth and package' , async t => {
8585 Object . assign ( process . env , npmRegistry . authEnv ) ;
86- console . log ( process . env ) ;
86+
8787 const pkg = { name : 'valid-token' , version : '0.0.0-dev' , publishConfig : { registry : npmRegistry . url } } ;
8888 await outputJson ( './package.json' , pkg ) ;
8989 await t . notThrows ( t . context . m . verifyConditions ( { } , { options : { } , logger : t . context . logger } ) ) ;
@@ -109,71 +109,43 @@ test.serial('Verify npm auth and package with "npm_config_registry" env var set
109109 process . env . npm_config_registry = 'https://registry.yarnpkg.com' ; // eslint-disable-line camelcase
110110 const pkg = { name : 'valid-token' , version : '0.0.0-dev' , publishConfig : { registry : npmRegistry . url } } ;
111111 await outputJson ( './package.json' , pkg ) ;
112- await t . notThrows ( t . context . m . verifyConditions ( { } , { options : { } , logger : t . context . logger } ) ) ;
112+ await t . notThrows ( t . context . m . verifyConditions ( { } , { options : { publish : [ ] } , logger : t . context . logger } ) ) ;
113113
114114 const npmrc = ( await readFile ( '.npmrc' ) ) . toString ( ) ;
115115 t . regex ( npmrc , / _ a u t h = / ) ;
116116 t . regex ( npmrc , / e m a i l = / ) ;
117117} ) ;
118118
119- test . serial (
120- 'Throw SemanticReleaseError if publish "npmPublish" option in verifyConditions is not a Boolean' ,
121- async t => {
122- const pkg = { name : 'invalid-npmPublish' , version : '0.0.0-dev' , publishConfig : { registry : npmRegistry . url } } ;
123- await outputJson ( './package.json' , pkg ) ;
124- const npmPublish = 42 ;
125- const error = await t . throws (
126- t . context . m . verifyConditions (
127- { } ,
128- {
129- options : { publish : [ '@semantic-release/github' , { path : '@semantic-release/npm' , npmPublish} ] } ,
130- logger : t . context . logger ,
131- }
132- )
133- ) ;
134-
135- t . is ( error . name , 'SemanticReleaseError' ) ;
136- t . is ( error . code , 'EINVALIDNPMPUBLISH' ) ;
137- }
138- ) ;
139-
140- test . serial (
141- 'Throw SemanticReleaseError if publish "tarballDir" option in verifyConditions is not a String' ,
142- async t => {
143- const pkg = { name : 'invalid-tarballDir' , version : '0.0.0-dev' , publishConfig : { registry : npmRegistry . url } } ;
144- await outputJson ( './package.json' , pkg ) ;
145- const tarballDir = 42 ;
146- const error = await t . throws (
119+ test . serial ( 'Throw SemanticReleaseError Array if config option are not valid in verifyConditions' , async t => {
120+ const pkg = { publishConfig : { registry : npmRegistry . url } } ;
121+ await outputJson ( './package.json' , pkg ) ;
122+ const npmPublish = 42 ;
123+ const tarballDir = 42 ;
124+ const pkgRoot = 42 ;
125+ const errors = [
126+ ...( await t . throws (
147127 t . context . m . verifyConditions (
148128 { } ,
149129 {
150- options : { publish : [ '@semantic-release/github' , { path : '@semantic-release/npm' , tarballDir} ] } ,
130+ options : {
131+ publish : [ '@semantic-release/github' , { path : '@semantic-release/npm' , npmPublish, tarballDir, pkgRoot} ] ,
132+ } ,
151133 logger : t . context . logger ,
152134 }
153135 )
154- ) ;
155-
156- t . is ( error . name , 'SemanticReleaseError' ) ;
157- t . is ( error . code , 'EINVALIDTARBALLDIR' ) ;
158- }
159- ) ;
160-
161- test . serial ( 'Throw SemanticReleaseError if publish "pkgRoot" option in verifyConditions is not a String' , async t => {
162- const pkg = { name : 'invalid-pkgRoot' , version : '0.0.0-dev' , publishConfig : { registry : npmRegistry . url } } ;
163- await outputJson ( './package.json' , pkg ) ;
164- const pkgRoot = 42 ;
165- const error = await t . throws (
166- t . context . m . verifyConditions (
167- { } ,
168- {
169- options : { publish : [ '@semantic-release/github' , { path : '@semantic-release/npm' , pkgRoot} ] } ,
170- logger : t . context . logger ,
171- }
172- )
173- ) ;
174-
175- t . is ( error . name , 'SemanticReleaseError' ) ;
176- t . is ( error . code , 'EINVALIDPKGROOT' ) ;
136+ ) ) ,
137+ ] ;
138+
139+ t . is ( errors [ 0 ] . name , 'SemanticReleaseError' ) ;
140+ t . is ( errors [ 0 ] . code , 'EINVALIDNPMPUBLISH' ) ;
141+ t . is ( errors [ 1 ] . name , 'SemanticReleaseError' ) ;
142+ t . is ( errors [ 1 ] . code , 'EINVALIDTARBALLDIR' ) ;
143+ t . is ( errors [ 2 ] . name , 'SemanticReleaseError' ) ;
144+ t . is ( errors [ 2 ] . code , 'EINVALIDPKGROOT' ) ;
145+ t . is ( errors [ 3 ] . name , 'SemanticReleaseError' ) ;
146+ t . is ( errors [ 3 ] . code , 'ENOPKGNAME' ) ;
147+ t . is ( errors [ 4 ] . name , 'SemanticReleaseError' ) ;
148+ t . is ( errors [ 4 ] . code , 'ENOPKGVERSION' ) ;
177149} ) ;
178150
179151test . serial ( 'Publish the package' , async t => {
@@ -257,6 +229,38 @@ test.serial('Create the package and skip publish from a sub-directory', async t
257229 await t . throws ( execa ( 'npm' , [ 'view' , pkg . name , 'version' ] ) ) ;
258230} ) ;
259231
232+ test . serial ( 'Throw SemanticReleaseError Array if config option are not valid in publish' , async t => {
233+ const pkg = { publishConfig : { registry : npmRegistry . url } } ;
234+ await outputJson ( './package.json' , pkg ) ;
235+ const npmPublish = 42 ;
236+ const tarballDir = 42 ;
237+ const pkgRoot = 42 ;
238+
239+ const errors = [
240+ ...( await t . throws (
241+ t . context . m . publish (
242+ { npmPublish, tarballDir, pkgRoot} ,
243+ {
244+ options : { publish : [ '@semantic-release/github' , '@semantic-release/npm' ] } ,
245+ nextRelease : { version : '1.0.0' } ,
246+ logger : t . context . logger ,
247+ }
248+ )
249+ ) ) ,
250+ ] ;
251+
252+ t . is ( errors [ 0 ] . name , 'SemanticReleaseError' ) ;
253+ t . is ( errors [ 0 ] . code , 'EINVALIDNPMPUBLISH' ) ;
254+ t . is ( errors [ 1 ] . name , 'SemanticReleaseError' ) ;
255+ t . is ( errors [ 1 ] . code , 'EINVALIDTARBALLDIR' ) ;
256+ t . is ( errors [ 2 ] . name , 'SemanticReleaseError' ) ;
257+ t . is ( errors [ 2 ] . code , 'EINVALIDPKGROOT' ) ;
258+ t . is ( errors [ 3 ] . name , 'SemanticReleaseError' ) ;
259+ t . is ( errors [ 3 ] . code , 'ENOPKGNAME' ) ;
260+ t . is ( errors [ 4 ] . name , 'SemanticReleaseError' ) ;
261+ t . is ( errors [ 4 ] . code , 'ENOPKGVERSION' ) ;
262+ } ) ;
263+
260264test . serial ( 'Verify token and set up auth only on the fist call' , async t => {
261265 Object . assign ( process . env , npmRegistry . authEnv ) ;
262266 const pkg = { name : 'test-module' , version : '0.0.0-dev' , publishConfig : { registry : npmRegistry . url } } ;
0 commit comments