0
0
mirror of https://github.com/nodejs/node.git synced 2024-12-01 16:10:02 +01:00
nodejs/test/parallel/test-eslint-required-modules.js
Richard Lau 1df3080af3 tools: allow RegExp in required-modules eslint rule
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>
2019-05-13 16:07:34 -04:00

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.' }]
}
]
});