Skip to content

Commit b6f5eb1

Browse files
legendecasmhdawson
authored andcommitted
test: run test suites with helpers
PR-URL: #976 Reviewed-By: Michael Dawson <[email protected]>
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

0 commit comments

Comments
 (0)