mirror of
https://github.com/nodejs/node.git
synced 2024-12-01 16:10:02 +01:00
1df3080af3
PR-URL: https://github.com/nodejs/node/pull/27647 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
52 lines
1.2 KiB
JavaScript
52 lines
1.2 KiB
JavaScript
'use strict';
|
|
|
|
const common = require('../common');
|
|
if (!common.hasCrypto)
|
|
common.skip('missing crypto');
|
|
|
|
common.skipIfEslintMissing();
|
|
|
|
const RuleTester = require('../../tools/node_modules/eslint').RuleTester;
|
|
const rule = require('../../tools/eslint-rules/required-modules');
|
|
|
|
new RuleTester().run('required-modules', rule, {
|
|
valid: [
|
|
{
|
|
code: 'require("common")',
|
|
options: [{ common: 'common' }]
|
|
},
|
|
{
|
|
code: 'foo',
|
|
options: []
|
|
},
|
|
{
|
|
code: 'require("common")',
|
|
options: [{ common: 'common(/index\\.(m)?js)?$' }]
|
|
},
|
|
{
|
|
code: 'require("common/index.js")',
|
|
options: [{ common: 'common(/index\\.(m)?js)?$' }]
|
|
},
|
|
],
|
|
invalid: [
|
|
{
|
|
code: 'foo',
|
|
options: [{ common: 'common' }],
|
|
errors: [{ message: 'Mandatory module "common" must be loaded.' }]
|
|
},
|
|
{
|
|
code: 'require("common/fixtures.js")',
|
|
options: [{ common: 'common(/index\\.(m)?js)?$' }],
|
|
errors: [{
|
|
message:
|
|
'Mandatory module "common" must be loaded.'
|
|
}]
|
|
},
|
|
{
|
|
code: 'require("somethingElse")',
|
|
options: [{ common: 'common' }],
|
|
errors: [{ message: 'Mandatory module "common" must be loaded.' }]
|
|
}
|
|
]
|
|
});
|