1'use strict';
2
3const common = require('../common');
4if ((!common.hasCrypto) || (!common.hasIntl)) {
5  common.skip('ESLint tests require crypto and Intl');
6}
7
8common.skipIfEslintMissing();
9
10const RuleTester = require('../../tools/node_modules/eslint').RuleTester;
11const rule = require('../../tools/eslint-rules/crypto-check');
12
13const message = 'Please add a hasCrypto check to allow this test to be ' +
14                'skipped when Node is built "--without-ssl".';
15
16new RuleTester().run('crypto-check', rule, {
17  valid: [
18    'foo',
19    'crypto',
20    `
21    if (!common.hasCrypto) {
22      common.skip("missing crypto");
23    }
24    require("crypto");
25    `,
26    `
27    if (!common.hasCrypto) {
28      common.skip("missing crypto");
29    }
30    internalBinding("crypto");
31    `,
32  ],
33  invalid: [
34    {
35      code: 'require("common")\n' +
36            'require("crypto")\n' +
37            'if (!common.hasCrypto) {\n' +
38            '  common.skip("missing crypto");\n' +
39            '}',
40      errors: [{ message }]
41    },
42    {
43      code: 'require("common")\n' +
44            'require("crypto")',
45      errors: [{ message }],
46      output: 'require("common")\n' +
47              'if (!common.hasCrypto) {' +
48              ' common.skip("missing crypto");' +
49              '}\n' +
50              'require("crypto")'
51    },
52    {
53      code: 'require("common")\n' +
54            'if (common.foo) {}\n' +
55            'require("crypto")',
56      errors: [{ message }],
57      output: 'require("common")\n' +
58              'if (!common.hasCrypto) {' +
59              ' common.skip("missing crypto");' +
60              '}\n' +
61              'if (common.foo) {}\n' +
62              'require("crypto")'
63    },
64    {
65      code: 'require("common")\n' +
66            'if (common.foo) {}\n' +
67            'internalBinding("crypto")',
68      errors: [{ message }],
69      output: 'require("common")\n' +
70              'if (!common.hasCrypto) {' +
71              ' common.skip("missing crypto");' +
72              '}\n' +
73              'if (common.foo) {}\n' +
74              'internalBinding("crypto")'
75    },
76  ]
77});
78