From c6eb22abb6a38f2b36d8a796abe088075cfdd60a Mon Sep 17 00:00:00 2001 From: SomeKittens Date: Sat, 9 May 2015 20:01:58 -0700 Subject: [PATCH] refactor(log): Remove log option Now that we've switched to an event emitter, log was no longer used and was causing confusion. The major change here is that once we emit an event, it is not stored. If this turns out to be a big deal, we can implement a message storage module. Closes #81 tweaked test --- CONTRIBUTING.md | 7 +- README.md | 3 - hint.js | 9 +-- src/modules/angular-hint-modules/display.js | 5 +- .../angular-hint-modules/getNgAppMod.js | 5 +- .../angular-hint-modules/hasNameSpace.js | 5 +- src/modules/controllers.js | 4 +- src/modules/events.js | 2 +- src/modules/hint-log.js | 48 ----------- src/modules/log.js | 53 ------------ test/controllers.spec.js | 51 ++++-------- test/events.spec.js | 18 ++--- test/getNgAppMod.spec.js | 6 +- test/hasNameSpace.spec.js | 4 - test/log.spec.js | 80 ------------------- test/modules.spec.js | 42 +++++----- 16 files changed, 63 insertions(+), 279 deletions(-) delete mode 100644 src/modules/hint-log.js delete mode 100644 src/modules/log.js delete mode 100644 test/log.spec.js diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 66770888..4d4b69b0 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -225,12 +225,11 @@ The following steps describe how an AngularHint module should be developed. - Each AngularHint module should load its own dependencies using `browserify`. For instance, AngularHintDOM depends on the library `domInterceptor`. This dependency is included within AngularHintDom by the browserify `require` function. - All AngularHint modules should load AngularHintLog as a dependency, see #3. -3. Message Logging +3. Events -All AngularHint modules should use AngularHintLog to log their messages. This creates a standard pipeline for -all AngularHint messages. +All AngularHint modules should use `hint.emit` to emit their events. This creates a standard pipeline for all AngularHint events. -To use AngularHintLog, see its [README.md](https://github.com/angular/angular-hint-log#angular-hint-log). +`angular.hint` is an instance of [EventEmitter2](https://github.com/asyncly/EventEmitter2). 4. Module Testing diff --git a/README.md b/README.md index 02aeadd7..407d9f25 100644 --- a/README.md +++ b/README.md @@ -74,9 +74,6 @@ AngularHint is composed of several small modules that you may want to use indivi * [AngularHintInterpolation](https://github.com/angular/angular-hint-interpolation) * [AngularHintModules](https://github.com/angular/angular-hint-modules) -AngularHint uses [AngularHintLog](https://github.com/angular/angular-hint-log) to provide -logging functionality. - ## Interested in Contributing? See the [Contributing Guidelines](https://github.com/angular/angular-hint/blob/master/CONTRIBUTING.md) diff --git a/hint.js b/hint.js index 846a2a5b..e66cf2f6 100644 --- a/hint.js +++ b/hint.js @@ -1,10 +1,7 @@ 'use strict'; -// Set up the event stuffs -require('./src/modules/hintEmitter'); - // Create pipe for all hint messages from different modules -require('./src/modules/log'); +require('./src/modules/hintEmitter'); // Load angular hint modules require('./src/modules/controllers'); @@ -76,7 +73,7 @@ function loadModules() { } else if (document.querySelector('[ng-hint]')) { modules = AVAILABLE_MODULES; } else { - angular.hint.log('General', 'ngHint is included on the page, but is not active because ' + + angular.hint.emit('general:noinclude', 'ngHint is included on the page, but is not active because ' + 'there is no `ng-hint` attribute present', SEVERITY_WARNING); } return modules; @@ -94,7 +91,7 @@ function hintModulesFromElement (elt) { return selectedModules.map(hintModuleName).filter(function (name) { return (AVAILABLE_MODULES.indexOf(name) > -1) || - angular.hint.log('General', 'Module ' + name + ' could not be found', SEVERITY_WARNING); + angular.hint.emit('general:404module', 'Module ' + name + ' could not be found', SEVERITY_WARNING); }); } diff --git a/src/modules/angular-hint-modules/display.js b/src/modules/angular-hint-modules/display.js index 1309fa82..715968c7 100644 --- a/src/modules/angular-hint-modules/display.js +++ b/src/modules/angular-hint-modules/display.js @@ -1,8 +1,7 @@ -var hintLog = angular.hint = require('./../log'), - MODULE_NAME = 'Modules'; +var MODULE_NAME = 'Modules'; module.exports = function(modules) { modules.forEach(function(module) { - hintLog.log(MODULE_NAME, module.message, module.severity); + angular.hint.emit(MODULE_NAME, module.message, module.severity); }); }; diff --git a/src/modules/angular-hint-modules/getNgAppMod.js b/src/modules/angular-hint-modules/getNgAppMod.js index 763a72f7..fbd76531 100644 --- a/src/modules/angular-hint-modules/getNgAppMod.js +++ b/src/modules/angular-hint-modules/getNgAppMod.js @@ -1,9 +1,8 @@ -var hintLog = angular.hint = require('./../log'), - MODULE_NAME = 'Modules', +var MODULE_NAME = 'Modules', SEVERITY_ERROR = 1; module.exports = function(attrs, ngAppFound) { if(attrs['ng-app'] && ngAppFound) { - hintLog.log(MODULE_NAME, 'ng-app may only be included once. The module "' + + angular.hint.emit(MODULE_NAME, 'ng-app may only be included once. The module "' + attrs['ng-app'].value + '" was not used to bootstrap because ng-app was already included.', SEVERITY_ERROR); } diff --git a/src/modules/angular-hint-modules/hasNameSpace.js b/src/modules/angular-hint-modules/hasNameSpace.js index ac62d492..b341b7c5 100644 --- a/src/modules/angular-hint-modules/hasNameSpace.js +++ b/src/modules/angular-hint-modules/hasNameSpace.js @@ -1,5 +1,4 @@ -var hintLog = angular.hint = require('./../log'), - MODULE_NAME = 'Modules', +var MODULE_NAME = 'Modules', SEVERITY_SUGGESTION = 3; module.exports = function(str) { @@ -8,7 +7,7 @@ module.exports = function(str) { } if(str.toLowerCase() === str || str.charAt(0).toUpperCase() === str.charAt(0)) { - hintLog.log(MODULE_NAME, 'The best practice for' + + angular.hint.emit(MODULE_NAME, 'The best practice for' + ' module names is to use lowerCamelCase. Check the name of "' + str + '".', SEVERITY_SUGGESTION); return false; diff --git a/src/modules/controllers.js b/src/modules/controllers.js index fc0f56a8..751e36a1 100644 --- a/src/modules/controllers.js +++ b/src/modules/controllers.js @@ -47,7 +47,7 @@ function processController(ctrlName) { } function sendMessageForGlobalController(name) { - angular.hint.log(MODULE_NAME, + angular.hint.emit(MODULE_NAME + ':global', 'add `' + name + '` to a module', angular.version.minor <= 2 ? SEVERITY_WARNING : SEVERITY_ERROR, CATEGORY_GLOBAL_CONTROLLER); @@ -62,7 +62,7 @@ function sendMessageForControllerName(name) { newName = addControllerSuffix(newName); } if (name !== newName) { - angular.hint.log(MODULE_NAME, + angular.hint.emit(MODULE_NAME + ':rename', 'Consider renaming `' + name + '` to `' + newName + '`.', SEVERITY_WARNING, CATEGORY_CONTROLLER_NAME); diff --git a/src/modules/events.js b/src/modules/events.js index 1a8c614c..fd940daf 100644 --- a/src/modules/events.js +++ b/src/modules/events.js @@ -53,7 +53,7 @@ function ngEventDirectivesDecorator(ngEventAttrName) { property = property[0]; propChain = lastProp + property; if ($parse(propChain)(scope) === undefined) { - angular.hint.log(MODULE_NAME, propChain + ' is undefined'); + angular.hint.emit(MODULE_NAME + ':undef', propChain + ' is undefined'); } boundFn = boundFn.replace(property, ''); lastProp += property; diff --git a/src/modules/hint-log.js b/src/modules/hint-log.js deleted file mode 100644 index 86cb3cf4..00000000 --- a/src/modules/hint-log.js +++ /dev/null @@ -1,48 +0,0 @@ -'use strict'; - -/* - * HintLog creates a queue of messages logged by ngHint modules. This object - * has a key for each ngHint module that corresponds to the messages - * from that module. - */ -var queuedMessages = {}, - MESSAGE_TYPES = [ - 'error', - 'warning', - 'suggestion' - ]; - -/* - * Add a message to the HintLog message queue. Messages are organized into categories - * according to their module name and severity. - */ -function logMessage(moduleName, message, severity, category) { - // If no severity was provided, categorize the message as a `suggestion` - severity = severity || 3; - var messageType = MESSAGE_TYPES[severity - 1]; - - moduleName = moduleName || 'General'; - - // If the category does not exist, initialize a new object - queuedMessages[moduleName] = queuedMessages[moduleName] || {}; - queuedMessages[moduleName][messageType] = queuedMessages[moduleName][messageType] || []; - - if (queuedMessages[moduleName][messageType].indexOf(message) < 0) { - queuedMessages[moduleName][messageType].push(message); - } - - this.onMessage(moduleName, message, messageType, category); -} - -/* - * Return and empty the current queue of messages. - */ -function flush() { - var flushMessages = queuedMessages; - queuedMessages = {}; - return flushMessages; -} - -module.exports.onMessage = function(message) {}; -module.exports.logMessage = logMessage; -module.exports.flush = flush; diff --git a/src/modules/log.js b/src/modules/log.js deleted file mode 100644 index 43a8c454..00000000 --- a/src/modules/log.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -/* - * HintLog creates a queue of messages logged by ngHint modules. This object - * has a key for each ngHint module that corresponds to the messages - * from that module. - */ -var queuedMessages = {}; - -angular.hint = angular.hint || {}; - -var MESSAGE_TYPES = [ - 'error', - 'warning', - 'suggestion' -]; - -/* - * Add a message to the HintLog message queue. Messages are organized into categories - * according to their module name and severity. - */ -function logMessage(moduleName, message, severity, category) { - // If no severity was provided, categorize the message as a `suggestion` - severity = severity || 3; - var messageType = MESSAGE_TYPES[severity - 1]; - - moduleName = moduleName || 'General'; - - // If the category does not exist, initialize a new object - queuedMessages[moduleName] = queuedMessages[moduleName] || {}; - queuedMessages[moduleName][messageType] = queuedMessages[moduleName][messageType] || []; - - if (queuedMessages[moduleName][messageType].indexOf(message) < 0) { - queuedMessages[moduleName][messageType].push(message); - } - - this.onMessage(moduleName, message, messageType, category); -} - -/* - * Return and empty the current queue of messages. - */ -function flush() { - var flushMessages = queuedMessages; - queuedMessages = {}; - return flushMessages; -} - -angular.hint.onMessage = function(message) {}; -angular.hint.log = logMessage; -angular.hint.flush = flush; - -module.exports = angular.hint; \ No newline at end of file diff --git a/test/controllers.spec.js b/test/controllers.spec.js index aca7a7bd..ec5001d7 100644 --- a/test/controllers.spec.js +++ b/test/controllers.spec.js @@ -15,12 +15,11 @@ describe('controllerDecorator', function() { $controller = _$controller_; $rootScope = _$rootScope_; $compile = _$compile_; - spyOn(angular.hint, 'log').and.callThrough(); + spyOn(angular.hint, 'emit').and.callThrough(); })); afterEach(function () { - angular.hint.flush(); delete window.MockController; }); @@ -36,10 +35,10 @@ describe('controllerDecorator', function() { } catch (e) {}; if (angular.version.minor < 3) { - expect(angular.hint.log).toHaveBeenCalledWith('Controllers', 'add `MockController` to a module', SEVERITY_WARNING, + expect(angular.hint.emit).toHaveBeenCalledWith('Controllers:global', 'add `MockController` to a module', SEVERITY_WARNING, 'Using global functions as controllers is against Angular best practices and depricated in Angular 1.3 and up'); } else { - expect(angular.hint.log).toHaveBeenCalledWith('Controllers', 'add `MockController` to a module', SEVERITY_ERROR, + expect(angular.hint.emit).toHaveBeenCalledWith('Controllers:global', 'add `MockController` to a module', SEVERITY_ERROR, 'Using global functions as controllers is against Angular best practices and depricated in Angular 1.3 and up'); } }); @@ -82,7 +81,7 @@ describe('controllerDecorator', function() { ''); $compile(elm)(scope); $rootScope.$digest(); - expect(angular.hint.log).not.toHaveBeenCalled(); + expect(angular.hint.emit).not.toHaveBeenCalled(); }); @@ -149,7 +148,7 @@ describe('controllerDecorator', function() { ''); $compile(elm)(scope); $rootScope.$digest(); - expect(angular.hint.log).toHaveBeenCalledWith('Controllers', + expect(angular.hint.emit).toHaveBeenCalledWith('Controllers:rename', 'Consider renaming `globalFunction` to `GlobalFunctionController`.', SEVERITY_WARNING, 'Name controllers according to best practices'); @@ -170,7 +169,7 @@ describe('controllerDecorator', function() { $controllerProvider.register('SampleController', function() {}); $controller('SampleController'); - expect(angular.hint.log).not.toHaveBeenCalledWith('Controllers', 'It is against Angular' + + expect(angular.hint.emit).not.toHaveBeenCalledWith('Controllers', 'It is against Angular' + 'best practices to instantiate a controller on the window. This behavior is deprecated in' + ' Angular 1.3.0', (angular.version.minor < 3 ? SEVERITY_WARNING : SEVERITY_ERROR)); }); @@ -179,7 +178,7 @@ describe('controllerDecorator', function() { it('should warn if a controller name does not begin with an uppercase letter', function(){ $controllerProvider.register('sampleController', function() {}); $controller('sampleController'); - expect(angular.hint.log).toHaveBeenCalledWith('Controllers', + expect(angular.hint.emit).toHaveBeenCalledWith('Controllers:rename', 'Consider renaming `sampleController` to `SampleController`.', SEVERITY_WARNING, 'Name controllers according to best practices'); @@ -189,14 +188,14 @@ describe('controllerDecorator', function() { it('should not warn if a controller name begins with an uppercase letter', function(){ $controllerProvider.register('SampleController', function() {}); $controller('SampleController'); - expect(angular.hint.log).not.toHaveBeenCalled(); + expect(angular.hint.emit).not.toHaveBeenCalled(); }); it('should warn if a controller name does not include Controller', function(){ $controllerProvider.register('Sample', function() {}); $controller('Sample'); - expect(angular.hint.log).toHaveBeenCalledWith('Controllers', + expect(angular.hint.emit).toHaveBeenCalledWith('Controllers:rename', 'Consider renaming `Sample` to `SampleController`.', SEVERITY_WARNING, 'Name controllers according to best practices'); @@ -206,7 +205,7 @@ describe('controllerDecorator', function() { it('should warn if a controller name does not end with Controller', function(){ $controllerProvider.register('SampleControllerYay', function() {}); $controller('SampleControllerYay'); - expect(angular.hint.log).toHaveBeenCalledWith('Controllers', + expect(angular.hint.emit).toHaveBeenCalledWith('Controllers:rename', 'Consider renaming `SampleControllerYay` to `SampleControllerYayController`.', SEVERITY_WARNING, 'Name controllers according to best practices'); @@ -216,19 +215,7 @@ describe('controllerDecorator', function() { it('should not warn if a controller ends with Controller', function(){ $controllerProvider.register('SampleController', function() {}); $controller('SampleController'); - expect(angular.hint.log).not.toHaveBeenCalled(); - }); - - - it('should collect all hinting messages using angular.hint', function() { - var sampleControl = $controller(MockController); - $controllerProvider.register('sample', function() {}); - $controller('sample'); - var log = angular.hint.flush(); - var totalNumberOfMessages = log['Controllers'].warning.length + - (log['Controllers'].error || []).length; - - expect(totalNumberOfMessages).toBe(1); + expect(angular.hint.emit).not.toHaveBeenCalled(); }); }); @@ -238,20 +225,16 @@ describe('module.controller', function() { beforeEach(module('ngHintControllers')); beforeEach(function() { - spyOn(angular.hint, 'log').and.callThrough(); - }); - - afterEach(function () { - angular.hint.flush(); + spyOn(angular.hint, 'emit').and.callThrough(); }); it('should accept name and constructor as separate arguments', function() { angular.module('sampleApp', []).controller('SampleController', angular.noop); - expect(angular.hint.log).not.toHaveBeenCalled(); + expect(angular.hint.emit).not.toHaveBeenCalled(); angular.module('sampleApp', []).controller('sampleController', angular.noop); - expect(angular.hint.log).toHaveBeenCalled(); - expect(angular.hint.log.calls.count()).toBe(1); + expect(angular.hint.emit).toHaveBeenCalled(); + expect(angular.hint.emit.calls.count()).toBe(1); }); @@ -260,7 +243,7 @@ describe('module.controller', function() { 'SampleController': angular.noop, 'sampleController': angular.noop }); - expect(angular.hint.log).toHaveBeenCalled(); - expect(angular.hint.log.calls.count()).toBe(1); + expect(angular.hint.emit).toHaveBeenCalled(); + expect(angular.hint.emit.calls.count()).toBe(1); }); }); diff --git a/test/events.spec.js b/test/events.spec.js index d453897f..5e5836a1 100644 --- a/test/events.spec.js +++ b/test/events.spec.js @@ -12,17 +12,17 @@ describe('hintEvents', function() { $rootScope = _$rootScope_; $compile = _$compile_; $controller = _$controller_; - spyOn(angular.hint, 'log').and.callThrough(); + spyOn(angular.hint, 'emit').and.callThrough(); })); - it('should log a message if the path to handle an ng-event is not found', function() { + it('should emit a message if the path to handle an ng-event is not found', function() { var elt = angular.element(''); $compile(elt)($rootScope); $rootScope.$digest(); elt.triggerHandler('click'); // TODO: fix this 'a' is undefined - expect(angular.hint.log).toHaveBeenCalledWith('Events', 'a.b.c is undefined'); + expect(angular.hint.emit).toHaveBeenCalledWith('Events:undef', 'a.b.c is undefined'); }); // TODO: implement this @@ -33,9 +33,9 @@ describe('hintEvents', function() { $rootScope.$digest(); elt.triggerHandler('click'); - // expect(angular.hint.log).not.toHaveBeenCalledWith('Events', 'a is undefined'); - expect(angular.hint.log).toHaveBeenCalledWith('Events', 'a.b is undefined'); - expect(angular.hint.log).toHaveBeenCalledWith('Events', 'a.b.c is undefined'); + // expect(angular.hint.emit).not.toHaveBeenCalledWith('Events:undef', 'a is undefined'); + expect(angular.hint.emit).toHaveBeenCalledWith('Events:undef', 'a.b is undefined'); + expect(angular.hint.emit).toHaveBeenCalledWith('Events:undef', 'a.b.c is undefined'); }); it('should log a message if the path to handle an ng-event with array syntax is not found', function() { @@ -45,9 +45,9 @@ describe('hintEvents', function() { $rootScope.$digest(); elt.triggerHandler('click'); - // expect(angular.hint.log).not.toHaveBeenCalledWith('Events', 'a is undefined'); - expect(angular.hint.log).toHaveBeenCalledWith('Events', 'a[\'b\'] is undefined'); - expect(angular.hint.log).toHaveBeenCalledWith('Events', 'a[\'b\'].c is undefined'); + // expect(angular.hint.emit).not.toHaveBeenCalledWith('Events:undef', 'a is undefined'); + expect(angular.hint.emit).toHaveBeenCalledWith('Events:undef', 'a[\'b\'] is undefined'); + expect(angular.hint.emit).toHaveBeenCalledWith('Events:undef', 'a[\'b\'].c is undefined'); }); diff --git a/test/getNgAppMod.spec.js b/test/getNgAppMod.spec.js index 8b41b55e..e5cb251c 100644 --- a/test/getNgAppMod.spec.js +++ b/test/getNgAppMod.spec.js @@ -18,10 +18,10 @@ describe('getNgAppMod()', function() { 'id': {value: 'idName'}, 'ng-app': {value: 'testModule'} }; + spyOn(angular.hint, 'emit').and.callThrough(); var foundNgApp = getNgAppMod(attributes, false); getNgAppMod(attributes, foundNgApp); - var log = hintLog.flush(); - expect(log.Modules.error).toEqual(['ng-app may only be included once. The module ' + - '"testModule" was not used to bootstrap because ng-app was already included.']); + expect(angular.hint.emit).toHaveBeenCalledWith('Modules', 'ng-app may only be included once. The module ' + + '"testModule" was not used to bootstrap because ng-app was already included.', 1); }); }); \ No newline at end of file diff --git a/test/hasNameSpace.spec.js b/test/hasNameSpace.spec.js index da4d2ec1..d50d2b96 100644 --- a/test/hasNameSpace.spec.js +++ b/test/hasNameSpace.spec.js @@ -2,10 +2,6 @@ var hasNameSpace = require('../src/modules/angular-hint-modules/hasNameSpace'); var hintLog = angular.hint; describe('hasNameSpace()', function() { - afterEach(function() { - hintLog.flush(); - }); - it('should check that a module has a correctly formatted name', function() { expect(hasNameSpace('MyApp')).toBe(false); expect(hasNameSpace('myapp')).toBe(false); diff --git a/test/log.spec.js b/test/log.spec.js deleted file mode 100644 index 34d56418..00000000 --- a/test/log.spec.js +++ /dev/null @@ -1,80 +0,0 @@ -'use strict'; - -var hint = angular.hint; - -describe('hint', function() { - - afterEach(function() { - expect(hint.flush()).toEqual({}); - }); - - describe('log', function() { - it('should add a new message to the message queue', function() { - hint.log('Directives', 'An error', 1); - expect(hint.flush()['Directives'].error).toEqual(['An error']); - }); - - - it('should queue modules without a given name under General', function() { - hint.log('','An error', 1); - expect(hint.flush()['General'].error).toEqual(['An error']); - }); - - - it('should queue modules without a given severity under Suggestion', function() { - hint.log('','An error'); - expect(hint.flush()['General'].suggestion).toEqual(['An error']); - }); - - - it('should prevent the logging of duplicate messages', function() { - //Same error, only logged once - hint.log('Directives', 'An error', 1); - hint.log('Directives', 'An error', 1); - expect(hint.flush()['Directives'].error.length).toBe(1); - - //Different errors, both logged - hint.log('Directives', 'An error', 1); - hint.log('Directives', 'An error part 2', 1); - expect(Object.keys(hint.flush()['Directives'].error).length).toBe(2); - - //Different severities, both logged - hint.log('Directives', 'An error', 1); - hint.log('Directives', 'An error part 2', 2); - var log = hint.flush(); - expect(Object.keys(log['Directives'].error).length).toBe(1); - expect(Object.keys(log['Directives'].warning).length).toBe(1); - - hint.log('','An error', 1); - hint.log('','An error', 1); - expect(Object.keys(hint.flush()['General'].error).length).toBe(1); - }); - }); - - describe('flush', function() { - it('should return the currently queued messages', function() { - hint.log('', 'An error', 1); - hint.log('', 'Another error', 1); - var log = hint.flush(); - expect(log['General'].error).toEqual(['An error', 'Another error']); - }); - - - it('should empty the queued messages', function() { - hint.log('', 'An error', 1); - hint.log('', 'Another error', 2); - var log = hint.flush(); - expect(log['General'].error[0]).toEqual('An error'); - expect(log['General'].warning[0]).toEqual('Another error'); - }); - }); - - describe('onMessage', function() { - it('should be called whenever a message is added', function() { - hint.onMessage = jasmine.createSpy('onMessage'); - hint.log('', 'An error', 1); - expect(hint.onMessage).toHaveBeenCalledWith('General', 'An error', 'error', undefined); - hint.flush(); - }); - }); -}); diff --git a/test/modules.spec.js b/test/modules.spec.js index afbb60f8..24898ff9 100644 --- a/test/modules.spec.js +++ b/test/modules.spec.js @@ -15,34 +15,30 @@ describe('hintModules', function() { modData.createdMulti = { 'testModule': ['testModule'] }; - }); - - afterEach(function() { - hintLog.flush(); + spyOn(angular.hint, 'emit').and.callThrough(); }); it('should identify modules created and not loaded', function() { angular.module('createdAndNotLoaded', []); start(); - expect(hintLog.flush().Modules.warning[0]).toBe('Module "createdAndNotLoaded" was' + - ' created but never loaded.'); + expect(angular.hint.emit).toHaveBeenCalledWith('Modules', 'Module "createdAndNotLoaded" was' + + ' created but never loaded.', 2); }); it('should identify modules loaded that do not exist', function() { angular.module('testModule', ['doesntExist']); start(); - var log = hintLog.flush(); - expect(log.Modules.error[0]).toBe('Module "doesntExist" was loaded but' + - ' does not exist.'); + expect(angular.hint.emit).toHaveBeenCalledWith('Modules', 'Module "doesntExist" was loaded but' + + ' does not exist.', 1); }); it('should identify modules that have been loaded multiple times', function() { angular.module('testModule', []); start(); - expect(hintLog.flush().Modules.warning[1]).toBe('Multiple modules with name ' + - '"testModule" are being created and they will overwrite each other.'); + expect(angular.hint.emit).toHaveBeenCalledWith('Modules', 'Multiple modules with name ' + + '"testModule" are being created and they will overwrite each other.', 2); }); @@ -50,8 +46,8 @@ describe('hintModules', function() { angular.module('moduleDuplicate', []); angular.module('moduleDuplicate', []); start(); - expect(hintLog.flush().Modules.warning[3]).toBe('Multiple modules with name ' + - '"moduleDuplicate" are being created and they will overwrite each other.'); + expect(angular.hint.emit).toHaveBeenCalledWith('Modules', 'Multiple modules with name ' + + '"moduleDuplicate" are being created and they will overwrite each other.', 2); }); @@ -59,27 +55,27 @@ describe('hintModules', function() { angular.module('testModule2', []); angular.module('testModule2').controller('controller', [function(){}]); start(); - var log = hintLog.flush().Modules; - var duplicateMessages = log.warning; - expect(duplicateMessages).not.toContain('Multiple modules with name "testModule2" are being ' + - 'created and they will overwrite each other.'); + expect(angular.hint.emit).not.toHaveBeenCalledWith('Modules', 'Multiple modules with name "testModule2" are being ' + + 'created and they will overwrite each other.', 2); }); it('should warn if modules are not named with lowerCamelCase or dotted.segments', function() { angular.module('testmodule', []); start(); - var log = hintLog.flush(); - expect(log.Modules.suggestion[0]).toBe('The best practice for' + - ' module names is to use lowerCamelCase. Check the name of "testmodule".'); + expect(angular.hint.emit).toHaveBeenCalledWith('Modules', 'The best practice for' + + ' module names is to use lowerCamelCase. Check the name of "testmodule".', 3); angular.module('Testmodule', []); - expect(hintLog.flush().Modules.suggestion[0]).toBe('The best practice for' + - ' module names is to use lowerCamelCase. Check the name of "Testmodule".'); + expect(angular.hint.emit).toHaveBeenCalledWith('Modules', 'The best practice for' + + ' module names is to use lowerCamelCase. Check the name of "Testmodule".', 3); }); }); describe('hintModules integration', function() { + beforeEach(function () { + spyOn(angular.hint, 'emit').and.callThrough(); + }); it('should not warn about itself or other ngHintModules', function() { // what is this i dont even @@ -98,6 +94,6 @@ describe('hintModules integration', function() { //angular.module('ngLocale', []); start(); - expect(hintLog.flush()['Modules']).not.toBeDefined(); + expect(angular.hint.emit).not.toHaveBeenCalled(); }); });