@@ -8,11 +8,11 @@ var child_process = require('child_process');
88var stream = require ( 'stream' ) ;
99var util = require ( 'util' ) ;
1010var Timer = process . binding ( 'timer_wrap' ) . Timer ;
11- var execSync = require ( 'child_process' ) . execSync ;
1211
13- var testRoot = process . env . NODE_TEST_DIR ? fs . realpathSync ( process . env . NODE_TEST_DIR ) : __dirname ;
12+ var testRoot = process . env . NODE_TEST_DIR ? path . resolve ( process . env . NODE_TEST_DIR ) : __dirname ;
1413
15- exports . fixturesDir = path . join ( __dirname , 'fixtures' ) ;
14+ exports . testDir = __dirname ;
15+ exports . fixturesDir = path . join ( exports . testDir , 'fixtures' ) ;
1616exports . tmpDirName = 'tmp' ;
1717// PORT should match the definition in test/testpy/__init__.py.
1818exports . PORT = + process . env . NODE_COMMON_PORT || 12346 ;
@@ -28,15 +28,14 @@ exports.isOSX = process.platform === 'darwin';
2828exports . enoughTestMem = os . totalmem ( ) > 0x40000000 ; /* 1 Gb */
2929
3030var cpus = os . cpus ( ) ;
31- exports . enoughTestCpu = Array . isArray ( cpus ) && ( cpus . length > 1 || cpus [ 0 ] . speed > 999 ) ;
31+ exports . enoughTestCpu = cpus . length > 1 || cpus [ 0 ] . speed > 999 ;
3232
3333exports . rootDir = exports . isWindows ? 'c:\\' : '/' ;
3434exports . buildType = process . config . target_defaults . default_configuration ;
3535
3636function rimrafSync ( p ) {
37- var st = void 0 ;
3837 try {
39- st = fs . lstatSync ( p ) ;
38+ var st = fs . lstatSync ( p ) ;
4039 } catch ( e ) {
4140 if ( e . code === 'ENOENT' ) return ;
4241 }
@@ -147,8 +146,8 @@ Object.defineProperty(exports, 'opensslCli', { get: function () {
147146
148147 if ( exports . isWindows ) opensslCli += '.exe' ;
149148
150- var opensslCmd = child_process . spawnSync ( opensslCli , [ 'version' ] ) ;
151- if ( opensslCmd . status !== 0 || opensslCmd . error !== undefined ) {
149+ var openssl_cmd = child_process . spawnSync ( opensslCli , [ 'version' ] ) ;
150+ if ( openssl_cmd . status !== 0 || openssl_cmd . error !== undefined ) {
152151 // openssl command cannot be executed
153152 opensslCli = false ;
154153 }
@@ -176,6 +175,12 @@ if (exports.isWindows) {
176175 exports . PIPE = exports . tmpDir + '/test.sock' ;
177176}
178177
178+ if ( exports . isWindows ) {
179+ exports . faketimeCli = false ;
180+ } else {
181+ exports . faketimeCli = path . join ( __dirname , '..' , 'tools' , 'faketime' , 'src' , 'faketime' ) ;
182+ }
183+
179184var ifaces = os . networkInterfaces ( ) ;
180185exports . hasIPv6 = Object . keys ( ifaces ) . some ( function ( name ) {
181186 return ( / l o / . test ( name ) && ifaces [ name ] . some ( function ( info ) {
@@ -184,27 +189,6 @@ exports.hasIPv6 = Object.keys(ifaces).some(function (name) {
184189 ) ;
185190} ) ;
186191
187- /*
188- * Check that when running a test with
189- * `$node --abort-on-uncaught-exception $file child`
190- * the process aborts.
191- */
192- exports . childShouldThrowAndAbort = function ( ) {
193- var testCmd = '' ;
194- if ( ! exports . isWindows ) {
195- // Do not create core files, as it can take a lot of disk space on
196- // continuous testing and developers' machines
197- testCmd += 'ulimit -c 0 && ' ;
198- }
199- testCmd += process . argv [ 0 ] + ' --abort-on-uncaught-exception ' ;
200- testCmd += process . argv [ 1 ] + ' child' ;
201- var child = child_process . exec ( testCmd ) ;
202- child . on ( 'exit' , function onExit ( exitCode , signal ) {
203- var errMsg = 'Test should have aborted ' + ( 'but instead exited with exit code ' + exitCode ) + ( ' and signal ' + signal ) ;
204- assert ( exports . nodeProcessAborted ( exitCode , signal ) , errMsg ) ;
205- } ) ;
206- } ;
207-
208192exports . ddCommand = function ( filename , kilobytes ) {
209193 if ( exports . isWindows ) {
210194 var p = path . resolve ( exports . fixturesDir , 'create-file.js' ) ;
@@ -214,6 +198,26 @@ exports.ddCommand = function (filename, kilobytes) {
214198 }
215199} ;
216200
201+ exports . spawnCat = function ( options ) {
202+ var spawn = require ( 'child_process' ) . spawn ;
203+
204+ if ( exports . isWindows ) {
205+ return spawn ( 'more' , [ ] , options ) ;
206+ } else {
207+ return spawn ( 'cat' , [ ] , options ) ;
208+ }
209+ } ;
210+
211+ exports . spawnSyncCat = function ( options ) {
212+ var spawnSync = require ( 'child_process' ) . spawnSync ;
213+
214+ if ( exports . isWindows ) {
215+ return spawnSync ( 'more' , [ ] , options ) ;
216+ } else {
217+ return spawnSync ( 'cat' , [ ] , options ) ;
218+ }
219+ } ;
220+
217221exports . spawnPwd = function ( options ) {
218222 var spawn = require ( 'child_process' ) . spawn ;
219223
@@ -237,8 +241,6 @@ exports.spawnSyncPwd = function (options) {
237241exports . platformTimeout = function ( ms ) {
238242 if ( process . config . target_defaults . default_configuration === 'Debug' ) ms = 2 * ms ;
239243
240- if ( global . __coverage__ ) ms = 4 * ms ;
241-
242244 if ( exports . isAix ) return 2 * ms ; // default localhost speed is slower on AIX
243245
244246 if ( process . arch !== 'arm' ) return ms ;
@@ -252,8 +254,8 @@ exports.platformTimeout = function (ms) {
252254 return ms ; // ARMv8+
253255} ;
254256
255- var knownGlobals = [ Buffer , clearImmediate , clearInterval , clearTimeout , console , constructor , // Enumerable in V8 3.21.
256- global , process , setImmediate , setInterval , setTimeout ] ;
257+ var knownGlobals = [ setTimeout , setInterval , setImmediate , clearTimeout , clearInterval , clearImmediate , console , constructor , // Enumerable in V8 3.21.
258+ Buffer , process , global ] ;
257259
258260if ( global . gc ) {
259261 knownGlobals . push ( global . gc ) ;
@@ -333,14 +335,8 @@ function leakedGlobals() {
333335 var leaked = [ ] ;
334336
335337 for ( var val in global ) {
336- if ( ! knownGlobals . includes ( global [ val ] ) ) leaked . push ( val ) ;
337- } if ( global . __coverage__ ) {
338- return leaked . filter ( function ( varname ) {
339- return ! / ^ ( c o v _ | _ _ c o v ) / . test ( varname ) ;
340- } ) ;
341- } else {
342- return leaked ;
343- }
338+ if ( - 1 === knownGlobals . indexOf ( global [ val ] ) ) leaked . push ( val ) ;
339+ } return leaked ;
344340}
345341exports . leakedGlobals = leakedGlobals ;
346342
@@ -351,7 +347,8 @@ process.on('exit', function () {
351347 if ( ! exports . globalCheck ) return ;
352348 var leaked = leakedGlobals ( ) ;
353349 if ( leaked . length > 0 ) {
354- fail ( 'Unexpected global(s) found: ' + leaked . join ( ', ' ) ) ;
350+ console . error ( 'Unknown globals: %s' , leaked ) ;
351+ assert . ok ( false , 'Unknown global found' ) ;
355352 }
356353} ) ;
357354
@@ -373,7 +370,7 @@ function runCallChecks(exitCode) {
373370}
374371
375372exports . mustCall = function ( fn , expected ) {
376- if ( expected === undefined ) expected = 1 ; else if ( typeof expected !== 'number' ) throw new TypeError ( 'Invalid expected value: ' + expected ) ;
373+ if ( typeof expected !== 'number' ) expected = 1 ;
377374
378375 var context = {
379376 expected : expected ,
@@ -410,42 +407,8 @@ exports.fileExists = function (pathname) {
410407 }
411408} ;
412409
413- exports . canCreateSymLink = function ( ) {
414- // On Windows, creating symlinks requires admin privileges.
415- // We'll only try to run symlink test if we have enough privileges.
416- // On other platforms, creating symlinks shouldn't need admin privileges
417- if ( exports . isWindows ) {
418- // whoami.exe needs to be the one from System32
419- // If unix tools are in the path, they can shadow the one we want,
420- // so use the full path while executing whoami
421- var whoamiPath = path . join ( process . env [ 'SystemRoot' ] , 'System32' , 'whoami.exe' ) ;
422-
423- var err = false ;
424- var output = '' ;
425-
426- try {
427- output = execSync ( whoamiPath + ' /priv' , { timout : 1000 } ) ;
428- } catch ( e ) {
429- err = true ;
430- } finally {
431- if ( err || ! output . includes ( 'SeCreateSymbolicLinkPrivilege' ) ) {
432- return false ;
433- }
434- }
435- }
436-
437- return true ;
438- } ;
439-
440- function fail ( msg ) {
410+ exports . fail = function ( msg ) {
441411 assert . fail ( null , null , msg ) ;
442- }
443- exports . fail = fail ;
444-
445- exports . mustNotCall = function ( msg ) {
446- return function mustNotCall ( ) {
447- fail ( msg || 'function should not have been called' ) ;
448- } ;
449412} ;
450413
451414exports . skip = function ( msg ) {
@@ -498,9 +461,9 @@ exports.nodeProcessAborted = function nodeProcessAborted(exitCode, signal) {
498461 // one of them (exit code or signal) needs to be set to one of
499462 // the expected exit codes or signals.
500463 if ( signal !== null ) {
501- return expectedSignals . includes ( signal ) ;
464+ return expectedSignals . indexOf ( signal ) > - 1 ;
502465 } else {
503- return expectedExitCodes . includes ( exitCode ) ;
466+ return expectedExitCodes . indexOf ( exitCode ) > - 1 ;
504467 }
505468} ;
506469
@@ -528,56 +491,4 @@ exports.expectWarning = function (name, expected) {
528491 // get each message only once.
529492 expected . splice ( expected . indexOf ( warning . message ) , 1 ) ;
530493 } , expected . length ) ) ;
531- } ;
532-
533- Object . defineProperty ( exports , 'hasIntl' , {
534- get : function ( ) {
535- return process . binding ( 'config' ) . hasIntl ;
536- }
537- } ) ;
538-
539- // https://github.com/w3c/testharness.js/blob/master/testharness.js
540- exports . WPT = {
541- test : function ( fn , desc ) {
542- try {
543- fn ( ) ;
544- } catch ( err ) {
545- if ( err instanceof Error ) err . message = 'In ' + desc + ':\n ' + err . message ;
546- throw err ;
547- }
548- } ,
549- assert_equals : assert . strictEqual ,
550- assert_true : function ( value , message ) {
551- return assert . strictEqual ( value , true , message ) ;
552- } ,
553- assert_false : function ( value , message ) {
554- return assert . strictEqual ( value , false , message ) ;
555- } ,
556- assert_throws : function ( code , func , desc ) {
557- assert . throws ( func , function ( err ) {
558- return typeof err === 'object' && 'name' in err && err . name === code . name ;
559- } , desc ) ;
560- } ,
561- assert_array_equals : assert . deepStrictEqual ,
562- assert_unreached : function ( desc ) {
563- assert . fail ( undefined , undefined , 'Reached unreachable code: ' + desc ) ;
564- }
565- } ;
566-
567- // Useful for testing expected internal/error objects
568- exports . expectsError = function expectsError ( _ref ) {
569- var code = _ref . code ,
570- type = _ref . type ,
571- message = _ref . message ;
572-
573- return function ( error ) {
574- assert . strictEqual ( error . code , code ) ;
575- if ( type !== undefined ) assert ( error instanceof type , error + ' is not the expected type ' + type ) ;
576- if ( message instanceof RegExp ) {
577- assert ( message . test ( error . message ) , error . message + ' does not match ' + message ) ;
578- } else if ( typeof message === 'string' ) {
579- assert . strictEqual ( error . message , message ) ;
580- }
581- return true ;
582- } ;
583494} ;
0 commit comments