1
1
'use strict' ;
2
2
3
+ const majorNodeVersion = process . versions . node . split ( '.' ) [ 0 ] ;
4
+
5
+ if ( typeof global . gc !== 'function' ) {
6
+ // Construct the correct (version-dependent) command-line args.
7
+ let args = [ '--expose-gc' , '--no-concurrent-array-buffer-freeing' ] ;
8
+ if ( majorNodeVersion >= 14 ) {
9
+ args . push ( '--no-concurrent-array-buffer-sweeping' ) ;
10
+ }
11
+ args . push ( __filename ) ;
12
+
13
+ const child = require ( './napi_child' ) . spawnSync ( process . argv [ 0 ] , args , {
14
+ stdio : 'inherit' ,
15
+ } ) ;
16
+
17
+ if ( child . signal ) {
18
+ console . error ( `Tests aborted with ${ child . signal } ` ) ;
19
+ process . exitCode = 1 ;
20
+ } else {
21
+ process . exitCode = child . status ;
22
+ }
23
+ process . exit ( process . exitCode ) ;
24
+ }
25
+
3
26
process . config . target_defaults . default_configuration =
4
27
require ( 'fs' )
5
28
. readdirSync ( require ( 'path' ) . join ( __dirname , 'build' ) )
@@ -68,7 +91,7 @@ let testModules = [
68
91
'version_management'
69
92
] ;
70
93
71
- let napiVersion = Number ( process . versions . napi )
94
+ let napiVersion = Number ( process . versions . napi ) ;
72
95
if ( process . env . NAPI_VERSION ) {
73
96
// we need this so that we don't try run tests that rely
74
97
// on methods that are not available in the NAPI_VERSION
@@ -77,8 +100,6 @@ if (process.env.NAPI_VERSION) {
77
100
}
78
101
console . log ( 'napiVersion:' + napiVersion ) ;
79
102
80
- const majorNodeVersion = process . versions . node . split ( '.' ) [ 0 ]
81
-
82
103
if ( napiVersion < 3 ) {
83
104
testModules . splice ( testModules . indexOf ( 'callbackscope' ) , 1 ) ;
84
105
testModules . splice ( testModules . indexOf ( 'version_management' ) , 1 ) ;
@@ -110,40 +131,19 @@ if (majorNodeVersion < 12) {
110
131
testModules . splice ( testModules . indexOf ( 'objectwrap_worker_thread' ) , 1 ) ;
111
132
}
112
133
113
- if ( typeof global . gc === 'function' ) {
114
- ( async function ( ) {
115
- console . log ( `Testing with N-API Version '${ napiVersion } '.` ) ;
134
+ ( async function ( ) {
135
+ console . log ( `Testing with N-API Version '${ napiVersion } '.` ) ;
116
136
117
- console . log ( 'Starting test suite\n' ) ;
137
+ console . log ( 'Starting test suite\n' ) ;
118
138
119
- // Requiring each module runs tests in the module.
120
- for ( const name of testModules ) {
121
- console . log ( `Running test '${ name } '` ) ;
122
- await require ( './' + name ) ;
123
- } ;
139
+ // Requiring each module runs tests in the module.
140
+ for ( const name of testModules ) {
141
+ console . log ( `Running test '${ name } '` ) ;
142
+ await require ( './' + name ) ;
143
+ } ;
124
144
125
- console . log ( '\nAll tests passed!' ) ;
126
- } ) ( ) . catch ( ( error ) => {
127
- console . log ( error ) ;
128
- process . exit ( 1 ) ;
129
- } ) ;
130
- } else {
131
- // Construct the correct (version-dependent) command-line args.
132
- let args = [ '--expose-gc' , '--no-concurrent-array-buffer-freeing' ] ;
133
- if ( majorNodeVersion >= 14 ) {
134
- args . push ( '--no-concurrent-array-buffer-sweeping' ) ;
135
- }
136
- args . push ( __filename ) ;
137
-
138
- const child = require ( './napi_child' ) . spawnSync ( process . argv [ 0 ] , args , {
139
- stdio : 'inherit' ,
140
- } ) ;
141
-
142
- if ( child . signal ) {
143
- console . error ( `Tests aborted with ${ child . signal } ` ) ;
144
- process . exitCode = 1 ;
145
- } else {
146
- process . exitCode = child . status ;
147
- }
148
- process . exit ( process . exitCode ) ;
149
- }
145
+ console . log ( '\nAll tests passed!' ) ;
146
+ } ) ( ) . catch ( ( error ) => {
147
+ console . log ( error ) ;
148
+ process . exit ( 1 ) ;
149
+ } ) ;
0 commit comments