• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/prefer-common-mustsucceed');
12
13const msg1 = 'Please use common.mustSucceed instead of ' +
14             'common.mustCall(assert.ifError).';
15const msg2 = 'Please use common.mustSucceed instead of ' +
16             'common.mustCall with assert.ifError.';
17
18new RuleTester({
19  parserOptions: { ecmaVersion: 2015 }
20}).run('prefer-common-mustsucceed', rule, {
21  valid: [
22    'foo((err) => assert.ifError(err))',
23    'foo(function(err) { assert.ifError(err) })',
24    'foo(assert.ifError)',
25    'common.mustCall((err) => err)',
26  ],
27  invalid: [
28    {
29      code: 'common.mustCall(assert.ifError)',
30      errors: [{ message: msg1 }]
31    },
32    {
33      code: 'common.mustCall((err) => assert.ifError(err))',
34      errors: [{ message: msg2 }]
35    },
36    {
37      code: 'common.mustCall((e) => assert.ifError(e))',
38      errors: [{ message: msg2 }]
39    },
40    {
41      code: 'common.mustCall(function(e) { assert.ifError(e); })',
42      errors: [{ message: msg2 }]
43    },
44    {
45      code: 'common.mustCall(function(e) { return assert.ifError(e); })',
46      errors: [{ message: msg2 }]
47    },
48    {
49      code: 'common.mustCall(function(e) {{ assert.ifError(e); }})',
50      errors: [{ message: msg2 }]
51    },
52  ]
53});
54