Skip to content

Commit b6f5eb1

Browse files
legendecasmhdawson
authored andcommitted
test: run test suites with helpers
PR-URL: #976 Reviewed-By: Michael Dawson <midawson@redhat.com>
1 parent fbcdf00 commit b6f5eb1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+191
-260
lines changed

test/addon.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
'use strict';
2-
const buildType = process.config.target_defaults.default_configuration;
2+
33
const assert = require('assert');
44

5-
test(require(`./build/${buildType}/binding.node`));
6-
test(require(`./build/${buildType}/binding_noexcept.node`));
5+
module.exports = require('./common').runTest(test);
76

87
function test(binding) {
98
assert.strictEqual(binding.addon.increment(), 43);

test/addon_data.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,10 @@
11
'use strict';
2-
const buildType = process.config.target_defaults.default_configuration;
2+
33
const assert = require('assert');
44
const { spawn } = require('child_process');
55
const readline = require('readline');
6-
const path = require('path');
76

8-
module.exports =
9-
test(path.resolve(__dirname, `./build/${buildType}/binding.node`))
10-
.then(() =>
11-
test(path.resolve(__dirname,
12-
`./build/${buildType}/binding_noexcept.node`)));
7+
module.exports = require('./common').runTestWithBindingPath(test);
138

149
// Make sure the instance data finalizer is called at process exit. If the hint
1510
// is non-zero, it will be printed out by the child process.

test/arraybuffer.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
'use strict';
2-
const buildType = process.config.target_defaults.default_configuration;
2+
33
const assert = require('assert');
44
const testUtil = require('./testUtil');
55

6-
module.exports = test(require(`./build/${buildType}/binding.node`))
7-
.then(() => test(require(`./build/${buildType}/binding_noexcept.node`)));
6+
module.exports = require('./common').runTest(test);
87

98
function test(binding) {
109
return testUtil.runGCTests([

test/asynccontext.js

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
'use strict';
2-
const buildType = process.config.target_defaults.default_configuration;
2+
33
const assert = require('assert');
44
const common = require('./common');
55

@@ -17,14 +17,27 @@ function checkAsyncHooks() {
1717
return false;
1818
}
1919

20-
test(require(`./build/${buildType}/binding.node`));
21-
test(require(`./build/${buildType}/binding_noexcept.node`));
20+
module.exports = common.runTest(test);
2221

2322
function installAsyncHooksForTest() {
2423
return new Promise((resolve, reject) => {
2524
let id;
2625
const events = [];
27-
const hook = async_hooks.createHook({
26+
/**
27+
* TODO(legendecas): investigate why resolving & disabling hooks in
28+
* destroy callback causing crash with case 'callbackscope.js'.
29+
*/
30+
let hook;
31+
let destroyed = false;
32+
const interval = setInterval(() => {
33+
if (destroyed) {
34+
hook.disable();
35+
clearInterval(interval);
36+
resolve(events);
37+
}
38+
}, 10);
39+
40+
hook = async_hooks.createHook({
2841
init(asyncId, type, triggerAsyncId, resource) {
2942
if (id === undefined && type === 'async_context_test') {
3043
id = asyncId;
@@ -44,30 +57,30 @@ function installAsyncHooksForTest() {
4457
destroy(asyncId) {
4558
if (asyncId === id) {
4659
events.push({ eventName: 'destroy' });
47-
hook.disable();
48-
resolve(events);
60+
destroyed = true;
4961
}
5062
}
5163
}).enable();
5264
});
5365
}
5466

5567
function test(binding) {
56-
binding.asynccontext.makeCallback(common.mustCall(), { foo: 'foo' });
57-
if (!checkAsyncHooks())
68+
if (!checkAsyncHooks()) {
5869
return;
70+
}
5971

6072
const hooks = installAsyncHooksForTest();
6173
const triggerAsyncId = async_hooks.executionAsyncId();
62-
hooks.then(actual => {
63-
assert.deepStrictEqual(actual, [
64-
{ eventName: 'init',
65-
type: 'async_context_test',
66-
triggerAsyncId: triggerAsyncId,
67-
resource: { foo: 'foo' } },
68-
{ eventName: 'before' },
69-
{ eventName: 'after' },
70-
{ eventName: 'destroy' }
71-
]);
74+
binding.asynccontext.makeCallback(common.mustCall(), { foo: 'foo' });
75+
return hooks.then(actual => {
76+
assert.deepStrictEqual(actual, [
77+
{ eventName: 'init',
78+
type: 'async_context_test',
79+
triggerAsyncId: triggerAsyncId,
80+
resource: { foo: 'foo' } },
81+
{ eventName: 'before' },
82+
{ eventName: 'after' },
83+
{ eventName: 'destroy' }
84+
]);
7285
}).catch(common.mustNotCall());
7386
}

test/asyncprogressqueueworker.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
'use strict';
2-
const buildType = process.config.target_defaults.default_configuration;
2+
33
const common = require('./common')
44
const assert = require('assert');
5-
const os = require('os');
65

7-
module.exports = test(require(`./build/${buildType}/binding.node`))
8-
.then(() => test(require(`./build/${buildType}/binding_noexcept.node`)));
6+
module.exports = common.runTest(test);
97

108
async function test({ asyncprogressqueueworker }) {
119
await success(asyncprogressqueueworker);

test/asyncprogressworker.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
'use strict';
2-
const buildType = process.config.target_defaults.default_configuration;
2+
33
const common = require('./common')
44
const assert = require('assert');
55

6-
module.exports = test(require(`./build/${buildType}/binding.node`))
7-
.then(() => test(require(`./build/${buildType}/binding_noexcept.node`)));
6+
module.exports = common.runTest(test);
87

98
async function test({ asyncprogressworker }) {
109
await success(asyncprogressworker);

test/asyncworker-nocallback.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
'use strict';
2-
const buildType = process.config.target_defaults.default_configuration;
2+
33
const common = require('./common');
44

5-
module.exports = test(require(`./build/${buildType}/binding.node`))
6-
.then(() => test(require(`./build/${buildType}/binding_noexcept.node`)));
5+
module.exports = common.runTest(test);
76

87
async function test(binding) {
98
await binding.asyncworker.doWorkNoCallback(true, {})

test/asyncworker-persistent.js

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
'use strict';
2-
const buildType = process.config.target_defaults.default_configuration;
2+
33
const assert = require('assert');
4-
const common = require('./common');
5-
const binding = require(`./build/${buildType}/binding.node`);
6-
const noexceptBinding = require(`./build/${buildType}/binding_noexcept.node`);
74

85
function test(binding, succeed) {
96
return new Promise((resolve) =>
@@ -21,7 +18,7 @@ function test(binding, succeed) {
2118
}));
2219
}
2320

24-
module.exports = test(binding.persistentasyncworker, false)
25-
.then(() => test(binding.persistentasyncworker, true))
26-
.then(() => test(noexceptBinding.persistentasyncworker, false))
27-
.then(() => test(noexceptBinding.persistentasyncworker, true));
21+
module.exports = require('./common').runTest(async binding => {
22+
await test(binding.persistentasyncworker, false);
23+
await test(binding.persistentasyncworker, true);
24+
});

test/asyncworker.js

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
'use strict';
2-
const buildType = process.config.target_defaults.default_configuration;
32
const assert = require('assert');
43
const common = require('./common');
54

@@ -17,14 +16,27 @@ function checkAsyncHooks() {
1716
return false;
1817
}
1918

20-
module.exports = test(require(`./build/${buildType}/binding.node`))
21-
.then(() => test(require(`./build/${buildType}/binding_noexcept.node`)));
19+
module.exports = common.runTest(test);
2220

2321
function installAsyncHooksForTest() {
2422
return new Promise((resolve, reject) => {
2523
let id;
2624
const events = [];
27-
const hook = async_hooks.createHook({
25+
/**
26+
* TODO(legendecas): investigate why resolving & disabling hooks in
27+
* destroy callback causing crash with case 'callbackscope.js'.
28+
*/
29+
let hook;
30+
let destroyed = false;
31+
const interval = setInterval(() => {
32+
if (destroyed) {
33+
hook.disable();
34+
clearInterval(interval);
35+
resolve(events);
36+
}
37+
}, 10);
38+
39+
hook = async_hooks.createHook({
2840
init(asyncId, type, triggerAsyncId, resource) {
2941
if (id === undefined && type === 'TestResource') {
3042
id = asyncId;
@@ -44,8 +56,7 @@ function installAsyncHooksForTest() {
4456
destroy(asyncId) {
4557
if (asyncId === id) {
4658
events.push({ eventName: 'destroy' });
47-
hook.disable();
48-
resolve(events);
59+
destroyed = true;
4960
}
5061
}
5162
}).enable();

test/basic_types/array.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
'use strict';
2-
const buildType = process.config.target_defaults.default_configuration;
32
const assert = require('assert');
43

5-
test(require(`../build/${buildType}/binding.node`));
6-
test(require(`../build/${buildType}/binding_noexcept.node`));
4+
module.exports = require('../common').runTest(test);
75

86
function test(binding) {
97

test/basic_types/boolean.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
'use strict';
2-
const buildType = process.config.target_defaults.default_configuration;
2+
33
const assert = require('assert');
44

5-
test(require(`../build/${buildType}/binding.node`));
6-
test(require(`../build/${buildType}/binding_noexcept.node`));
5+
module.exports = require('../common').runTest(test);
76

87
function test(binding) {
98
const bool1 = binding.basic_types_boolean.createBoolean(true);

test/basic_types/number.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
'use strict';
22

3-
const buildType = process.config.target_defaults.default_configuration;
43
const assert = require('assert');
54

6-
test(require(`../build/${buildType}/binding.node`));
7-
test(require(`../build/${buildType}/binding_noexcept.node`));
5+
module.exports = require('../common').runTest(test);
86

97
function test(binding) {
108
const MIN_INT32 = -2147483648;

test/basic_types/value.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
'use strict';
22

3-
const buildType = process.config.target_defaults.default_configuration;
43
const assert = require('assert');
54

6-
test(require(`../build/${buildType}/binding.node`));
7-
test(require(`../build/${buildType}/binding_noexcept.node`));
5+
module.exports = require('../common').runTest(test);
86

97
function test(binding) {
108
const externalValue = binding.basic_types_value.createExternal();

test/bigint.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
'use strict';
22

3-
const buildType = process.config.target_defaults.default_configuration;
43
const assert = require('assert');
54

6-
test(require(`./build/${buildType}/binding.node`));
7-
test(require(`./build/${buildType}/binding_noexcept.node`));
5+
module.exports = require('./common').runTest(test);
86

97
function test(binding) {
108
const {

test/buffer.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
'use strict';
2-
const buildType = process.config.target_defaults.default_configuration;
2+
33
const assert = require('assert');
44
const testUtil = require('./testUtil');
55
const safeBuffer = require('safe-buffer');
66

7-
module.exports = test(require(`./build/${buildType}/binding.node`))
8-
.then(() => test(require(`./build/${buildType}/binding_noexcept.node`)));
7+
module.exports = require('./common').runTest(test);
98

109
function test(binding) {
1110
return testUtil.runGCTests([

test/callbackscope.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
'use strict';
2-
const buildType = process.config.target_defaults.default_configuration;
32
const assert = require('assert');
4-
const common = require('./common');
53

64
// we only check async hooks on 8.x an higher were
75
// they are closer to working properly
@@ -17,16 +15,15 @@ function checkAsyncHooks() {
1715
return false;
1816
}
1917

20-
test(require(`./build/${buildType}/binding.node`));
21-
test(require(`./build/${buildType}/binding_noexcept.node`));
18+
module.exports = require('./common').runTest(test);
2219

2320
function test(binding) {
2421
if (!checkAsyncHooks())
2522
return;
2623

2724
let id;
2825
let insideHook = false;
29-
async_hooks.createHook({
26+
const hook = async_hooks.createHook({
3027
init(asyncId, type, triggerAsyncId, resource) {
3128
if (id === undefined && type === 'callback_scope_test') {
3229
id = asyncId;
@@ -42,7 +39,11 @@ function test(binding) {
4239
}
4340
}).enable();
4441

45-
binding.callbackscope.runInCallbackScope(function() {
46-
assert(insideHook);
42+
return new Promise(resolve => {
43+
binding.callbackscope.runInCallbackScope(function() {
44+
assert(insideHook);
45+
hook.disable();
46+
resolve();
47+
});
4748
});
4849
}

test/common/index.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,30 @@ exports.mustNotCall = function(msg) {
7474
assert.fail(msg || 'function should not have been called');
7575
};
7676
};
77+
78+
exports.runTest = async function(test, buildType) {
79+
buildType = buildType || process.config.target_defaults.default_configuration;
80+
81+
const bindings = [
82+
`../build/${buildType}/binding.node`,
83+
`../build/${buildType}/binding_noexcept.node`,
84+
].map(it => require.resolve(it));
85+
86+
for (const item of bindings) {
87+
await Promise.resolve(test(require(item)))
88+
.finally(exports.mustCall());
89+
}
90+
}
91+
92+
exports.runTestWithBindingPath = async function(test, buildType) {
93+
buildType = buildType || process.config.target_defaults.default_configuration;
94+
95+
const bindings = [
96+
`../build/${buildType}/binding.node`,
97+
`../build/${buildType}/binding_noexcept.node`,
98+
].map(it => require.resolve(it));
99+
100+
for (const item of bindings) {
101+
await test(item);
102+
}
103+
}

test/dataview/dataview.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
'use strict';
22

3-
const buildType = process.config.target_defaults.default_configuration;
43
const assert = require('assert');
5-
6-
test(require(`../build/${buildType}/binding.node`));
7-
test(require(`../build/${buildType}/binding_noexcept.node`));
4+
module.exports = require('../common').runTest(test);
85

96
function test(binding) {
107
function testDataViewCreation(factory, arrayBuffer, offset, length) {

0 commit comments

Comments
 (0)