node/test/parallel/test-eslint-prefer-util-format-errors.js
Rich Trott e60801aaac
test: skip ESLint tests if no Intl
ESLint dependency now requires Intl because it uses regexp unicode
character properties.

Fixes: https://github.com/nodejs/node/issues/41102

PR-URL: https://github.com/nodejs/node/pull/41105
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Derek Lewis <DerekNonGeneric@inf.is>
Reviewed-By: Richard Lau <rlau@redhat.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
2021-12-07 10:01:36 +00:00

33 lines
964 B
JavaScript

'use strict';
/* eslint-disable no-template-curly-in-string */
const common = require('../common');
if ((!common.hasCrypto) || (!common.hasIntl)) {
common.skip('ESLint tests require crypto and Intl');
}
common.skipIfEslintMissing();
const RuleTester = require('../../tools/node_modules/eslint').RuleTester;
const rule = require('../../tools/eslint-rules/prefer-util-format-errors');
new RuleTester({ parserOptions: { ecmaVersion: 6 } })
.run('prefer-util-format-errors', rule, {
valid: [
'E(\'ABC\', \'abc\');',
'E(\'ABC\', (arg1, arg2) => `${arg2}${arg1}`);',
'E(\'ABC\', (arg1, arg2) => `${arg1}{arg2.something}`);',
'E(\'ABC\', (arg1, arg2) => fn(arg1, arg2));',
],
invalid: [
{
code: 'E(\'ABC\', (arg1, arg2) => `${arg1}${arg2}`);',
errors: [{
message: 'Please use a printf-like formatted string that ' +
'util.format can consume.'
}]
},
]
});