Hi,
It seems I am unable to instruct Karma to only run a particular file.
Is this not possible anymore (I saw a reference to this having been possible on Stack Overflow)?
$ karma run karma.conf.js --files=new Array\("tests/unit/frontend/specs/timeLeftSpec.js"\)
[2015-11-30 10:20:50.784] [DEBUG] config - Loading config /Users/vs/Kod/myproject/karma.conf.js
/Users/vs/Kod/myproject/node_modules/karma/lib/config.js:107
config.files = config.files.map(createPatternObject).map(createPatternMapper(basePathResolve));
^
TypeError: config.files.map is not a function
at normalizeConfig (/Users/vs/Kod/myproject/node_modules/karma/lib/config.js:107:31)
at Object.parseConfig (/Users/vs/Kod/myproject/node_modules/karma/lib/config.js:293:10)
at Object.exports.run (/Users/vs/Kod/myproject/node_modules/karma/lib/runner.js:30:16)
at Object.<anonymous> (/usr/local/share/npm/lib/node_modules/karma/bin/karma:22:39)
at Module._compile (module.js:434:26)
at Object.Module._extensions..js (module.js:452:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Function.Module.runMain (module.js:475:10)
at startup (node.js:117:18)
I imagine using this for allowing my IDE (PhpStorm) to run the Karma test for a file (in the IDE) whenever a test/implementation file changes.
I am in the same situation, and cannot seem to find a way to make it work.
Is files in karma.conf.js an array?
files: [
'tests.bundle.js'
]
@tbroussard Thank you, that seems to help. It looks like its only accepting arrays now
@tbroussard doesn't answer the mail on the original problem. This is a command line issue not a config problem.
Even with this simple script I am still seeing the above error.
#!/bin/sh
set -e
array=(${@//,/ })
echo "###########"
for i in "${!array[@]}";
do
echo " $i ${array[$i]}"
echo
done
echo "###########"
karma start "--files=$array"
use case: npm run karma file1, file2, file3.
package.json:
"scripts:"{
"karma": "./scripts/karma"
}
I'm sorry, but I'm failing to see how and when the --files option would ever work. There is no mention about in the docs or the cli options. It might have been there in an earlier version but currently it simply does not exist, so all the above will not work as far as I understand.
Right no worries it is just documented as an invalid option in a few places like stack overflow. Therefore many; including me went down a rabbit hole.
http://stackoverflow.com/questions/29150998/karma-running-a-single-test-file-from-command-line
@nmccready thanks for mentioning that question, I left a comment for the future
Thanks for the clarification.
Just out of curiosity:
If I would like to run only a single test (when that test or its implementation changes), is there a way of doing this with karma-runner today?
That depends on the test framework you use, mocha for example supports the grep argument and als .only on individual tests. But you have to check your framework/framework adapter for details
@Dignifiedquire is there a cli way or proposed cli way to easily test specific files without using karma.conf.js's? IE I know I can hack it up locally but thats brute force. Basically I want to use all the same setting but easily overwrite the files list. This is easier todo via the js dsl. Example.
Note that the pop line makes assumptions and only works with angular-google-maps.
Where it removes the test everything. And concats on specifics.
@nmccready I'm unsure about this, I can see the usefulness of this but not sure if this is opening a lot of rabbit holes. We could naively allow overriding the files property on the cli but I can see lots of things breaking like preprocessors depending on the files and so on. Also the what would the watcher process do in that case? stop watching all files and start watching only the new files? (that could entail a pretty big performance hit)
I dunno, I never run the watchers I leave that to grunt, gulp or watch. Otherwise too much watching happens and you get into an ugly mess.
Added this to help whomever https://www.npmjs.com/package/karma-kickoff
@nmccready that's pretty cool :)
Banging my head on the wall for a few hours of this now, I don't get why karma needs to be this user-hostile to running a single test. Makes TDD a true pain edit: excruciating.
Ended up creating simple helper script for running single test file github
Banging my head on the wall for a few hours of this now, I don't get why karma needs to be this user-hostile to running a single test. Makes TDD a true pain edit: excruciating.
Comments like this are pretty maintainer-hostile. So if you need this so badly why not create a good PR with tests to solve the issue?
@dignifiedquire As a maintainer, I get it. However, the pain that I get for hours of searching for a solution and coming up with dead ends everywhere I look, that pain is pretty real too.
So if you need this so badly why not create a good PR with tests to solve the issue?
Maybe the reason I had to spend this much time to find a solution is that I wasn't well versed at all in your library, at the level of not even being able to operate it. If I can't even operate the thing, how much time of learning is it going to take me to end up fixing it and making a PR? Surely more than a few hours.
I just ran into this issue today. While I would like to find an easy way to specify an individual file, the other answer in the SO thread does give a way to test a describe block which is very helpful. For me, when I want to run tests on an individual file, calling out the name of a describe block is sufficient.
karma run -- --grep=nameOfDescribeBlock
Most helpful comment
Banging my head on the wall for a few hours of this now, I don't get why karma needs to be this user-hostile to running a single test. Makes TDD
a true painedit: excruciating.