mirror of
https://github.com/zebrajr/node.git
synced 2025-12-07 00:20:38 +01: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>
50 lines
1.3 KiB
JavaScript
50 lines
1.3 KiB
JavaScript
'use strict';
|
|
|
|
const common = require('../common');
|
|
|
|
common.skipIfEslintMissing();
|
|
|
|
const RuleTester = require('../../tools/eslint').RuleTester;
|
|
const rule = require('../../tools/eslint-rules/require-buffer');
|
|
const ruleTester = new RuleTester({
|
|
parserOptions: { ecmaVersion: 6 },
|
|
env: { node: true }
|
|
});
|
|
|
|
const message = "Use const Buffer = require('buffer').Buffer; " +
|
|
'at the beginning of this file';
|
|
|
|
const useStrict = '\'use strict\';\n\n';
|
|
const bufferModule = 'const { Buffer } = require(\'buffer\');\n';
|
|
const mockComment = '// Some Comment\n//\n// Another Comment\n\n';
|
|
const useBuffer = 'Buffer;';
|
|
ruleTester.run('require-buffer', rule, {
|
|
valid: [
|
|
'foo',
|
|
'const Buffer = require("Buffer"); Buffer;',
|
|
'const { Buffer } = require(\'buffer\'); Buffer;',
|
|
],
|
|
invalid: [
|
|
{
|
|
code: useBuffer,
|
|
errors: [{ message }],
|
|
output: bufferModule + useBuffer,
|
|
},
|
|
{
|
|
code: useStrict + useBuffer,
|
|
errors: [{ message }],
|
|
output: useStrict + bufferModule + useBuffer,
|
|
},
|
|
{
|
|
code: mockComment + useBuffer,
|
|
errors: [{ message }],
|
|
output: mockComment + bufferModule + useBuffer,
|
|
},
|
|
{
|
|
code: mockComment + useStrict + useBuffer,
|
|
errors: [{ message }],
|
|
output: mockComment + useStrict + bufferModule + useBuffer,
|
|
},
|
|
]
|
|
});
|