@@ -6,64 +6,37 @@ if (common.isInsideDirWithUnusualChars)
66 common . skip ( 'npm does not support this install path' ) ;
77
88const path = require ( 'path' ) ;
9- const exec = require ( 'child_process' ) . exec ;
109const assert = require ( 'assert' ) ;
1110const fs = require ( 'fs' ) ;
1211const fixtures = require ( '../common/fixtures' ) ;
12+ const { spawnSyncAndAssert } = require ( '../common/child_process' ) ;
1313
1414const tmpdir = require ( '../common/tmpdir' ) ;
1515tmpdir . refresh ( ) ;
16- const npmSandbox = tmpdir . resolve ( 'npm-sandbox' ) ;
17- fs . mkdirSync ( npmSandbox ) ;
18- const homeDir = tmpdir . resolve ( 'home' ) ;
19- fs . mkdirSync ( homeDir ) ;
20- const installDir = tmpdir . resolve ( 'install-dir' ) ;
21- fs . mkdirSync ( installDir ) ;
22-
23- const npmPath = path . join (
24- __dirname ,
25- '..' ,
26- '..' ,
27- 'deps' ,
28- 'npm' ,
29- 'bin' ,
30- 'npm-cli.js'
31- ) ;
32-
33- const pkgContent = JSON . stringify ( {
34- dependencies : {
35- 'package-name' : fixtures . path ( 'packages/main' )
36- }
37- } ) ;
3816
39- const pkgPath = path . join ( installDir , 'package.json' ) ;
17+ // Copy fixtures/npm-install to the tmpdir for testing
18+ fs . cpSync ( fixtures . path ( 'npm-install' ) , tmpdir . path , { recursive : true } ) ;
4019
41- fs . writeFileSync ( pkgPath , pkgContent ) ;
20+ const npmPath = path . join ( __dirname , '..' , '..' , 'deps' , 'npm' , 'bin' , 'npm-cli.js' ) ;
4221
43- const env = { ...process . env ,
44- PATH : path . dirname ( process . execPath ) ,
45- NODE : process . execPath ,
46- NPM : npmPath ,
47- NPM_CONFIG_PREFIX : path . join ( npmSandbox , 'npm-prefix' ) ,
48- NPM_CONFIG_TMP : path . join ( npmSandbox , 'npm-tmp' ) ,
49- NPM_CONFIG_AUDIT : false ,
50- NPM_CONFIG_UPDATE_NOTIFIER : false ,
51- HOME : homeDir } ;
22+ const env = {
23+ ...process . env ,
24+ PATH : path . dirname ( process . execPath ) ,
25+ NODE : process . execPath ,
26+ NPM : npmPath ,
27+ NPM_CONFIG_PREFIX : tmpdir . resolve ( 'npm-prefix' ) ,
28+ NPM_CONFIG_TMP : tmpdir . resolve ( 'npm-tmp' ) ,
29+ NPM_CONFIG_AUDIT : false ,
30+ NPM_CONFIG_UPDATE_NOTIFIER : false ,
31+ HOME : tmpdir . resolve ( 'home' ) ,
32+ } ;
5233
53- exec ( `"${ common . isWindows ? process . execPath : '$NODE' } " "${ common . isWindows ? npmPath : '$NPM' } " install` , {
54- cwd : installDir ,
55- env : env
56- } , common . mustCall ( handleExit ) ) ;
57-
58- function handleExit ( error , stdout , stderr ) {
59- const code = error ? error . code : 0 ;
60- const signalCode = error ? error . signal : null ;
61-
62- if ( code !== 0 ) {
63- process . stderr . write ( stderr ) ;
64- }
34+ const installDir = tmpdir . resolve ( 'install-dir' ) ;
35+ spawnSyncAndAssert (
36+ process . execPath ,
37+ [ npmPath , 'install' ] ,
38+ { cwd : installDir , env } ,
39+ { }
40+ ) ;
6541
66- assert . strictEqual ( code , 0 , `npm install got error code ${ code } ` ) ;
67- assert . strictEqual ( signalCode , null , `unexpected signal: ${ signalCode } ` ) ;
68- assert ( fs . existsSync ( `${ installDir } /node_modules/package-name` ) ) ;
69- }
42+ assert ( fs . existsSync ( path . join ( installDir , 'node_modules' , 'example' ) ) ) ;
0 commit comments