-
Notifications
You must be signed in to change notification settings - Fork 610
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
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
1c69917
Make "npm test" run Karma tests
msabramo 1037d8e
Make MainController tests work
msabramo 02fab80
test/karma.conf.js: Add more files
msabramo 8c03b03
test/karma.conf.js: Add 'dots' reporter
msabramo d0404bf
Add app/app.spec.js
msabramo 1a30a65
Enable junit and spec Karma reporters
msabramo a9fd8db
app/app.spec.js: Check scope attributes
msabramo 205fc7e
app/app.spec.js: Check scope.appMode
msabramo 19c4762
test/spec/controllers/main.js: Check appVersion & registryHost
msabramo af36dae
MainController: use registry-services
msabramo 351fc22
Remove app/services/registry-host-services.js
msabramo 99fdbd1
repository-list-controller: Add dependencies
msabramo 8e7bdf0
$scope.repositories = data;
msabramo 5463786
Add unit test for RepositoryListController
msabramo 4459aab
Gruntfile.js: Use DOCKER_REGISTRY_{HOST,PORT}
msabramo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,174 @@ | ||
'use strict'; | ||
|
||
describe('docker-registry-frontend', function() { | ||
var $route, $location, $rootScope, $httpBackend, $controller; | ||
|
||
beforeEach(module('docker-registry-frontend')); | ||
beforeEach(inject(function(_$route_, _$location_, _$rootScope_, _$httpBackend_, _$controller_) { | ||
$route = _$route_; | ||
$location = _$location_; | ||
$rootScope = _$rootScope_; | ||
$httpBackend = _$httpBackend_; | ||
$controller = _$controller_; | ||
})); | ||
|
||
it('/home should display home page', function() { | ||
$httpBackend.expectGET('home.html').respond(200); | ||
$location.path('/home'); | ||
$rootScope.$digest(); | ||
expect($route.current.templateUrl).toBe('home.html'); | ||
expect($route.current.controller).toBe('HomeController'); | ||
var scope = {}; | ||
var expectedAppMode = { | ||
"browseOnly": true, | ||
"defaultRepositoriesPerPage": 20, | ||
"defaultTagsPerPage": 10 | ||
} | ||
$controller('HomeController', {$scope: scope}); | ||
$httpBackend.expectGET('/app-mode.json').respond(expectedAppMode); | ||
$httpBackend.flush(); | ||
jasmine.addCustomEqualityTester(angular.equals); | ||
expect(scope.appMode).toEqual(expectedAppMode); | ||
}); | ||
|
||
it('/repositories should display repository list page', function() { | ||
$httpBackend.expectGET('repository/repository-list.html').respond(200); | ||
$location.path('/repositories'); | ||
$rootScope.$digest(); | ||
expect($route.current.templateUrl).toBe('repository/repository-list.html'); | ||
expect($route.current.controller).toBe('RepositoryListController'); | ||
var scope = {}; | ||
$controller('RepositoryListController', {$scope: scope}); | ||
expect(scope.reposPerPage).toBeUndefined(); | ||
}); | ||
|
||
it('/repositories/10 should display repository list page', function() { | ||
$httpBackend.expectGET('repository/repository-list.html').respond(200); | ||
$location.path('/repositories/10'); | ||
$rootScope.$digest(); | ||
expect($route.current.templateUrl).toBe('repository/repository-list.html'); | ||
expect($route.current.controller).toBe('RepositoryListController'); | ||
var scope = {}; | ||
$controller('RepositoryListController', {$scope: scope}); | ||
// expect(scope.reposPerPage).toBe(10); | ||
}); | ||
|
||
it('/repositories/20 should display repository list page', function() { | ||
$httpBackend.expectGET('repository/repository-list.html').respond(200); | ||
$location.path('/repositories/20'); | ||
$rootScope.$digest(); | ||
expect($route.current.templateUrl).toBe('repository/repository-list.html'); | ||
expect($route.current.controller).toBe('RepositoryListController'); | ||
var scope = {}; | ||
$controller('RepositoryListController', {$scope: scope}); | ||
// expect(scope.reposPerPage).toBe(20); | ||
}); | ||
|
||
it('URL with repositoryUser and repositoryName and no tagsPerPage should display repository detail page', function() { | ||
$httpBackend.expectGET('repository/repository-detail.html').respond(200); | ||
$location.path('/repository/owner/name'); | ||
$rootScope.$digest(); | ||
expect($route.current.templateUrl).toBe('repository/repository-detail.html'); | ||
expect($route.current.controller).toBe('RepositoryDetailController'); | ||
var scope = {}; | ||
$controller('RepositoryDetailController', {$scope: scope}); | ||
expect(scope.repositoryUser).toBe('owner'); | ||
expect(scope.repositoryName).toBe('name'); | ||
expect(scope.repository).toBe('owner/name'); | ||
expect(scope.maxTagsPage).toBeUndefined(); | ||
}); | ||
|
||
it('URL with repositoryUser and repositoryName and tagsPerPage should display repository detail page', function() { | ||
$httpBackend.expectGET('repository/repository-detail.html').respond(200); | ||
$location.path('/repository/owner/name/10'); | ||
$rootScope.$digest(); | ||
expect($route.current.templateUrl).toBe('repository/repository-detail.html'); | ||
expect($route.current.controller).toBe('RepositoryDetailController'); | ||
var scope = {}; | ||
$controller('RepositoryDetailController', {$scope: scope}); | ||
expect(scope.repositoryUser).toBe('owner'); | ||
expect(scope.repositoryName).toBe('name'); | ||
expect(scope.repository).toBe('owner/name'); | ||
}); | ||
|
||
// This test currently fails; this URL is incorrectly routing to the home page | ||
// @todo @FIXME | ||
// | ||
// it('URL with repositoryName but no repositoryUser and no tagsPerPage should display repository detail page', function() { | ||
// $httpBackend.expectGET('repository/repository-detail.html').respond(200); | ||
// $location.path('/repository/cx'); | ||
// $rootScope.$digest(); | ||
// expect($route.current.templateUrl).toBe('repository/repository-detail.html'); | ||
// expect($route.current.controller).toBe('RepositoryDetailController'); | ||
// }); | ||
|
||
it('URL with repositoryName but no repositoryUser and tagsPerPage should display repository detail page', function() { | ||
$httpBackend.expectGET('repository/repository-detail.html').respond(200); | ||
$location.path('/repository/cx/10'); | ||
$rootScope.$digest(); | ||
expect($route.current.templateUrl).toBe('repository/repository-detail.html'); | ||
expect($route.current.controller).toBe('RepositoryDetailController'); | ||
var scope = {}; | ||
$controller('RepositoryDetailController', {$scope: scope}); | ||
// expect(scope.repositoryUser).toBeUndefined(); | ||
// expect(scope.repositoryName).toBe('cx'); | ||
// expect(scope.repository).toBe('cx'); | ||
}); | ||
|
||
it('/about should display about page', function() { | ||
$httpBackend.expectGET('about.html').respond(200); | ||
$location.path('/about'); | ||
$rootScope.$digest(); | ||
expect($route.current.templateUrl).toBe('about.html'); | ||
}); | ||
|
||
it('/tag/repositoryUser/repositoryName/latest should display tag detail page', function() { | ||
$httpBackend.expectGET('tag/tag-detail.html').respond(200); | ||
$location.path('/tag/repositoryUser/repositoryName/latest'); | ||
$rootScope.$digest(); | ||
expect($route.current.templateUrl).toBe('tag/tag-detail.html'); | ||
expect($route.current.controller).toBe('TagController'); | ||
var scope = {}; | ||
$controller('TagController', {$scope: scope}); | ||
expect(scope.repositoryUser).toBe('repositoryUser'); | ||
expect(scope.repositoryName).toBe('repositoryName'); | ||
expect(scope.repository).toBe('repositoryUser/repositoryName'); | ||
expect(scope.tagName).toBe('latest'); | ||
}); | ||
|
||
// This test currently fails; this URL is incorrectly routing to the home page | ||
// @todo @FIXME | ||
// | ||
// it('/tag/repositoryName/latest should display tag detail page', function() { | ||
// $httpBackend.expectGET('tag/tag-detail.html').respond(200); | ||
// $location.path('/tag/repositoryName/latest'); | ||
// $rootScope.$digest(); | ||
// expect($route.current.templateUrl).toBe('tag/tag-detail.html'); | ||
// expect($route.current.controller).toBe('TagController'); | ||
// }); | ||
|
||
it('/image/88e37c7099fa should display image detail page', function() { | ||
$httpBackend.expectGET('tag/image-detail.html').respond(200); | ||
$location.path('/image/88e37c7099fa'); | ||
$rootScope.$digest(); | ||
expect($route.current.templateUrl).toBe('tag/image-detail.html'); | ||
expect($route.current.controller).toBe('ImageController'); | ||
}); | ||
|
||
it('/image/88e37c7099fa/tag should display create tag page', function() { | ||
$httpBackend.expectGET('tag/create-tag.html').respond(200); | ||
$location.path('/image/88e37c7099fa/tag'); | ||
$rootScope.$digest(); | ||
expect($route.current.templateUrl).toBe('tag/create-tag.html'); | ||
expect($route.current.controller).toBe('CreateTagController'); | ||
}); | ||
|
||
it('/unknown-url should display home page', function() { | ||
$httpBackend.expectGET('home.html').respond(200); | ||
$location.path('/unknown-url'); | ||
$rootScope.$digest(); | ||
expect($route.current.templateUrl).toBe('home.html'); | ||
expect($route.current.controller).toBe('HomeController'); | ||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
'use strict'; | ||
|
||
describe('RepositoryListController', function() { | ||
|
||
// load the controller's module | ||
beforeEach(module('repository-list-controller')); | ||
|
||
var $controller, $httpBackend, $q, $rootScope; | ||
|
||
beforeEach(inject(function(_$controller_, _$httpBackend_, _$q_, _$rootScope_) { | ||
$controller = _$controller_; | ||
$httpBackend = _$httpBackend_; | ||
$q = _$q_; | ||
$rootScope = _$rootScope_; | ||
})); | ||
|
||
it('should attach some keys to the scope', function() { | ||
var $scope = $rootScope.$new(); | ||
var route = { | ||
'current': { | ||
'params': { | ||
'lastNamespace': 'lastNamespace', | ||
'lastRepository': 'lastRepository', | ||
'reposPerPage': 10 | ||
} | ||
} | ||
}; | ||
|
||
var mockRepositoryReturnValue = { | ||
repos: [{username: 'username', name: 'name', selected: true}], | ||
lastNamespace: 'lastNamespace', | ||
lastRepository: 'lastRepository' | ||
}; | ||
var mockRepository = {query: null}; | ||
spyOn(mockRepository, 'query').and.returnValue({$promise: $q.when(mockRepositoryReturnValue)}); | ||
|
||
var expectedAppMode = {"browseOnly": true, "defaultRepositoriesPerPage": 20, "defaultTagsPerPage": 10}; | ||
$httpBackend.expectGET('/app-mode.json').respond(expectedAppMode); | ||
var ctrl = $controller('RepositoryListController', {$scope: $scope, $route: route, Repository: mockRepository}); | ||
$httpBackend.flush(); | ||
expect($scope.reposPerPage).toBe(10); | ||
expect($scope.lastNamespace).toEqual('lastNamespace'); | ||
expect($scope.lastRepository).toEqual('lastRepository'); | ||
expect($scope.selectedRepositories).toEqual(['name']); | ||
expect(mockRepository.query).toHaveBeenCalled(); | ||
expect($scope.repositories).toEqual(mockRepositoryReturnValue); | ||
}); | ||
}); | ||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 Maybe this is a dump question but how can I trigger this
test-single-run
? Justnpm test-single-run
won't work. As you can see here, travis will stuck after a while when runningnpm test
. I know that this is normal and that it allows me open various browsers to run my tests.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
(noterun
in there).npm test
is a special case, but in general you need to usenpm run
(ornpm run-script
) to execute thescripts
that you define inpackage.json
.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 inpretest
you do annpm 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
donpm 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 donpm install
for theinstall
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 ascript
for that, liketest-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
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.
From #146:
Awesome!