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