ericclemmons / grunt-angular-templates

Grunt build task to concatenate & pre-load your AngularJS templates
MIT License
710 stars 107 forks source link

Can't find application module #94

Closed vance closed 10 years ago

vance commented 10 years ago

The template js file produces:

angular.module('MyLittleApp').run(['$templateCache', function($templateCache) { 'use strict';

$templateCache.put('src/main/app/components/nav/navigation.html',

but when Karma runs it, it says "Module 'MyLittleApp' is not available!" Without including this file tests work normally.

ericclemmons commented 10 years ago

Is your actual module MyLittleApp already included before this file?

Example:

angular.module('MyLittleApp', ['ui.router']).config(...)

Of course there will be an error if Angular tries to reference a module that hasn't been declared yet...

vance commented 10 years ago

Yes, of course the application is there. I can include the application module in my tests and they work fine.

ericclemmons commented 10 years ago

I'm not sure what to tell you without a test case. Hundreds of people have been using this in both testing, development & production successfully, so why Karma is complaining that the module is not available is probably a Karma issue. (That error doesn't sound like an Angular error).

Here's what seems promising via Google:

http://stackoverflow.com/questions/19412109/angular-jasmine-test-not-finding-modules

I can open this up again once there's an example to work off of...

vance commented 10 years ago

My tests work absolutely fine in both grunt-contrib-jasmine and karma. The tests can load the application module and, for instance, my NavController. It can run tests against it.

Its as soon as I include the app.template.js in my karma config, the application is undefined error is raised (from that file). Do I need to defer something? I've tried wrapping in IIFE wrappers even.

The same error is raised in both grunt-karma and in grunt-contrib-jasmine.

ericclemmons commented 10 years ago

@vance I've had my own set of issues before with multiple modules & Karma (namely ui.bootstrap, which is common in my stuff). Because Karma's such a ... interesting piece of architecture (I'm being polite here), can you take the Gruntfile.js, karma.conf.js, a core module, and show an example on how to reproduce this? Otherwise I'm flying blind here... =/

vance commented 10 years ago

It would take a bit of time to clean out the project of business-specific doo-dads. But it could be done.

vance commented 10 years ago

Thanks for your patience. I've created a stripped-down test project. I included all the node modules so you can just pull-n-go.

Run grunt karma:go or grunt runtJasmine. In this project it is possible to run the tests standalone without template.js... you can toggle this in the karma config by setting {pattern:'src/main/app/templates.js', included: true}, to false

https://github.com/vance/debugGruntAngularTemplates

vance commented 10 years ago

Just realized i pushed a broken version (from my cleanup). Gimme a sec.

vance commented 10 years ago

ok. I fixed the typo. It runs regardless, just wanted to make sure we are clear that's not the issue.

vance commented 10 years ago

Any luck reproducing the problem of not finding the application module?