node/test/parallel/test-eslint-lowercase-name-for-primitive.js
Myles Borins 1fd69872e6 test: add common.skipIfEslintMissing
We've added a number of tests that hook into ESLint which can error
when running the test suite with the distributed tarball. This PR
adds a new test helper `common.skipIfEslintMissing` and will skip
remaining tests in a file when `ESLint` is not available at
`tools/node_modules/eslint`

PR-URL: https://github.com/nodejs/node/pull/18807
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
2018-02-16 15:54:56 -08:00

52 lines
1.5 KiB
JavaScript

'use strict';
const common = require('../common');
common.skipIfEslintMissing();
const RuleTester = require('../../tools/node_modules/eslint').RuleTester;
const rule = require('../../tools/eslint-rules/lowercase-name-for-primitive');
const valid = [
'string',
'number',
'boolean',
'null',
'undefined'
];
new RuleTester().run('lowercase-name-for-primitive', rule, {
valid: [
'new errors.TypeError("ERR_INVALID_ARG_TYPE", "a", ["string", "number"])',
...valid.map((name) =>
`new errors.TypeError("ERR_INVALID_ARG_TYPE", "name", "${name}")`
)
],
invalid: [
{
code: 'new errors.TypeError(\'ERR_INVALID_ARG_TYPE\', \'a\', ' +
'\'Number\')',
errors: [{ message: 'primitive should use lowercase: Number' }],
output: 'new errors.TypeError(\'ERR_INVALID_ARG_TYPE\', \'a\', ' +
'\'number\')'
},
{
code: 'new errors.TypeError(\'ERR_INVALID_ARG_TYPE\', \'a\', ' +
'\'STRING\')',
errors: [{ message: 'primitive should use lowercase: STRING' }],
output: 'new errors.TypeError(\'ERR_INVALID_ARG_TYPE\', \'a\', ' +
'\'string\')'
},
{
code: 'new errors.TypeError(\'ERR_INVALID_ARG_TYPE\', \'a\', ' +
'[\'String\', \'Number\']) ',
errors: [
{ message: 'primitive should use lowercase: String' },
{ message: 'primitive should use lowercase: Number' }
],
output: 'new errors.TypeError(\'ERR_INVALID_ARG_TYPE\', \'a\', ' +
'[\'string\', \'number\']) '
}
]
});