-
Notifications
You must be signed in to change notification settings - Fork 616
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make "npm test" run Karma tests #140
Conversation
fcd4218
to
a3b141c
Compare
Result is this: ``` $ npm test > docker-registry-frontend@0.0.2 pretest /Users/marca/dev/git-repos/docker-registry-frontend_2 > npm install > docker-registry-frontend@0.0.2 postinstall /Users/marca/dev/git-repos/docker-registry-frontend_2 > bower install > docker-registry-frontend@0.0.2 test /Users/marca/dev/git-repos/docker-registry-frontend_2 > karma start test/karma.conf.js 09 07 2016 13:36:20.771:WARN [karma]: No captured browser, open http://localhost:8080/ 09 07 2016 13:36:20.781:INFO [karma]: Karma v1.1.1 server started at http://localhost:8080/ 09 07 2016 13:36:20.782:INFO [launcher]: Launching browser PhantomJS with unlimited concurrency 09 07 2016 13:36:20.788:INFO [launcher]: Starting browser PhantomJS 09 07 2016 13:36:21.250:INFO [PhantomJS 2.1.1 (Mac OS X 0.0.0)]: Connected on socket /#Z4MF21dfMgThOi3zAAAA with id 9538616 PhantomJS 2.1.1 (Mac OS X 0.0.0) Controller: MainCtrl should attach a list of awesomeThings to the scope FAILED forEach@bower_components/angular/angular.js:326:24 loadModules@bower_components/angular/angular.js:4115:12 createInjector@bower_components/angular/angular.js:4041:22 workFn@bower_components/angular-mocks/angular-mocks.js:2464:60 loaded@http://localhost:8080/context.js:151:17 bower_components/angular/angular.js:4155:53 TypeError: undefined is not an object (evaluating 'scope.awesomeThings') in test/spec/controllers/main.js (line 20) test/spec/controllers/main.js:20:17 loaded@http://localhost:8080/context.js:151:17 PhantomJS 2.1.1 (Mac OS X 0.0.0): Executed 1 of 1 (1 FAILED) ERROR (0.005 secs / 0.006 secs) ``` Fixes kwk#139
a3b141c
to
080109e
Compare
This makes the `MainController` tests pass. ``` $ npm test > docker-registry-frontend@0.0.2 pretest /Users/marca/dev/git-repos/docker-registry-frontend_2 > npm install > docker-registry-frontend@0.0.2 postinstall /Users/marca/dev/git-repos/docker-registry-frontend_2 > bower install > docker-registry-frontend@0.0.2 test /Users/marca/dev/git-repos/docker-registry-frontend_2 > karma start test/karma.conf.js 09 07 2016 17:06:59.974:WARN [karma]: No captured browser, open http://localhost:8080/ 09 07 2016 17:06:59.986:INFO [karma]: Karma v1.1.1 server started at http://localhost:8080/ 09 07 2016 17:06:59.986:INFO [launcher]: Launching browser PhantomJS with unlimited concurrency 09 07 2016 17:07:00.133:INFO [launcher]: Starting browser PhantomJS 09 07 2016 17:07:01.051:INFO [PhantomJS 2.1.1 (Mac OS X 0.0.0)]: Connected on socket /#6enEIdsugSVdKVioAAAA with id 62465837 PhantomJS 2.1.1 (Mac OS X 0.0.0): Executed 1 of 1 SUCCESS (0.004 secs / 0.024 secs) ```
080109e
to
1037d8e
Compare
E.g.: - angular-bootstrap, - angular-bootstrap-checkbox - angular-filter - angular-loading-bar - angular-moment - angular-smart-table I also alphabetized the list to make it easier to check if something is already included.
In `MainController`, depend on the `registry-services` module instead of the `registry-host-services` module.
Remove `app/services/registry-host-services.js` because it seems to be an older, unused version of `app/services/registry-services.js`
Specify that the `repository-list-controller` module depends on `ngRoute` and `ui.bootstrap` modules. Otherwise controller tests of this module fail.
In `repository-list-controller`, do: $scope.repositories = data; in the promise callback. Otherwise, the new tests in `app/repository/repository-list-controller.spec.js` fail. This is because promises get resolved in templates but not in until tests -- see http://stackoverflow.com/questions/15048132/angularjs-promise-not-being-resolved-in-unit-test
in `app/repository/repository-list-controller.spec.js`. RepositoryListController ✓ should attach some keys to the scope
Use `DOCKER_REGISTRY_HOST` and `DOCKER_REGISTRY_PORT` environment variables so that one can specify a custom Docker registry server while developing, without hacking `Gruntfile.js`.
@msabramo Thank you so much for contributing tests to this project. It should help getting all the open PRs merged in more quickly. |
See also PR #140 for more information on tests.
"postinstall": "bower install", | ||
"pretest": "npm install", | ||
"test": "karma start test/karma.conf.js", | ||
"test-single-run": "karma start test/karma.conf.js --single-run" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kwk There are no dumb questions. Use npm run test-single-run
(note run
in there). npm test
is a special case, but in general you need to use npm run
(or npm run-script
) to execute the scripts
that you define in package.json
.
$ npm run test-single-run
> docker-registry-frontend@0.0.2 test-single-run /Users/marca/dev/git-repos/docker-registry-frontend_2
> karma start test/karma.conf.js --single-run
19 07 2016 06:29:24.145:WARN [karma]: Port 8080 in use
19 07 2016 06:29:24.148:WARN [karma]: Port 8081 in use
19 07 2016 06:29:24.148:INFO [karma]: Karma v1.1.1 server started at http://localhost:8082/
19 07 2016 06:29:24.149:INFO [launcher]: Launching browser PhantomJS with unlimited concurrency
19 07 2016 06:29:24.157:INFO [launcher]: Starting browser PhantomJS
19 07 2016 06:29:24.613:INFO [PhantomJS 2.1.1 (Mac OS X 0.0.0)]: Connected on socket /#L0dobW7vCDANyy35AAAA with id 59001397
docker-registry-frontend
✓ /home should display home page
✓ /repositories should display repository list page
✓ /repositories/10 should display repository list page
✓ /repositories/20 should display repository list page
✓ URL with repositoryUser and repositoryName and no tagsPerPage should display repository detail page
✓ URL with repositoryUser and repositoryName and tagsPerPage should display repository detail page
✓ URL with repositoryName but no repositoryUser and no tagsPerPage should display repository detail page
✓ URL with repositoryName but no repositoryUser and tagsPerPage should display repository detail page
✓ /about should display about page
✓ /tag/repositoryUser/repositoryName/latest should display tag detail page
✓ /image/88e37c7099fa should display image detail page
✓ /image/88e37c7099fa/tag should display create tag page
✓ /unknown-url should display home page
RepositoryListController
✓ should attach some keys to the scope
MainController
✓ should attach an appVersion and registryHost to the scope
PhantomJS 2.1.1 (Mac OS X 0.0.0): Executed 15 of 15 SUCCESS (0.008 secs / 0.077 secs)
TOTAL: 15 SUCCESS
See https://docs.npmjs.com/cli/run-script for more info on this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was going to submit a PR to change it in .travis.yml
but I see that you are a step ahead of me.
Crossing my fingers and hoping that the Travis CI build passes!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@msabramo Thank you for this. I totally forgot about run
. It probably will not pass because in pretest
you do an npm install
which I have to do before running the single test as well, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmmm yeah, you are probably right. And I don't know if there is a way to have a pre
step for a script. I guess the easiest thing to do is to have the .travis.yml
do npm install
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might work on Travis perhaps, because maybe the default for a node_js
project is to do npm install
for the install
step.
That seems to be what they are saying (I think) at https://docs.travis-ci.com/user/languages/javascript-with-nodejs#Travis-CI-uses-npm
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just found this:
https://karma-runner.github.io/latest/plus/travis.html
Though that will work, it doesn't seem ideal because then npm test
won't run continuously, which is kind of nice for development. I guess one could use a script
for that, like test-continuously
or something.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here's what angular-seed does:
https://github.com/angular/angular-seed/blob/master/.travis.yml
script:
- node_modules/.bin/karma start karma.conf.js --no-auto-watch --single-run --reporters=dots --browsers=Firefox
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This makes
npm test
run unit tests with Karma.I also added some tests for routes in
app/app.spec.js
.Result is this:
Fixes #139