Skip to content

Commit fc49b45

Browse files
committed
adding unit testing hooks, connect server, jshint, watch tasks and livereload
1 parent d4efc6f commit fc49b45

6 files changed

Lines changed: 189 additions & 2 deletions

File tree

Gruntfile.js

Lines changed: 106 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
module.exports = function(grunt) {
2-
32
"use strict";
43

5-
require('load-grunt-tasks')(grunt);
4+
require("load-grunt-tasks")(grunt);
65

76
grunt.initConfig({
87

@@ -62,10 +61,115 @@ module.exports = function(grunt) {
6261
dest: "template/material/"
6362
}
6463

64+
},
65+
66+
connect: {
67+
options: {
68+
port: 8040,
69+
hostname: "localhost",
70+
livereload: 35740,
71+
keepalive: true
72+
73+
},
74+
livereload: {
75+
options: {
76+
open: true,
77+
base: "."
78+
}
79+
},
80+
test: {
81+
options: {
82+
port: 8041,
83+
open: 'http://localhost:8041/SpecRunner.html',
84+
base: [
85+
"scripts",
86+
"test"
87+
]
88+
}
89+
}
90+
},
91+
92+
jasmine: {
93+
src: 'scripts/**/*.js',
94+
options: {
95+
specs: 'test/*Spec.js',
96+
helpers: 'test/*Helper.js',
97+
vendor: [
98+
'https://code.jquery.com/jquery-1.10.2.min.js',
99+
'https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js'
100+
]
101+
}
102+
},
103+
104+
jshint: {
105+
options: {
106+
jshintrc: ".jshintrc",
107+
reporter: require("jshint-stylish")
108+
},
109+
all: [
110+
"Gruntfile.js",
111+
"scripts/**/*.js",
112+
"template/**/*.js",
113+
"test/**/*.js"
114+
],
115+
test: {
116+
options: {
117+
jshintrc: "test/.jshintrc",
118+
src: ["test/**/*.js"]
119+
}
120+
}
121+
},
122+
123+
watch: {
124+
js: {
125+
files: ["Gruntfile.js", "scripts/**/*.js", "template/**/*.js"],
126+
tasks: ["newer:jshint:all"]
127+
},
128+
jsTest: {
129+
files: ["test/**/*.js"],
130+
tasks: ["newer:jshint:test", "jasmine"]
131+
},
132+
livereload: {
133+
options: {
134+
livereload: "<%= connect.options.livereload %>"
135+
},
136+
files: [
137+
'index.html',
138+
'css-compiled/**/*.css',
139+
'**/*.{png,jpg,jpeg,gif,webp,svg}'
140+
]
141+
}
65142
}
66143

67144
});
68145

69146
grunt.registerTask("default", ["less", "autoprefixer", "cssmin", "copy"]);
147+
70148
grunt.registerTask("scss", ["sass", "autoprefixer", "cssmin", "copy"]);
149+
150+
grunt.registerTask("build", function(target) {
151+
var buildType = "default";
152+
if (target && target === "scss") {
153+
buildType = "scss";
154+
}
155+
156+
grunt.task.run(["newer:jshint", "test", buildType]);
157+
});
158+
159+
grunt.registerTask("test", [
160+
"connect:test",
161+
"jasmine"
162+
]);
163+
164+
grunt.registerTask("serve", function(target){
165+
var buildTarget = "default";
166+
if(target && target === "scss") {
167+
buildTarget = "scss";
168+
}
169+
grunt.task.run([
170+
"build:"+ buildTarget,
171+
"connect:livereload",
172+
"watch"
173+
])
174+
});
71175
};

package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,15 @@
1919
"devDependencies": {
2020
"grunt": "^0.4.5",
2121
"grunt-autoprefixer": "^1.0.1",
22+
"grunt-contrib-connect": "^0.8.0",
2223
"grunt-contrib-copy": "^0.6.0",
2324
"grunt-contrib-cssmin": "^0.10.0",
25+
"grunt-contrib-jasmine": "^0.8.0",
26+
"grunt-contrib-jshint": "^0.10.0",
2427
"grunt-contrib-less": "^0.11.4",
2528
"grunt-contrib-sass": "^0.8.1",
29+
"grunt-contrib-watch": "^0.6.1",
30+
"jshint-stylish": "^1.0.0",
2631
"load-grunt-tasks": "^0.6.0"
2732
}
2833
}

test/.jshintrc

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
{
2+
"bitwise": true,
3+
"camelcase": true,
4+
"curly": true,
5+
"eqeqeq": false,
6+
"es3": false,
7+
"forin": true,
8+
"freeze": false,
9+
"immed": true,
10+
"indent": 4,
11+
"latedef": true,
12+
"newcap": true,
13+
"noarg": true,
14+
"noempty": true,
15+
"nonbsp": true,
16+
"nonew": true,
17+
"plusplus": false,
18+
"quotmark": "double",
19+
"undef": true,
20+
"unused": true,
21+
"strict": false,
22+
"trailing": true,
23+
"maxparams": 5,
24+
"maxdepth": 5,
25+
"maxstatements": 50,
26+
"maxlen": 150,
27+
28+
"eqnull": true,
29+
30+
"browser": false,
31+
"devel": false,
32+
"node": true,
33+
34+
"white": true,
35+
36+
"globals": {
37+
"$": true,
38+
"document": true,
39+
"brackets": true,
40+
"define": true,
41+
"Mustache": true,
42+
"window": true
43+
}
44+
}

test/SpecRunner.html

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<!DOCTYPE HTML>
2+
<html>
3+
<head>
4+
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
5+
<title>Unit Tests Bootstrap Material Design</title>
6+
7+
<link rel="shortcut icon" type="image/png" href="lib/jasmine-2.0.3/jasmine_favicon.png">
8+
<link rel="stylesheet" type="text/css" href="lib/jasmine-2.0.3/jasmine.css">
9+
10+
<script type="text/javascript" src="lib/jasmine-2.0.3/jasmine.js"></script>
11+
<script type="text/javascript" src="lib/jasmine-2.0.3/jasmine-html.js"></script>
12+
<script type="text/javascript" src="lib/jasmine-2.0.3/boot.js"></script>
13+
14+
<!-- include source files here... -->
15+
<script type="text/javascript" src="src/Player.js"></script>
16+
<script type="text/javascript" src="src/Song.js"></script>
17+
18+
<!-- include spec files here... -->
19+
<script type="text/javascript" src="spec/SpecHelper.js"></script>
20+
<script type="text/javascript" src="spec/PlayerSpec.js"></script>
21+
22+
</head>
23+
24+
<body>
25+
</body>
26+
</html>

test/materialSpec.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
'use strict';
2+
3+
describe('Material', function (){
4+
5+
it('jquery should be loaded', function () {
6+
expect($).toBeDefined();
7+
});
8+
});

test/ripplesSpec.js

Whitespace-only changes.

0 commit comments

Comments
 (0)