1. Fixer for crypto-check.js 2. Extends tests PR-URL: https://github.com/nodejs/node/pull/16647 Refs: https://github.com/nodejs/node/issues/16636 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Khaidi Chu <i@2333.moe> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
48 lines
1.2 KiB
JavaScript
48 lines
1.2 KiB
JavaScript
'use strict';
|
|
|
|
const common = require('../common');
|
|
|
|
common.skipIfEslintMissing();
|
|
|
|
const RuleTester = require('../../tools/node_modules/eslint').RuleTester;
|
|
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',
|
|
`
|
|
if (!common.hasCrypto) {
|
|
common.skip("missing crypto");
|
|
}
|
|
require("crypto");
|
|
`
|
|
],
|
|
invalid: [
|
|
{
|
|
code: 'require("common")\n' +
|
|
'require("crypto")',
|
|
errors: [{ message }],
|
|
output: 'require("common")\n' +
|
|
'if (!common.hasCrypto) {' +
|
|
' common.skip("missing crypto");' +
|
|
'}\n' +
|
|
'require("crypto")'
|
|
},
|
|
{
|
|
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")'
|
|
}
|
|
]
|
|
});
|