Skip to content

Commit 04acc30

Browse files
author
aniaw
committed
update unit test, npm packages, clean
1 parent b598b40 commit 04acc30

11 files changed

Lines changed: 187 additions & 221 deletions

File tree

.bowerrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"directory": "app/bower_components"
3+
}

.jshintrc

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@
1919
"trailing": true,
2020
"smarttabs": true,
2121
"globals": {
22-
"angular": true
22+
"angular": true,
23+
"describe": true,
24+
"it": true,
25+
"expect": true,
26+
"module": true,
27+
"inject": true,
28+
"beforeEach": true
2329
}
2430
}

Gruntfile.js

Lines changed: 72 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,93 @@
11
/*jshint camelcase:false*/
2-
'use strict';
3-
4-
// # Globbing
5-
// for performance reasons we're only matching one level down:
6-
// 'test/spec/{,*/}*.js'
7-
// use this if you want to recursively match all subfolders:
8-
// 'test/spec/**/*.js'
92

103
module.exports = function (grunt)
114
{
5+
'use strict';
126

137
grunt.loadNpmTasks('grunt-contrib-watch');
148
grunt.loadNpmTasks('grunt-contrib-connect');
9+
grunt.loadNpmTasks('grunt-contrib-jshint');
1510
grunt.loadNpmTasks('grunt-karma');
1611

12+
require('load-grunt-tasks')(grunt);
13+
14+
1715
var config = {
1816
app: 'app'
1917
};
2018

2119
grunt.initConfig({
22-
config: config, watch: {
23-
livereload: {
24-
options: {
25-
livereload: '<%= connect.options.livereload %>'
26-
}, files: ['<%= config.app %>/**/*.html', '<%= config.app %>/**/*.js']
27-
}
28-
}, connect: {
29-
options: {
30-
port: 9000, livereload: 35729, hostname: 'localhost'
31-
}, livereload: {
32-
options: {
33-
open: true, middleware: function (connect)
34-
{
35-
return [connect().use('/bower_components', connect.static('./bower_components')), connect.static(config.app)
36-
37-
];
20+
config: config,
21+
watch: {
22+
livereload: {
23+
options: {
24+
livereload: '<%= connect.options.livereload %>'
25+
},
26+
files: ['<%= config.app %>/**/*.html', '<%= config.app %>/**/*.js']
27+
}
28+
},
29+
30+
connect: {
31+
options: {
32+
port: 9000,
33+
livereload: 35729,
34+
hostname: '127.0.0.1'
35+
},
36+
test: {
37+
options: {
38+
base: ['app'],
39+
port: 9001
40+
}
41+
},
42+
livereload: {
43+
options: {
44+
open: true,
45+
middleware: function (connect)
46+
{
47+
return [connect().use('/bower_components', connect.static('./bower_components')), connect.static(config.app)
48+
49+
];
50+
}
51+
}
52+
}
53+
},
54+
karma: {
55+
options: {
56+
configFile: 'test/karma.conf.js'
57+
},
58+
unit: {
59+
singleRun: true
60+
},
61+
dev: {
62+
singleRun: false
63+
}
64+
},
65+
jshint: {
66+
default: {
67+
options: {
68+
jshintrc: true
69+
},
70+
files: {
71+
src: ['app/**/*.js', 'test/**/*.js', '!app/bower_components/**/*.js']
72+
}
73+
},
74+
verify: {
75+
options: {
76+
jshintrc: true,
77+
reporter: 'checkstyle',
78+
reporterOutput: 'target/jshint.xml'
79+
},
80+
files: {src: ['app/**/*.js', 'test/**/*.js', '!app/bower_components/**/*.js']}
3881
}
3982
}
4083
}
41-
},
42-
karma: {
43-
unit: {
44-
configFile: 'test/karma.conf.js'
45-
}
46-
}
47-
});
84+
);
85+
86+
grunt.registerTask('serve', ['connect:livereload', 'watch']);
87+
88+
grunt.registerTask('verify', ['jshint:verify', 'karma:unit']);
4889

49-
grunt.registerTask('serve', function ()
50-
{
51-
grunt.task.run(['connect:livereload', 'watch']);
52-
});
90+
grunt.registerTask('test:dev', ['karma:dev']);
5391

5492
grunt.registerTask('default', ['serve']);
5593
};

app/BlogPostCtrl.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,5 @@
66

77
}
88

9-
var module = angular.module("exerciseApp", []);
10-
module.controller('BlogPostCtrl', [BlogPostCtrl]);
9+
angular.module('app', []).controller('BlogPostCtrl', [BlogPostCtrl]);
1110
})();

app/index.html

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,31 @@
11
<!DOCTYPE html>
2-
<html ng-app="exerciseApp">
2+
<html ng-app="app">
33
<head lang="en">
44
<meta charset="UTF-8">
55
<title>Angular Exercise 1</title>
66
<link rel="stylesheet" href="bower_components/bootstrap/dist/css/bootstrap.min.css">
77
</head>
8-
<body class="container">
9-
<div ng-controller="BlogPostCtrl as blogPosts">
10-
<table class="table table-striped table-bordered">
11-
<thead>
12-
<tr>
13-
<th>ID</th>
14-
<th>Author</th>
15-
<th>Title</th>
16-
</tr>
17-
</thead>
18-
<tbody>
19-
<tr>
20-
<th></th>
21-
<th></th>
22-
<th></th>
23-
</tr>
24-
</tbody>
25-
</table>
8+
<body>
9+
<div ng-controller="BlogPostCtrl as blogPost">
10+
<div class="container">
11+
<h2 class="page-header">ng-repeat exercise</h2>
12+
<table class="table table-striped table-bordered">
13+
<thead>
14+
<tr>
15+
<th>ID</th>
16+
<th>Author</th>
17+
<th>Title</th>
18+
</tr>
19+
</thead>
20+
<tbody>
21+
<tr>
22+
<th></th>
23+
<th></th>
24+
<th></th>
25+
</tr>
26+
</tbody>
27+
</table>
28+
</div>
2629
</div>
2730

2831
<script src="bower_components/angular/angular.js"></script>

bower.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@
55
"angular": "1.2.16",
66
"angular-resource": "1.2.16",
77
"bootstrap": "3.1.1"
8-
},
8+
},
99
"devDependencies": {
1010
"angular-mocks": "1.2.16"
11-
},
12-
"appPath": "app"
11+
}
1312
}

package.json

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
{
22
"name": "angular-exercises",
3-
"description": "Angular training",
3+
"description": "angular training",
44
"version": "0.0.0",
5+
"repository": "https://github.com/Real-Skill/angular-exercises.git",
56
"dependencies": {},
67
"devDependencies": {
7-
"grunt": "0.4.2",
8-
"grunt-contrib-jshint": "0.8.0",
9-
"grunt-contrib-watch": "0.6.1",
8+
"grunt": "0.4.5",
9+
"grunt-cli": "0.1.13",
1010
"grunt-contrib-connect": "0.7.1",
11-
"grunt-karma": "0.9.0",
12-
"karma-phantomjs-launcher": "0.1.4",
13-
"karma": "0.12.16",
14-
"karma-coverage": "0.2.4",
15-
"karma-jasmine": "0.1.5",
16-
"karma-spec-reporter": "0.0.13"
17-
},
18-
"engines": {
19-
"node": ">=0.10.0"
11+
"grunt-contrib-jshint": "0.11.3",
12+
"grunt-contrib-watch": "0.6.1",
13+
"grunt-karma": "2.0.0",
14+
"karma": "1.4.1",
15+
"karma-chrome-launcher": "0.1.4",
16+
"karma-coverage": "0.3.1",
17+
"karma-jasmine": "1.1.0",
18+
"karma-junit-reporter": "0.2.2",
19+
"karma-spec-reporter": "0.0.13",
20+
"load-grunt-tasks": "0.4.0"
2021
},
21-
"repository": {
22-
"type": "git",
23-
"url": "https://github.com/aniaw/angular-exercises.git"
22+
"scripts": {
23+
"test": "grunt verify --force"
2424
}
2525
}

test/.jshintrc

Lines changed: 0 additions & 44 deletions
This file was deleted.

test/karma.conf.js

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
/*global module*/
2-
module.exports = function (config) {
1+
module.exports = function (config)
2+
{
33
'use strict';
44

55
config.set({
@@ -13,26 +13,31 @@ module.exports = function (config) {
1313
frameworks: ['jasmine'],
1414

1515
// list of files / patterns to load in the browser
16-
files: [
17-
'bower_components/angular/angular.js',
18-
'bower_components/angular-mocks/angular-mocks.js',
19-
'app/**/*.js', 'test/spec/**/*.js'
20-
],
16+
files: ['app/bower_components/angular/angular.js',
17+
'app/bower_components/angular-mocks/angular-mocks.js',
18+
'app/*.js',
19+
'app/!(bower_components)/**/*.js',
20+
'test/unit/**/*.spec.js'],
2121

2222
// list of files / patterns to exclude
2323
exclude: [],
2424

25-
// test results reporter to use
26-
// possible values: 'dots', 'progress', 'junit', 'growl', 'coverage'
27-
reporters: ['spec', 'coverage'],
25+
reporters: ['spec', 'coverage', 'junit'],
2826

2927
preprocessors: {
30-
'app/**/*.js': 'coverage'
28+
'app/*.js': 'coverage',
29+
'app/!(bower_components)/**/*.js': 'coverage'
3130
},
3231

3332
coverageReporter: {
34-
dir: 'target/coverage/',
35-
type: 'html'
33+
dir: 'target/',
34+
type: 'cobertura',
35+
file: 'coverage.xml'
36+
},
37+
38+
39+
junitReporter: {
40+
outputFile: 'target/test-results.xml'
3641
},
3742

3843
// web server port
@@ -46,18 +51,14 @@ module.exports = function (config) {
4651
// - Safari (only Mac)
4752
// - PhantomJS
4853
// - IE (only Windows)
49-
browsers: [
50-
'PhantomJS'
51-
],
54+
browsers: ['PhantomJS'],
5255

5356
// Which plugins to enable
54-
plugins: [
55-
'karma-phantomjs-launcher', 'karma-coverage', 'karma-jasmine', 'karma-spec-reporter'
56-
],
57+
plugins: ['karma-phantomjs-launcher', 'karma-jasmine', 'karma-spec-reporter', 'karma-junit-reporter', 'karma-coverage'],
5758

5859
// Continuous Integration mode
5960
// if true, it capture browsers, run tests and exit
60-
singleRun: false,
61+
singleRun: true,
6162

6263
colors: true,
6364

@@ -67,7 +68,6 @@ module.exports = function (config) {
6768

6869
//https://github.com/karma-runner/karma/issues/895
6970
usePolling: true
70-
7171
// Uncomment the following lines if you are using grunt's server to run the tests
7272
// proxies: {
7373
// '/': 'http://localhost:9000/'

0 commit comments

Comments
 (0)