mirror of
https://github.com/nodejs/node.git
synced 2025-05-10 20:34:33 +00:00

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>
34 lines
908 B
JavaScript
34 lines
908 B
JavaScript
'use strict';
|
|
|
|
const common = require('../common');
|
|
|
|
common.skipIfEslintMissing();
|
|
|
|
const RuleTester = require('../../tools/node_modules/eslint').RuleTester;
|
|
const rule = require('../../tools/eslint-rules/prefer-assert-iferror');
|
|
|
|
new RuleTester().run('prefer-assert-iferror', rule, {
|
|
valid: [
|
|
'assert.ifError(err);',
|
|
'if (err) throw somethingElse;',
|
|
'throw err;',
|
|
'if (err) { throw somethingElse; }'
|
|
],
|
|
invalid: [
|
|
{
|
|
code: 'require("assert");\n' +
|
|
'if (err) throw err;',
|
|
errors: [{ message: 'Use assert.ifError(err) instead.' }],
|
|
output: 'require("assert");\n' +
|
|
'assert.ifError(err);'
|
|
},
|
|
{
|
|
code: 'require("assert");\n' +
|
|
'if (error) { throw error; }',
|
|
errors: [{ message: 'Use assert.ifError(error) instead.' }],
|
|
output: 'require("assert");\n' +
|
|
'assert.ifError(error);'
|
|
}
|
|
]
|
|
});
|