@@ -4,7 +4,7 @@ const majorNodeVersion = process.versions.node.split('.')[0];
4
4
5
5
if ( typeof global . gc !== 'function' ) {
6
6
// Construct the correct (version-dependent) command-line args.
7
- let args = [ '--expose-gc' ] ;
7
+ const args = [ '--expose-gc' ] ;
8
8
const majorV8Version = process . versions . v8 . split ( '.' ) [ 0 ] ;
9
9
if ( majorV8Version < 9 ) {
10
10
args . push ( '--no-concurrent-array-buffer-freeing' ) ;
@@ -15,7 +15,7 @@ if (typeof global.gc !== 'function') {
15
15
args . push ( __filename ) ;
16
16
17
17
const child = require ( './napi_child' ) . spawnSync ( process . argv [ 0 ] , args , {
18
- stdio : 'inherit' ,
18
+ stdio : 'inherit'
19
19
} ) ;
20
20
21
21
if ( child . signal ) {
@@ -27,17 +27,36 @@ if (typeof global.gc !== 'function') {
27
27
process . exit ( process . exitCode ) ;
28
28
}
29
29
30
+ const testModules = [ ] ;
31
+
30
32
const fs = require ( 'fs' ) ;
31
33
const path = require ( 'path' ) ;
32
34
33
- let testModules = [ ] ;
35
+ let filterCondition = process . env . npm_config_filter || '' ;
36
+ let filterConditionFiles = [ ] ;
37
+
38
+ if ( filterCondition !== '' ) {
39
+ filterCondition = require ( '../unit-test/matchModules' ) . matchWildCards ( process . env . npm_config_filter ) ;
40
+ filterConditionFiles = filterCondition . split ( ' ' ) . length > 0 ? filterCondition . split ( ' ' ) : [ filterCondition ] ;
41
+ }
42
+
43
+ const filterConditionsProvided = filterConditionFiles . length > 0 ;
44
+
45
+ function checkFilterCondition ( fileName , parsedFilepath ) {
46
+ let result = false ;
47
+
48
+ if ( ! filterConditionsProvided ) return true ;
49
+ if ( filterConditionFiles . includes ( parsedFilepath ) ) result = true ;
50
+ if ( filterConditionFiles . includes ( fileName ) ) result = true ;
51
+ return result ;
52
+ }
34
53
35
54
// TODO(RaisinTen): Update this when the test filenames
36
55
// are changed into test_*.js.
37
- function loadTestModules ( currentDirectory = __dirname , pre = '' ) {
56
+ function loadTestModules ( currentDirectory = __dirname , pre = '' ) {
38
57
fs . readdirSync ( currentDirectory ) . forEach ( ( file ) => {
39
58
if ( currentDirectory === __dirname && (
40
- file === 'binding.cc' ||
59
+ file === 'binding.cc' ||
41
60
file === 'binding.gyp' ||
42
61
file === 'build' ||
43
62
file === 'common' ||
@@ -50,15 +69,19 @@ function loadTestModules(currentDirectory = __dirname, pre = '') {
50
69
return ;
51
70
}
52
71
const absoluteFilepath = path . join ( currentDirectory , file ) ;
72
+ const parsedFilepath = path . parse ( file ) ;
73
+ const parsedPath = path . parse ( currentDirectory ) ;
74
+
53
75
if ( fs . statSync ( absoluteFilepath ) . isDirectory ( ) ) {
54
76
if ( fs . existsSync ( absoluteFilepath + '/index.js' ) ) {
55
- testModules . push ( pre + file ) ;
77
+ if ( checkFilterCondition ( parsedFilepath . name , parsedPath . base ) ) {
78
+ testModules . push ( pre + file ) ;
79
+ }
56
80
} else {
57
81
loadTestModules ( absoluteFilepath , pre + file + '/' ) ;
58
82
}
59
83
} else {
60
- const parsedFilepath = path . parse ( file ) ;
61
- if ( parsedFilepath . ext === '.js' ) {
84
+ if ( parsedFilepath . ext === '.js' && checkFilterCondition ( parsedFilepath . name , parsedPath . base ) ) {
62
85
testModules . push ( pre + parsedFilepath . name ) ;
63
86
}
64
87
}
@@ -69,7 +92,7 @@ loadTestModules();
69
92
70
93
process . config . target_defaults . default_configuration =
71
94
fs
72
- . readdirSync ( path . join ( __dirname , 'build' ) )
95
+ . readdirSync ( path . join ( __dirname , process . env . REL_BUILD_PATH || '' , 'build' ) )
73
96
. filter ( ( item ) => ( item === 'Debug' || item === 'Release' ) ) [ 0 ] ;
74
97
75
98
let napiVersion = Number ( process . versions . napi ) ;
@@ -87,7 +110,7 @@ if (napiVersion < 3) {
87
110
testModules . splice ( testModules . indexOf ( 'version_management' ) , 1 ) ;
88
111
}
89
112
90
- if ( napiVersion < 4 ) {
113
+ if ( napiVersion < 4 && ! filterConditionsProvided ) {
91
114
testModules . splice ( testModules . indexOf ( 'asyncprogressqueueworker' ) , 1 ) ;
92
115
testModules . splice ( testModules . indexOf ( 'asyncprogressworker' ) , 1 ) ;
93
116
testModules . splice ( testModules . indexOf ( 'threadsafe_function/threadsafe_function_ctx' ) , 1 ) ;
@@ -98,36 +121,36 @@ if (napiVersion < 4) {
98
121
testModules . splice ( testModules . indexOf ( 'threadsafe_function/threadsafe_function' ) , 1 ) ;
99
122
}
100
123
101
- if ( napiVersion < 5 ) {
124
+ if ( napiVersion < 5 && ! filterConditionsProvided ) {
102
125
testModules . splice ( testModules . indexOf ( 'date' ) , 1 ) ;
103
126
}
104
127
105
- if ( napiVersion < 6 ) {
128
+ if ( napiVersion < 6 && ! filterConditionsProvided ) {
106
129
testModules . splice ( testModules . indexOf ( 'addon' ) , 1 ) ;
107
130
testModules . splice ( testModules . indexOf ( 'addon_data' ) , 1 ) ;
108
131
testModules . splice ( testModules . indexOf ( 'bigint' ) , 1 ) ;
109
132
testModules . splice ( testModules . indexOf ( 'typedarray-bigint' ) , 1 ) ;
110
133
}
111
134
112
- if ( majorNodeVersion < 12 ) {
135
+ if ( majorNodeVersion < 12 && ! filterConditionsProvided ) {
113
136
testModules . splice ( testModules . indexOf ( 'objectwrap_worker_thread' ) , 1 ) ;
114
137
testModules . splice ( testModules . indexOf ( 'error_terminating_environment' ) , 1 ) ;
115
138
}
116
139
117
- if ( napiVersion < 8 ) {
140
+ if ( napiVersion < 8 && ! filterConditionsProvided ) {
118
141
testModules . splice ( testModules . indexOf ( 'object/object_freeze_seal' ) , 1 ) ;
119
142
}
120
143
121
- ( async function ( ) {
144
+ ( async function ( ) {
122
145
console . log ( `Testing with Node-API Version '${ napiVersion } '.` ) ;
123
146
124
- console . log ( 'Starting test suite\n' ) ;
147
+ if ( filterConditionsProvided ) { console . log ( 'Starting test suite\n' , testModules ) ; } else { console . log ( 'Starting test suite\n' ) ; }
125
148
126
149
// Requiring each module runs tests in the module.
127
150
for ( const name of testModules ) {
128
151
console . log ( `Running test '${ name } '` ) ;
129
152
await require ( './' + name ) ;
130
- } ;
153
+ }
131
154
132
155
console . log ( '\nAll tests passed!' ) ;
133
156
} ) ( ) . catch ( ( error ) => {
0 commit comments