2

I managed to get a couple of EAK/grunt based Ember apps upgraded to 1.11 with HTMLBars, and then got them migrated to Ember CLI/Brocolli. The unit tests were setup for karma test runner so I'm looking at how to get those running in the CLI projects now, but I didn't write the tests and really have no experience with unit testing javascript modules.

Searching around the iNet, I can see that others have also used karma becasue of its coverage output and are trying to get it to work with Ember CLI, but that Ember Core isn't supporting it, though they say anyone should be able to get it set up with a custom addon. I'm also trying to use the 'testem' runner to see what sticks with that.

The Ember site does have an 'automating tests with runners' page for v1.10, with sections on 'testem' and 'karma', but it doesn't appear for v1.11 so I can't tell from that site what is or isn't relevant. But it seems like I should be able to work out a solution for the karma test runner, so I added the old devDependencies to the project package.json:

"karma": "^0.12.31",
"karma-chai": "~0.1.0",
"karma-chrome-launcher": "~0.1.2",
"karma-coverage": "~0.2.1",
"karma-firefox-launcher": "~0.1.3",
"karma-junit-reporter": "~0.2.1",
"karma-mocha": "~0.1.3",
"karma-phantomjs-launcher": "~0.1.2",
"karma-sinon-chai": "~0.1.5"

I also dropped the old 'karma.conf.js' (along with a few other karma confs) in the project and updated the paths inside (from 'vendor' to 'bower_components'). I did find a 'ember-cli-karma' node mode and installed it, but it seems to just have a 'package.json'. It has no docs and seems like just a stubbed out starter project with no implementation. I also installed 'karma', 'karma-cli' and 'testem' node modules.

The testem docs say to add you src and test files to 'testem.json', but with out examples I don't know what that means; a list of every src and test file? With what path; relative, absolute? Forward slashes, backslashes? preceded with / or ./ or ../? I just left them out because I think the system just finds the src and tests by convention.

When I run 'karma init' I get:

readline.js:529
this.line = this.line.slice(this.cursor);
                   ^
  TypeError: Cannot read property 'slice' of undefined

When I run 'testem' I get:

TEST'EM 'SCRIPTS!
Open the URL below in a browser to connect.
http://localhost:7357/aN;0faN;NaNf

...then the project's '../tests/index.html' loads in a browser, but is not able to 'find' any of the asset files (css, js) so nothing executes or renders correctly. I just see template expressions ({{content-for 'head'}}, etc).

When I run 'ember test' I get:

Building...BuildingBuilding.Building..Building...Built project successfully.

1..0
# tests 0
# pass  0
# fail  0

# ok
No tests were run, please check whether any errors occurred in the page (ember test --server) and ensure that you have a test launcher (e.g. PhantomJS) enabled.

When I run 'ember test --server' I get:

The test index.html loaded in a browser with a test report. When I uncheck 'hide passed tests' the report indicates '29 passed, 28 failed'. It has 11 sections where a particular test may have 3 problems such as 'could not load', 'failed', 'could not find module', 'attempting to register an unknown factory' or 'died'.

With this, I'm obviously running testem and not karma, so may as well work on getting testem working and figure out karma later. If there were more examples and migration troubleshooting docs I might have a systematic way to work through some of these problems.

bobvan
  • 251
  • 3
  • 9

2 Answers2

4

I ran into "No tests were run,..." problem recently after a node upgrade. I fixed it with a:

npm install -g phantomjs

This provides some additional options as well:

https://github.com/ember-cli/ember-cli/issues/3969

Jordan
  • 370
  • 3
  • 13
  • It's sort of a loaded question and was hoping for some insight on why the ember docs still have info on karma, what's the story with the ember-cli-karma project and how to get karma working in CLI. But trying to make sense of karma doesn't appear to be worth the effort at this point so I'll just work on getting the existing tests to work with testem. Installing the phatomjs headless runner did work, and I can see why, so I can accept your answer. Thx. – bobvan May 04 '15 at 16:03
  • Yeah, it did look like a multipart question. I wished I knew about the karma tests in Ember CLI. I used them in AngularJS but not in EmberJS (using QUnit there). Best of luck with the rest. – Jordan May 04 '15 at 19:23
0

I had the Cannot read property 'slice' of undefined error on MS Windows, running via MSys2. I have solved it by using karma init from an ordinary cmd prompt.

Vladius
  • 4,268
  • 2
  • 20
  • 21
  • Hmm, OK, ya I think I tried 'karma init' at one point. Well in my case I can't really go very far with karma because my tests were written in mocha syntax, with chai and sinon, so I installed a mocha module which overides the baked-in testem processes so now when I run 'ember test -server' I get a report more compatible with mocha. My problem now is objects injected by initializers are undefined in the tests when looked up from the container. So I have another question posted about that. – bobvan May 12 '15 at 16:16