-
-
Notifications
You must be signed in to change notification settings - Fork 498
Expand file tree
/
Copy pathindex.js
More file actions
134 lines (120 loc) · 3.98 KB
/
index.js
File metadata and controls
134 lines (120 loc) · 3.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
'use strict';
process.config.target_defaults.default_configuration =
require('fs')
.readdirSync(require('path').join(__dirname, 'build'))
.filter((item) => (item === 'Debug' || item === 'Release'))[0];
// FIXME: We might need a way to load test modules automatically without
// explicit declaration as follows.
let testModules = [
'addon',
'addon_data',
'arraybuffer',
'asynccontext',
'asyncprogressqueueworker',
'asyncprogressworker',
'asyncworker',
'asyncworker-nocallback',
'asyncworker-persistent',
'basic_types/array',
'basic_types/boolean',
'basic_types/number',
'basic_types/value',
'bigint',
'date',
'buffer',
'callbackscope',
'dataview/dataview',
'dataview/dataview_read_write',
'error',
'external',
'function',
'handlescope',
'memory_management',
'name',
'object/delete_property',
'object/finalizer',
'object/get_property',
'object/has_own_property',
'object/has_property',
'object/object',
'object/object_deprecated',
'object/set_property',
'promise',
'run_script',
'threadsafe_function/threadsafe_function_ctx',
'threadsafe_function/threadsafe_function_existing_tsfn',
'threadsafe_function/threadsafe_function_ptr',
'threadsafe_function/threadsafe_function_sum',
'threadsafe_function/threadsafe_function_unref',
'threadsafe_function/threadsafe_function',
'typedarray',
'typedarray-bigint',
'objectwrap',
'objectwrap_constructor_exception',
'objectwrap-removewrap',
'objectwrap_multiple_inheritance',
'objectwrap_worker_thread',
'objectreference',
'reference',
'version_management'
];
const napiVersion = Number(process.versions.napi)
const majorNodeVersion = process.versions.node.split('.')[0]
if (napiVersion < 3) {
testModules.splice(testModules.indexOf('callbackscope'), 1);
testModules.splice(testModules.indexOf('version_management'), 1);
}
if (napiVersion < 4) {
testModules.splice(testModules.indexOf('asyncprogressqueueworker'), 1);
testModules.splice(testModules.indexOf('asyncprogressworker'), 1);
testModules.splice(testModules.indexOf('threadsafe_function/threadsafe_function_ctx'), 1);
testModules.splice(testModules.indexOf('threadsafe_function/threadsafe_function_existing_tsfn'), 1);
testModules.splice(testModules.indexOf('threadsafe_function/threadsafe_function_ptr'), 1);
testModules.splice(testModules.indexOf('threadsafe_function/threadsafe_function_sum'), 1);
testModules.splice(testModules.indexOf('threadsafe_function/threadsafe_function_unref'), 1);
testModules.splice(testModules.indexOf('threadsafe_function/threadsafe_function'), 1);
}
if (napiVersion < 5) {
testModules.splice(testModules.indexOf('date'), 1);
}
if (napiVersion < 6) {
testModules.splice(testModules.indexOf('addon'), 1);
testModules.splice(testModules.indexOf('addon_data'), 1);
testModules.splice(testModules.indexOf('bigint'), 1);
testModules.splice(testModules.indexOf('typedarray-bigint'), 1);
}
if (majorNodeVersion < 12) {
testModules.splice(testModules.indexOf('objectwrap_worker_thread'), 1);
}
if (typeof global.gc === 'function') {
(async function() {
console.log(`Testing with N-API Version '${napiVersion}'.`);
console.log('Starting test suite\n');
// Requiring each module runs tests in the module.
for (const name of testModules) {
console.log(`Running test '${name}'`);
await require('./' + name);
};
console.log('\nAll tests passed!');
})().catch((error) => {
console.log(error);
process.exit(1);
});
} else {
// Construct the correct (version-dependent) command-line args.
let args = ['--expose-gc', '--no-concurrent-array-buffer-freeing'];
if (majorNodeVersion >= 14) {
args.push('--no-concurrent-array-buffer-sweeping');
}
args.push(__filename);
const child = require('./napi_child').spawnSync(process.argv[0], args, {
stdio: 'inherit',
});
if (child.signal) {
console.error(`Tests aborted with ${child.signal}`);
process.exitCode = 1;
} else {
process.exitCode = child.status;
}
process.exit(process.exitCode);
}