@@ -7,6 +7,7 @@ import tempy from 'tempy';
7
7
import clearModule from 'clear-module' ;
8
8
import { WritableStreamBuffer } from 'stream-buffers' ;
9
9
import npmRegistry from './helpers/npm-registry' ;
10
+ import otpServer from './helpers/otp-server' ;
10
11
11
12
/* eslint camelcase: ["error", {properties: "never"}] */
12
13
@@ -23,6 +24,8 @@ const testEnv = {
23
24
test . before ( async ( ) => {
24
25
// Start the local NPM registry
25
26
await npmRegistry . start ( ) ;
27
+ // Stop the test OTP server
28
+ await otpServer . start ( ) ;
26
29
} ) ;
27
30
28
31
test . beforeEach ( t => {
@@ -39,6 +42,8 @@ test.beforeEach(t => {
39
42
test . after . always ( async ( ) => {
40
43
// Stop the local NPM registry
41
44
await npmRegistry . stop ( ) ;
45
+ // Stop the test OTP server
46
+ await otpServer . start ( ) ;
42
47
} ) ;
43
48
44
49
test ( 'Skip npm auth verification if "npmPublish" is false' , async t => {
@@ -285,6 +290,34 @@ test('Publish the package on a dist-tag', async t => {
285
290
t . is ( ( await execa ( 'npm' , [ 'view' , pkg . name , 'version' ] , { cwd, env : testEnv } ) ) . stdout , '1.0.0' ) ;
286
291
} ) ;
287
292
293
+ test ( 'Publish the package with OTP' , async t => {
294
+ const cwd = tempy . directory ( ) ;
295
+ const env = npmRegistry . authEnv ;
296
+ const pkg = { name : 'publish-otp' , version : '0.0.0' , publishConfig : { registry : npmRegistry . url } } ;
297
+ await outputJson ( path . resolve ( cwd , 'package.json' ) , pkg ) ;
298
+
299
+ const { port, address} = otpServer . address ( ) ;
300
+ const result = await t . context . m . publish (
301
+ {
302
+ otpUrl : `http://${ address } :${ port } /otp`
303
+ } ,
304
+ {
305
+ cwd,
306
+ env,
307
+ options : { } ,
308
+ stdout : t . context . stdout ,
309
+ stderr : t . context . stderr ,
310
+ logger : t . context . logger ,
311
+ nextRelease : { version : '1.0.0' } ,
312
+ }
313
+ ) ;
314
+
315
+ t . deepEqual ( result , { name : 'npm package (@latest dist-tag)' , url : undefined } ) ;
316
+ t . is ( ( await readJson ( path . resolve ( cwd , 'package.json' ) ) ) . version , '1.0.0' ) ;
317
+ t . false ( await pathExists ( path . resolve ( cwd , `${ pkg . name } -1.0.0.tgz` ) ) ) ;
318
+ t . is ( ( await execa ( 'npm' , [ 'view' , pkg . name , 'version' ] , { cwd, env : testEnv } ) ) . stdout , '1.0.0' ) ;
319
+ } ) ;
320
+
288
321
test ( 'Publish the package from a sub-directory' , async t => {
289
322
const cwd = tempy . directory ( ) ;
290
323
const env = npmRegistry . authEnv ;
0 commit comments