1'use strict'; 2 3const common = require('../common'); 4if ((!common.hasCrypto) || (!common.hasIntl)) { 5 common.skip('ESLint tests require crypto and Intl'); 6} 7 8common.skipIfEslintMissing(); 9 10const RuleTester = require('../../tools/node_modules/eslint').RuleTester; 11const rule = require('../../tools/eslint-rules/required-modules'); 12 13new RuleTester().run('required-modules', rule, { 14 valid: [ 15 { 16 code: 'require("common")', 17 options: [{ common: 'common' }] 18 }, 19 { 20 code: 'foo', 21 options: [] 22 }, 23 { 24 code: 'require("common")', 25 options: [{ common: 'common(/index\\.(m)?js)?$' }] 26 }, 27 { 28 code: 'require("common/index.js")', 29 options: [{ common: 'common(/index\\.(m)?js)?$' }] 30 }, 31 ], 32 invalid: [ 33 { 34 code: 'foo', 35 options: [{ common: 'common' }], 36 errors: [{ message: 'Mandatory module "common" must be loaded.' }] 37 }, 38 { 39 code: 'require("common/fixtures.js")', 40 options: [{ common: 'common(/index\\.(m)?js)?$' }], 41 errors: [{ 42 message: 43 'Mandatory module "common" must be loaded.' 44 }] 45 }, 46 { 47 code: 'require("somethingElse")', 48 options: [{ common: 'common' }], 49 errors: [{ message: 'Mandatory module "common" must be loaded.' }] 50 }, 51 ] 52}); 53