|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +// ------------------------------------------------------------------------------ |
| 4 | +// Requirements |
| 5 | +// ------------------------------------------------------------------------------ |
| 6 | + |
| 7 | +var rule = require('../rules/module-configuration-file'); |
| 8 | +var RuleTester = require('eslint').RuleTester; |
| 9 | +var commonFalsePositives = require('./utils/commonFalsePositives'); |
| 10 | + |
| 11 | +// ------------------------------------------------------------------------------ |
| 12 | +// Tests |
| 13 | +// ------------------------------------------------------------------------------ |
| 14 | + |
| 15 | +var eslintTester = new RuleTester(); |
| 16 | +eslintTester.run('module-configuration-file', rule, { |
| 17 | + valid: [ |
| 18 | + { |
| 19 | + // config in a .config.js file |
| 20 | + filename: 'app.config.js', |
| 21 | + code: 'angular.module("app").config(function() {});' |
| 22 | + }, |
| 23 | + { |
| 24 | + // config in a .config.js file with module getter |
| 25 | + filename: 'admin.config.js', |
| 26 | + code: 'angular.module("admin").config(function($httpProvider) { $httpProvider.interceptors.push("authInterceptor"); });' |
| 27 | + }, |
| 28 | + { |
| 29 | + // simple config.js filename |
| 30 | + filename: 'config.js', |
| 31 | + code: 'angular.module("app").config(function() {});' |
| 32 | + }, |
| 33 | + { |
| 34 | + // config in a subdirectory |
| 35 | + filename: 'src/app/modules/admin.config.js', |
| 36 | + code: 'angular.module("admin").config(function() {});' |
| 37 | + }, |
| 38 | + { |
| 39 | + // module declaration without config |
| 40 | + filename: 'app.module.js', |
| 41 | + code: 'angular.module("app", []);' |
| 42 | + }, |
| 43 | + { |
| 44 | + // controller in non-config file |
| 45 | + filename: 'home.controller.js', |
| 46 | + code: 'angular.module("app").controller("HomeController", function() {});' |
| 47 | + }, |
| 48 | + { |
| 49 | + // service in non-config file |
| 50 | + filename: 'user.service.js', |
| 51 | + code: 'angular.module("app").factory("userService", function() {});' |
| 52 | + }, |
| 53 | + { |
| 54 | + // test file should be ignored |
| 55 | + filename: 'app.spec.js', |
| 56 | + code: 'angular.module("app").config(function() {});' |
| 57 | + }, |
| 58 | + { |
| 59 | + // test file should be ignored |
| 60 | + filename: 'app.test.js', |
| 61 | + code: 'angular.module("app").config(function() {});' |
| 62 | + } |
| 63 | + ].concat(commonFalsePositives), |
| 64 | + invalid: [ |
| 65 | + { |
| 66 | + filename: 'app.js', |
| 67 | + code: 'angular.module("app").config(function() {});', |
| 68 | + errors: [{ |
| 69 | + message: 'Module configuration should be in a separate file with a .config.js suffix' |
| 70 | + }] |
| 71 | + }, |
| 72 | + { |
| 73 | + filename: 'app.module.js', |
| 74 | + code: 'angular.module("app").config(function($httpProvider) { $httpProvider.interceptors.push("authInterceptor"); });', |
| 75 | + errors: [{ |
| 76 | + message: 'Module configuration should be in a separate file with a .config.js suffix' |
| 77 | + }] |
| 78 | + }, |
| 79 | + { |
| 80 | + filename: 'admin.js', |
| 81 | + code: 'angular.module("admin").config(function() {});', |
| 82 | + errors: [{ |
| 83 | + message: 'Module configuration should be in a separate file with a .config.js suffix' |
| 84 | + }] |
| 85 | + }, |
| 86 | + { |
| 87 | + filename: 'src/app/admin.module.js', |
| 88 | + code: 'angular.module("admin").config(configFunction);', |
| 89 | + errors: [{ |
| 90 | + message: 'Module configuration should be in a separate file with a .config.js suffix' |
| 91 | + }] |
| 92 | + } |
| 93 | + ] |
| 94 | +}); |
0 commit comments