Closed nicklasb closed 9 years ago
One option you can try is to use testFileRegex
instead of testFileSuffix
to be more specific (I should really add doco to the README).
Another option is you can use exclude
in the Karma config. You give it globs to exclude completely from Karma:
http://karma-runner.github.io/0.12/config/configuration-file.html
So this is intended behaviour? Is there no way in using the included
option from the pattern to automagically exclude those things? Something in karma must make that distinction?
No, it shouldn't work any differently. The jspm_packages
folder isn't
treated any differently by karma or karma-systemjs.
On 13 Aug 2015 22:04, "Nicklas Börjesson" notifications@github.com wrote:
So this is intended behaviour? Is there no way in using the included option from the pattern to automagically exclude those things? Something in karma must make that distinction?
— Reply to this email directly or view it on GitHub https://github.com/rolaveric/karma-systemjs/issues/38#issuecomment-130644064 .
I am not sure I understand, doesn't the included
options tell karma not to load the files, just to serve them? What seems strange is that they still seems to be loaded.
Sorry, you're right - it is different from using vanilla Karma.
What karma-systemjs
does is get the list of all files that Karma is serving, looks for the ones it thinks are tests (using testFileRegex
or testFileSuffix
) and calls System.import(filePath)
on them.
Hm, is there any way to instead build that list from the settings, perhaps using karmas' own code for that? It has to do that somewhere, right?
Because there are a couple of things that aren't great:
I don't necessarily agree with the first point. Assuming it can accurately identify the correct test suites, then it should only 'load' the minimum files necessary to run those tests.
However there's clearly a problem with that assumption - karma-systemjs
is picking more files than you want, and the configs mechanisms available aren't adequate to fix that.
So what's the best solution? Here's the options that I can think of:
System.import()
for every file that would normally have a {included: true}
pattern in standard Karma.
This should be ok. Even if you import things twice (eg. Because it's imported by another file) it'll be cached anyway - so no performance drawback. There could be side effects from loading modules, but that's always been a risk, really.
My only hesitation is that it's very different from how karma-systemjs
is configured today, but this wouldn't be the first or last open source project to change APIs.sourceFolder
that then gets used as a prefix for test suite paths, etc.
The glob is probably the best option.What do you think?
I would prefer 1, simply because it, in my opinion, is the correct one. It is either that, or having to answer this question indefinitely. And those who rely on it working like this has a really strange configuration that at least I would not like to support. Having plugins diverging radically from how parent projects works confuses uses and drives issues to the plugin project.
Breaking change is what major releases are for. I wouldn't be too afraid by them, especially when the plugin is this young. I mean, I know that there are users but here hasn't even been a release yet, I suppose that is intentional, but it should signal to users that this is a very young project.
Edited the above comment significantly (if you are reading this via mail).
OK, I've done a first crack at it. Committed under 0.8 branch, and published to npm as '0.8.0-beta2': https://github.com/rolaveric/karma-systemjs/tree/0.8
Updated my angular-seed repo to use it too: https://github.com/rolaveric/angular-seed/tree/es6
So what it does now is it takes every file pattern with {included: true}
, uses minimatch
to generate a RegExp string from the glob pattern that can be passed to the browser, then sets {included: false}
so Karma doesn't add a tag for them.
Then it passes those RegExp strings to the browser, which loops through each looking for files that match them - if they do, it runs System.import()
.
I've renamed systemjs.files
to systemjs.serveFiles
to be explicit about the shortcut it's providing, and also because I want people to think of it differently from the standard files
property.
Let me know what you think.
Good stuff! I'll try it out immidiately! (you didn't finish the last sentence)
Cheers. I didn't escape the script tag well enough for github, so I think it assumed the worst and just cleared the whole lot.
Results:
{pattern: 'test/*spec.js', included: true, served: true}
In conclusion, this is way better than before, now everything works logically.
Another thing, It would be great if you could make github releases too, so that one can see in detail what has changed, for example since 0.7.x.
Yeah point 2 is definitely a risk. There's a very real possibility of a race-condition where two third-party libraries assume they'll be loaded in a specific order. eg. angular and angular-mocks is the situation I ran into. In most cases you can tweak the file patterns in your karma config so those libraries are just served and then imported by your test suites, but the same can't be said for other karma plugins. Sounds your reordering workaround does the job though - I might add that to the FAQ in the README.md
Good idea on the github releases. I've honestly never done one before though so I'll have to read up on the details first. But it's just hit midnight here, so I might leave that till the morning :P
It is actually really easy, it is just version, caption and description linked to a tag. And in the case of beta:s use the pre-release setting. Sleep tight!
Done: https://github.com/rolaveric/karma-systemjs/releases/tag/0.8.0-beta2 I'll leave it in beta for a week or so, and if no significant issues come up I'll merge it into the master branch.
I was on 0.7.2 and upgraded to 0.8.0.
I'd like to get angular.js
and related files loaded globally (via <script>
tag). Now that karma.files[*].included is used to invoke System.register
, I can't find a way to do this.
We're testing against a few different versions of angular, and this was the mechanism we used to pick the version of angular to load using karma.files.
https://github.com/angular-ui/ui-router/blob/feature-1.0/Gruntfile.js#L103-L114
https://github.com/angular-ui/ui-router/blob/feature-1.0/files.js#L25-L33
https://github.com/angular-ui/ui-router/blob/feature-1.0/config/karma.js#L36-L46
Currently, all our tests (and some of our src) assumes angular is globally loaded. Any pointers would be appreciated. I can open a new issue if it would prefer.
@christopherthielen That's actually a scenario I never considered.
Does creating a specific files
pattern just for angular at the start, so it's System.import()
ed before everything else, work?
If not I'll have to create an includeFiles
property in the config for specifying patterns that MUST be included by script tags before SystemJS.
Importing angular first does not work. I think angular tests if it's being required and doesn't load the global or something. I can push a branch with the example if you want to play with the setup, but I think I will need a separate option to load the library globally like regular karma "included".
OK I've just committed a change where you can specify paths or patterns under systemjs.includeFiles
: 820b421c1cd58f8bc05dbe295759d3b62bbeac83
Give it a try. If it solves your problem, I'll publish a 0.8.1 release with it.
Hi,
I am trying to get testing going in my project and I am encountering a problem where I need to make karma publish my dependencies to make them available for the testing to work like this:
{pattern: 'jspm_packages/**/*.*', included: false, served: true}
The problem is that if I set the
testFileSuffix
to "spec.js", it tries to run all the tests in the dependencies as well, like angulars' tests. To make them not run, I have to narrow down the suffix to something that only matches my tests.Is this intended behaviour, I am thinking that this is likely related to karma-systemjs as it is a karma-systemjs configuration option?