1- var common = require ( "../common-tap.js" )
2- var test = require ( "tap" ) . test
3- var npm = require . resolve ( "../../bin/npm-cli.js" )
4- var path = require ( "path" )
5- var fs = require ( "fs" )
6- var rimraf = require ( "rimraf" )
7- var mkdirp = require ( "mkdirp" )
1+ var common = require ( '../common-tap.js' )
2+ var test = require ( 'tap' ) . test
3+ var path = require ( 'path' )
4+ var fs = require ( 'fs' )
5+ var rimraf = require ( 'rimraf' )
6+ var mkdirp = require ( 'mkdirp' )
87
98var mr = require ( "npm-registry-mock" )
109
11- var spawn = require ( "child_process" ) . spawn
12- var node = process . execPath
13-
14- var pkg = path . resolve ( process . env . npm_config_tmp || "/tmp" ,
15- "noargs-install-config-save" )
10+ var pkg = path . resolve ( process . env . npm_config_tmp || '/tmp' ,
11+ 'noargs-install-config-save' )
1612
1713function writePackageJson ( ) {
1814 rimraf . sync ( pkg )
@@ -29,33 +25,32 @@ function writePackageJson() {
2925 } ) , "utf8" )
3026}
3127
32- function createChild ( args ) {
33- var env = {
34- "npm_config_save" : true ,
35- "npm_config_registry" : common . registry ,
36- "npm_config_cache" : pkg + "/cache" ,
37- HOME : process . env . HOME ,
38- Path : process . env . PATH ,
39- PATH : process . env . PATH
40- }
41-
42- if ( process . platform === "win32" )
43- env . npm_config_cache = "%APPDATA%\\npm-cache"
44-
45- return spawn ( node , args , {
46- cwd : pkg ,
47- env : env
48- } )
28+ var env = {
29+ 'npm_config_save' : true ,
30+ 'npm_config_registry' : common . registry ,
31+ 'npm_config_cache' : pkg + '/cache' ,
32+ HOME : process . env . HOME ,
33+ Path : process . env . PATH ,
34+ PATH : process . env . PATH
35+ }
36+ var OPTS = {
37+ cwd : pkg ,
38+ env : env
4939}
5040
5141test ( "does not update the package.json with empty arguments" , function ( t ) {
5242 writePackageJson ( )
53- t . plan ( 1 )
43+ t . plan ( 2 )
5444
55- mr ( { port : common . port } , function ( er , s ) {
56- var child = createChild ( [ npm , "install" ] )
57- child . on ( "close" , function ( ) {
58- var text = JSON . stringify ( fs . readFileSync ( pkg + "/package.json" , "utf8" ) )
45+ mr ( { port : common . port } , function ( er , s ) {
46+ common . npm ( 'install' , OPTS , function ( er , code , stdout , stderr ) {
47+ if ( er ) throw er
48+ t . is ( code , 0 )
49+ if ( code !== 0 ) {
50+ console . error ( '#' , stdout )
51+ console . error ( '#' , stderr )
52+ }
53+ var text = JSON . stringify ( fs . readFileSync ( pkg + '/package.json' , 'utf8' ) )
5954 s . close ( )
6055 t . ok ( text . indexOf ( "\"dependencies" ) === - 1 )
6156 } )
@@ -64,11 +59,12 @@ test("does not update the package.json with empty arguments", function (t) {
6459
6560test ( "updates the package.json (adds dependencies) with an argument" , function ( t ) {
6661 writePackageJson ( )
67- t . plan ( 1 )
62+ t . plan ( 2 )
6863
69- mr ( { port : common . port } , function ( er , s ) {
70- var child = createChild ( [ npm , "install" , "underscore" ] )
71- child . on ( "close" , function ( ) {
64+ mr ( { port : common . port } , function ( er , s ) {
65+ common . npm ( [ 'install' , 'underscore' ] , OPTS , function ( er , code , stdout , stderr ) {
66+ if ( er ) throw er
67+ t . is ( code , 0 )
7268 s . close ( )
7369 var text = JSON . stringify ( fs . readFileSync ( pkg + "/package.json" , "utf8" ) )
7470 t . ok ( text . indexOf ( "\"dependencies" ) !== - 1 )
0 commit comments