|
| 1 | +//------------------------------------------------------------------------------ |
| 2 | +// Requirements |
| 3 | +//------------------------------------------------------------------------------ |
| 4 | + |
| 5 | +var rule = require('../rules/ng_file_name'), |
| 6 | + RuleTester = require("eslint").RuleTester; |
| 7 | + |
| 8 | +//------------------------------------------------------------------------------ |
| 9 | +// Tests |
| 10 | +//------------------------------------------------------------------------------ |
| 11 | + |
| 12 | +var eslintTester = new RuleTester(); |
| 13 | +eslintTester.run('ng_file_name', rule, { |
| 14 | + valid: [{ |
| 15 | + // basic module |
| 16 | + filename: 'myModule.js', |
| 17 | + code: 'angular.module("myModule", []);' |
| 18 | + }, { |
| 19 | + // basic filter |
| 20 | + filename: 'someFilter.js', |
| 21 | + code: 'app.filter("someFilter", function(){});' |
| 22 | + }, { |
| 23 | + // basic controller |
| 24 | + filename: 'SomeController.js', |
| 25 | + code: 'app.controller("SomeController", function(){});' |
| 26 | + }, { |
| 27 | + // basic service |
| 28 | + filename: 'myUtils.js', |
| 29 | + code: 'app.service("myUtils", function(){});' |
| 30 | + }, { |
| 31 | + // basic factory service |
| 32 | + filename: 'myUtils.js', |
| 33 | + code: 'app.factory("myUtils", function(){});' |
| 34 | + }, { |
| 35 | + // basic directive |
| 36 | + filename: 'beautifulDirective.js', |
| 37 | + code: 'app.directive("beautifulDirective", function(){});' |
| 38 | + }, { |
| 39 | + // typeSeparator dot with filter |
| 40 | + filename: 'src/app/myFilter.filter.js', |
| 41 | + code: 'app.filter("myFilter", function(){});', |
| 42 | + options: [{ |
| 43 | + typeSeparator: 'dot' |
| 44 | + }] |
| 45 | + }, { |
| 46 | + // ignore $provide declarations |
| 47 | + filename: 'src/app/myApp.module.js', |
| 48 | + code: '$provide.value("accountsService", accountsService);' |
| 49 | + }, { |
| 50 | + // ignore test declarations |
| 51 | + filename: 'src/app/fooBar.spec.js', |
| 52 | + code: 'it("myApp", function(){})' |
| 53 | + }, { |
| 54 | + // ignore test declarations |
| 55 | + filename: 'src/app/myService.spec.js', |
| 56 | + code: '$httpBackend.expectGET("/api/my/service").respond(200, dummyVorversicherer)' |
| 57 | + }, { |
| 58 | + // typeSeparator dash with service (factory) |
| 59 | + filename: 'src/app/someUtil-service.js', |
| 60 | + code: 'app.factory("someUtil", function(){});', |
| 61 | + options: [{ |
| 62 | + typeSeparator: 'dash' |
| 63 | + }] |
| 64 | + }, { |
| 65 | + // typeSeparator underscore with controller |
| 66 | + filename: 'src/app/SomeController_controller.js', |
| 67 | + code: 'app.controller("SomeController", function(){});', |
| 68 | + options: [{ |
| 69 | + typeSeparator: 'underscore' |
| 70 | + }] |
| 71 | + }, { |
| 72 | + // typeSeparator dot with controller and ignored type suffix |
| 73 | + filename: 'src/app/Avengers.controller.js', |
| 74 | + code: 'app.controller("AvengersController", function(){});', |
| 75 | + options: [{ |
| 76 | + typeSeparator: 'dot', |
| 77 | + ignoreTypeSuffix: true |
| 78 | + }] |
| 79 | + }, { |
| 80 | + // typeSeparator dot with controller and ignored type suffix |
| 81 | + filename: 'src/app/Avengers.controller.js', |
| 82 | + code: 'app.controller("AvengersController", function(){});', |
| 83 | + options: [{ |
| 84 | + typeSeparator: 'dot', |
| 85 | + ignoreTypeSuffix: true |
| 86 | + }] |
| 87 | + }, { |
| 88 | + // typeSeparator dot with service and ignored type suffix |
| 89 | + filename: 'src/app/avengers.service.js', |
| 90 | + code: 'app.factory("avengersService", function(){});', |
| 91 | + options: [{ |
| 92 | + typeSeparator: 'dot', |
| 93 | + ignoreTypeSuffix: true |
| 94 | + }] |
| 95 | + }, { |
| 96 | + // typeSeparator dot with service and ignored type suffix |
| 97 | + filename: 'src/app/avengersApi.service.js', |
| 98 | + code: 'app.factory("avengersApi", function(){});', |
| 99 | + options: [{ |
| 100 | + typeSeparator: 'dot', |
| 101 | + ignoreTypeSuffix: true |
| 102 | + }] |
| 103 | + }, { |
| 104 | + // typeSeparator dot with service and ignored type suffix (optimization: name shorter than type name) |
| 105 | + filename: 'src/app/utils.service.js', |
| 106 | + code: 'app.factory("utils", function(){});', |
| 107 | + options: [{ |
| 108 | + typeSeparator: 'dot', |
| 109 | + ignoreTypeSuffix: true |
| 110 | + }] |
| 111 | + }, { |
| 112 | + // nameStyle dash and typeSeparator dash with service |
| 113 | + filename: 'src/app/app-utils-service.js', |
| 114 | + code: 'app.factory("appUtils", function(){});', |
| 115 | + options: [{ |
| 116 | + typeSeparator: 'dash', |
| 117 | + nameStyle: 'dash' |
| 118 | + }] |
| 119 | + }, { |
| 120 | + // nameStyle underscore and typeSeparator dot with directive |
| 121 | + filename: 'src/app/my_tab.directive.js', |
| 122 | + code: 'app.directive("myTab", function(){});', |
| 123 | + options: [{ |
| 124 | + typeSeparator: 'dot', |
| 125 | + nameStyle: 'underscore' |
| 126 | + }] |
| 127 | + }], |
| 128 | + invalid: [{ |
| 129 | + filename: 'src/app/filters.js', |
| 130 | + code: 'app.filter("myFilter", function(){});', |
| 131 | + errors: [{ message: 'Filename must be "myFilter.js"'}] |
| 132 | + },{ |
| 133 | + filename: 'src/app/myFilter.js', |
| 134 | + code: 'app.filter("myFilter", function(){});', |
| 135 | + options: [{ |
| 136 | + typeSeparator: 'dot' |
| 137 | + }], |
| 138 | + errors: [{ message: 'Filename must be "myFilter.filter.js"'}] |
| 139 | + },{ |
| 140 | + // typeSeparator underscore with service |
| 141 | + filename: 'src/someService_controller.js', |
| 142 | + code: 'app.factory("someService", function(){});', |
| 143 | + options: [{ |
| 144 | + typeSeparator: 'underscore' |
| 145 | + }], |
| 146 | + errors: [{ message: 'Filename must be "someService_service.js"'}] |
| 147 | + }, { |
| 148 | + // typeSeparator dot with controller, but no ignored type suffix |
| 149 | + filename: 'src/app/Avengers.controller.js', |
| 150 | + code: 'app.controller("AvengersController", function(){});', |
| 151 | + options: [{ |
| 152 | + typeSeparator: 'dot' |
| 153 | + }], |
| 154 | + errors: [{ message: 'Filename must be "AvengersController.controller.js"'}] |
| 155 | + }, { |
| 156 | + // typeSeparator dot with controller and ignored type suffix |
| 157 | + filename: 'src/app/AvengersController.controller.js', |
| 158 | + code: 'app.controller("AvengersController", function(){});', |
| 159 | + options: [{ |
| 160 | + typeSeparator: 'dot', |
| 161 | + ignoreTypeSuffix: true |
| 162 | + }], |
| 163 | + errors: [{ message: 'Filename must be "Avengers.controller.js"'}] |
| 164 | + }, { |
| 165 | + // nameStyle dash and typeSeparator dot with directive |
| 166 | + filename: 'src/app/avangerProfile.directive.js', |
| 167 | + code: 'app.directive("avangerProfile", function(){});', |
| 168 | + options: [{ |
| 169 | + typeSeparator: 'dot', |
| 170 | + nameStyle: 'dash' |
| 171 | + }], |
| 172 | + errors: [{ message: 'Filename must be "avanger-profile.directive.js"'}] |
| 173 | + }] |
| 174 | +}); |
0 commit comments