@@ -4,7 +4,7 @@ const { describe, it } = require('mocha')
44const assert = require ( 'assert' )
55const path = require ( 'path' )
66const fs = require ( 'graceful-fs' )
7- const { execFileSync , execFile } = require ( 'child_process' )
7+ const cp = require ( 'child_process' )
88const os = require ( 'os' )
99const addonPath = path . resolve ( __dirname , 'node_modules' , 'hello_world' )
1010const nodeGyp = path . resolve ( __dirname , '..' , 'bin' , 'node-gyp.js' )
@@ -14,18 +14,18 @@ function runHello (hostProcess) {
1414 hostProcess = process . execPath
1515 }
1616 const testCode = "console.log(require('hello_world').hello())"
17- return execFileSync ( hostProcess , [ '-e' , testCode ] , { cwd : __dirname } ) . toString ( )
17+ return cp . execFileSync ( hostProcess , [ '-e' , testCode ] , { cwd : __dirname } ) . toString ( )
1818}
1919
2020function getEncoding ( ) {
2121 const code = 'import locale;print(locale.getdefaultlocale()[1])'
22- return execFileSync ( 'python' , [ '-c' , code ] ) . toString ( ) . trim ( )
22+ return cp . execFileSync ( 'python' , [ '-c' , code ] ) . toString ( ) . trim ( )
2323}
2424
2525function checkCharmapValid ( ) {
2626 let data
2727 try {
28- data = execFileSync ( 'python' , [ 'fixtures/test-charmap.py' ] ,
28+ data = cp . execFileSync ( 'python' , [ 'fixtures/test-charmap.py' ] ,
2929 { cwd : __dirname } )
3030 } catch ( err ) {
3131 return false
@@ -34,13 +34,25 @@ function checkCharmapValid () {
3434 return lines . pop ( ) === 'True'
3535}
3636
37+ const omit = ( obj , ...keys ) => {
38+ const res = { }
39+ for ( const key of Object . keys ( obj ) ) {
40+ if ( ! keys . includes ( key ) ) {
41+ res [ key ] = obj [ key ]
42+ }
43+ }
44+ return res
45+ }
46+
3747describe ( 'addon' , function ( ) {
3848 this . timeout ( 300000 )
3949
50+ const execFile = ( cmd , fn ) => cp . execFile ( process . execPath , cmd , { env : omit ( process . env , 'NODE_GYP_NULL_LOGGER' ) } , fn )
51+
4052 it ( 'build simple addon' , function ( done ) {
4153 // Set the loglevel otherwise the output disappears when run via 'npm test'
4254 const cmd = [ nodeGyp , 'rebuild' , '-C' , addonPath , '--loglevel=verbose' ]
43- const proc = execFile ( process . execPath , cmd , function ( err , stdout , stderr ) {
55+ const proc = execFile ( cmd , function ( err , stdout , stderr ) {
4456 const logLines = stderr . toString ( ) . trim ( ) . split ( / \r ? \n / )
4557 const lastLine = logLines [ logLines . length - 1 ]
4658 assert . strictEqual ( err , null )
@@ -105,7 +117,7 @@ describe('addon', function () {
105117 '--loglevel=verbose' ,
106118 '-nodedir=' + testNodeDir
107119 ]
108- const proc = execFile ( process . execPath , cmd , function ( err , stdout , stderr ) {
120+ const proc = execFile ( cmd , function ( err , stdout , stderr ) {
109121 try {
110122 fs . unlink ( testNodeDir )
111123 } catch ( err ) {
@@ -124,18 +136,13 @@ describe('addon', function () {
124136 } )
125137
126138 it ( 'addon works with renamed host executable' , function ( done ) {
127- // No `fs.copyFileSync` before node8.
128- if ( process . version . substr ( 1 ) . split ( '.' ) [ 0 ] < 8 ) {
129- return this . skip ( 'skipping test for old node version' )
130- }
131-
132139 this . timeout ( 300000 )
133140
134141 const notNodePath = path . join ( os . tmpdir ( ) , 'notnode' + path . extname ( process . execPath ) )
135142 fs . copyFileSync ( process . execPath , notNodePath )
136143
137144 const cmd = [ nodeGyp , 'rebuild' , '-C' , addonPath , '--loglevel=verbose' ]
138- const proc = execFile ( process . execPath , cmd , function ( err , stdout , stderr ) {
145+ const proc = execFile ( cmd , function ( err , stdout , stderr ) {
139146 const logLines = stderr . toString ( ) . trim ( ) . split ( / \r ? \n / )
140147 const lastLine = logLines [ logLines . length - 1 ]
141148 assert . strictEqual ( err , null )
0 commit comments