Testing after installing external dependency
I love this seed, however, I'm having a hard time getting tests to work after installing external dependencies. I followed the wiki instructions, but after installing ng2-material and running npm test, I get the warning, "WARN [web-server]: 404: /base/ng2-material/all.js" and no tests are run. If I include this file in the karma.conf.js file array, I get, "ERROR: ReferenceError: Can't find variable: require." The app works fine in the browser with a material design, but I'm fairly new to SystemJs and I'm not sure what it wants, or if it's even related to SystemJs. Thanks in advance for any help.
@Sixthdim - I have a ng2-material fork of the seed ( along with a few others ). I'll be finishing the conversion tomorrow afternoon, i'll have a look at the test execution then.
Any progress here?
A coworker and I have been trying to get tests working with this seed and ng2-material (0.3.3), but with no luck. We have determined if a component imports ng2-material AND has a spec file, that spec file is not run and no tests after that test are run. If either the ng2-material import or the spec file is removed from the component, tests from other components run. There are no errors and the only warning is WARN [web-server]: 404: /base/ng2-material/all.js, which seems to be inconsequential. Also, a few other external dependencies we are using are playing nice with tests, so it just seems to be an issue with ng2-material, but we are still trying to figure out why. I looked at the fork @d3viant0ne made from an earlier version of this seed (https://github.com/DeviantJS/angular2-seed-ng2material) and it also gets the warning, but his tests do run.
@Sixthdim - That repo is out of sync by about a week ( getting murdered at work ) I'll pick up the latest master and make sure they tests still run.
Having tinkered with ng2-material, I would highly suggest waiting on angular2-material which is catching up rapidly in the realm of components.
There are other issues related to packaging with ng2-material that have made it difficult to work with. Professionally, I have chosen to wait for the official Material2 repo.
@d3viant0ne, probably a sound decision. Thanks for your input and for taking a look.
@Sixthdim Silly question, but have you referenced the lib in karma.conf.js ?
@ludohenin I tried to reference it, but that would generate an error saying, ERROR: ReferenceError: Can't find variable: require.
@Sixthdim You probably need to modify system config in test-main.js.
See here for an example of how to reference custom paths for various libraries:
https://github.com/NathanWalker/angular2-seed-advanced/blob/master/test-main.js#L21-L36
So given ng2-material, you probably need to add to paths:
'ng2-material': 'node_modules/ng2-material/all.js'
And then also, as @ludohenin mentioned, you also need to make sure they are in karma.conf.js like so:
https://github.com/NathanWalker/angular2-seed-advanced/blob/master/karma.conf.js#L34-L38
So for ng2-material, would probably be like:
{ pattern: 'node_modules/ng2-material/**/*.js', included: false, watched: false }
@NathanWalker Well, I thought I had tried all permutations, but your suggestion worked! But only with the addition of ng2-material/*, like:
{
'ng2-material': 'node_modules/ng2-material/all.js',
'ng2-material/*': 'node_modules/ng2-material/*.js'
}
Tests now run and there are no warnings. Thank you for your help!
@Sixthdim Cheers! Glad it worked :+1:
I'm having a similar problem. At first I went through the same problem and got to a similar solution. Although the message I'm getting now is an error when loading the library package json (and it's not even searching it in /base/):
'(SystemJS) XHR error (404 Not Found) loading http://localhost:9876/node_modules/ng2-bootstrap/package.json
Does any one has any idea? When I remove the libraries the tests run, but I get the errors about the directives I'm using from the library, of course.
Any one had a similar problem?
I'm having the same problem with the angular2-google-maps library:
'(SystemJS) XHR error (404 Not Found) loading http://localhost:9876/node_modules/angular2-google-maps/package.json
Always get this error whe running the tests.