2017-10-11 05:42:47 +00:00
|
|
|
'use strict';
|
|
|
|
|
2018-02-15 23:47:10 +00:00
|
|
|
const common = require('../common');
|
2021-12-07 10:01:36 +00:00
|
|
|
if ((!common.hasCrypto) || (!common.hasIntl)) {
|
|
|
|
common.skip('ESLint tests require crypto and Intl');
|
|
|
|
}
|
2018-02-15 23:47:10 +00:00
|
|
|
|
|
|
|
common.skipIfEslintMissing();
|
2017-10-11 05:42:47 +00:00
|
|
|
|
2024-06-19 19:54:08 +00:00
|
|
|
const RuleTester = require('../../tools/eslint/node_modules/eslint').RuleTester;
|
2017-10-11 05:42:47 +00:00
|
|
|
const rule = require('../../tools/eslint-rules/crypto-check');
|
|
|
|
|
|
|
|
const message = 'Please add a hasCrypto check to allow this test to be ' +
|
|
|
|
'skipped when Node is built "--without-ssl".';
|
|
|
|
|
|
|
|
new RuleTester().run('crypto-check', rule, {
|
|
|
|
valid: [
|
|
|
|
'foo',
|
|
|
|
'crypto',
|
|
|
|
`
|
2017-10-31 19:38:45 +00:00
|
|
|
if (!common.hasCrypto) {
|
|
|
|
common.skip("missing crypto");
|
|
|
|
}
|
|
|
|
require("crypto");
|
2019-01-08 15:36:28 +00:00
|
|
|
`,
|
|
|
|
`
|
|
|
|
if (!common.hasCrypto) {
|
|
|
|
common.skip("missing crypto");
|
|
|
|
}
|
|
|
|
internalBinding("crypto");
|
2021-03-26 15:51:08 +00:00
|
|
|
`,
|
2017-10-11 05:42:47 +00:00
|
|
|
],
|
|
|
|
invalid: [
|
2019-01-08 18:02:15 +00:00
|
|
|
{
|
|
|
|
code: 'require("common")\n' +
|
|
|
|
'require("crypto")\n' +
|
|
|
|
'if (!common.hasCrypto) {\n' +
|
|
|
|
' common.skip("missing crypto");\n' +
|
|
|
|
'}',
|
|
|
|
errors: [{ message }]
|
|
|
|
},
|
2017-10-11 05:42:47 +00:00
|
|
|
{
|
2017-10-31 19:38:45 +00:00
|
|
|
code: 'require("common")\n' +
|
|
|
|
'require("crypto")',
|
|
|
|
errors: [{ message }],
|
|
|
|
output: 'require("common")\n' +
|
|
|
|
'if (!common.hasCrypto) {' +
|
|
|
|
' common.skip("missing crypto");' +
|
|
|
|
'}\n' +
|
|
|
|
'require("crypto")'
|
2017-10-11 05:42:47 +00:00
|
|
|
},
|
|
|
|
{
|
2017-10-31 19:38:45 +00:00
|
|
|
code: 'require("common")\n' +
|
|
|
|
'if (common.foo) {}\n' +
|
|
|
|
'require("crypto")',
|
|
|
|
errors: [{ message }],
|
|
|
|
output: 'require("common")\n' +
|
|
|
|
'if (!common.hasCrypto) {' +
|
|
|
|
' common.skip("missing crypto");' +
|
|
|
|
'}\n' +
|
|
|
|
'if (common.foo) {}\n' +
|
|
|
|
'require("crypto")'
|
2019-01-08 15:36:28 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
code: 'require("common")\n' +
|
|
|
|
'if (common.foo) {}\n' +
|
|
|
|
'internalBinding("crypto")',
|
|
|
|
errors: [{ message }],
|
|
|
|
output: 'require("common")\n' +
|
|
|
|
'if (!common.hasCrypto) {' +
|
|
|
|
' common.skip("missing crypto");' +
|
|
|
|
'}\n' +
|
|
|
|
'if (common.foo) {}\n' +
|
|
|
|
'internalBinding("crypto")'
|
2021-03-26 15:51:08 +00:00
|
|
|
},
|
2017-10-11 05:42:47 +00:00
|
|
|
]
|
|
|
|
});
|