Skip to content

Commit 9e68947

Browse files
danbevMylesBorins
authored andcommitted
test: add hasCrypto when using binding('crypto')
Currently, when configured --without-ssl tests that use process.binding('crypto') fail with the following error: === release test-accessor-properties === Path: parallel/test-accessor-properties node/test/parallel/test-accessor-properties.js:16 const crypto = process.binding('crypto'); ^ Error: No such module: crypto at Object.<anonymous> (test-accessor-properties.js:16:24) at Module._compile (module.js:660:30) at Object.Module._extensions..js (module.js:671:10) at Module.load (module.js:577:32) at tryModuleLoad (module.js:517:12) at Function.Module._load (module.js:509:3) at Function.Module.runMain (module.js:701:10) at startup (bootstrap_node.js:194:16) at bootstrap_node.js:645:3 This commit adds a hasCrypto check. Backport-PR-URL: #20456 PR-URL: #17867 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
1 parent f3e082c commit 9e68947

File tree

1 file changed

+25
-24
lines changed

1 file changed

+25
-24
lines changed

test/parallel/test-accessor-properties.js

+25-24
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict';
22

3-
require('../common');
3+
const common = require('../common');
44

55
// This tests that the accessor properties do not raise assertions
66
// when called with incompatible receivers.
@@ -12,9 +12,6 @@ const assert = require('assert');
1212
const TTY = process.binding('tty_wrap').TTY;
1313
const UDP = process.binding('udp_wrap').UDP;
1414

15-
// There are accessor properties in crypto too
16-
const crypto = process.binding('crypto');
17-
1815
{
1916
// Should throw instead of raise assertions
2017
assert.throws(() => {
@@ -33,15 +30,6 @@ const crypto = process.binding('crypto');
3330
UDP.prototype.fd;
3431
}, TypeError);
3532

36-
assert.throws(() => {
37-
crypto.SecureContext.prototype._external;
38-
}, TypeError);
39-
40-
assert.throws(() => {
41-
crypto.Connection.prototype._external;
42-
}, TypeError);
43-
44-
4533
// Should not throw for Object.getOwnPropertyDescriptor
4634
assert.strictEqual(
4735
typeof Object.getOwnPropertyDescriptor(TTY.prototype, 'bytesRead'),
@@ -63,15 +51,28 @@ const crypto = process.binding('crypto');
6351
'object'
6452
);
6553

66-
assert.strictEqual(
67-
typeof Object.getOwnPropertyDescriptor(
68-
crypto.SecureContext.prototype, '_external'),
69-
'object'
70-
);
71-
72-
assert.strictEqual(
73-
typeof Object.getOwnPropertyDescriptor(
74-
crypto.Connection.prototype, '_external'),
75-
'object'
76-
);
54+
if (common.hasCrypto) { // eslint-disable-line crypto-check
55+
// There are accessor properties in crypto too
56+
const crypto = process.binding('crypto');
57+
58+
assert.throws(() => {
59+
crypto.SecureContext.prototype._external;
60+
}, TypeError);
61+
62+
assert.throws(() => {
63+
crypto.Connection.prototype._external;
64+
}, TypeError);
65+
66+
assert.strictEqual(
67+
typeof Object.getOwnPropertyDescriptor(
68+
crypto.SecureContext.prototype, '_external'),
69+
'object'
70+
);
71+
72+
assert.strictEqual(
73+
typeof Object.getOwnPropertyDescriptor(
74+
crypto.Connection.prototype, '_external'),
75+
'object'
76+
);
77+
}
7778
}

0 commit comments

Comments
 (0)