Skip to content

Commit b916c7b

Browse files
committed
Merge pull request #49 from joshleeb/master
Increased testing ability
2 parents 8ee626a + fbdd36c commit b916c7b

File tree

6 files changed

+131
-112
lines changed

6 files changed

+131
-112
lines changed

Gruntfile.js

Lines changed: 67 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,77 @@
99
'use strict';
1010

1111
module.exports = function (grunt) {
12-
// Load grunt tasks automatically
13-
require('load-grunt-tasks')(grunt);
14-
1512
grunt.initConfig({
13+
jshint: {
14+
options: {
15+
reporter: require('jshint-stylish'),
16+
jasmine: true,
17+
node: true,
18+
mocha: true,
19+
predef: ['after', 'afterEach', 'angular', 'before', 'beforeEach',
20+
'describe', 'expect', 'inject', 'it', 'jasmine', 'spyOn',
21+
'xdescribe', 'xit']
22+
},
23+
files: [
24+
'Gruntfile.js',
25+
'src/**/*.js',
26+
'test/**/*.js'
27+
]
28+
},
29+
1630
karma: {
31+
options: {
32+
configFile: 'karma.conf.js'
33+
},
1734
unit: {
18-
configFile: 'karma.conf.js',
35+
browsers: ['PhantomJS'],
36+
reporters: ['mocha'],
37+
autoWatch: false,
38+
singleRun: true
39+
},
40+
dev: {
41+
browsers: ['PhantomJS'],
42+
reporters: ['mocha'],
43+
autoWatch: true,
44+
singleRun: false
45+
},
46+
release: {
47+
browsers: ['PhantomJS', 'Chrome', 'Firefox'],
48+
reporters: ['mocha'],
49+
autoWatch: false,
50+
singleRun: true
51+
},
52+
coverage: {
53+
browsers: ['PhantomJS'],
54+
reporters: ['coverage'],
55+
autoWatch: false,
1956
singleRun: true
2057
}
2158
},
59+
2260
clean: {
23-
dist: { src: 'dist', dot: true },
24-
lib: { src: 'example/lib', dot: true },
25-
bower: { src: 'bower_components', dot: true }
61+
dist: {
62+
src: 'dist',
63+
dot: true
64+
},
65+
lib: {
66+
src: 'example/lib',
67+
dot: true
68+
},
69+
bower: {
70+
src: 'bower_components',
71+
dot: true
72+
}
2673
},
74+
2775
bower: {
28-
install: { options: { targetDir: 'example/lib' } }
76+
install: {
77+
options: {
78+
targetDir: 'example/lib'
79+
}
80+
}
2981
},
82+
3083
cssmin: {
3184
dist: {
3285
expand: true,
@@ -35,7 +88,9 @@ module.exports = function (grunt) {
3588
'dist/autocomplete.min.css': 'src/autocomplete.css'
3689
}
3790
}
91+
3892
},
93+
3994
uglify: {
4095
dist: {
4196
files: {
@@ -45,16 +100,15 @@ module.exports = function (grunt) {
45100
}
46101
});
47102

48-
grunt.registerTask('test', [
49-
'karma'
50-
]);
103+
require('load-grunt-tasks')(grunt);
51104

105+
grunt.registerTask('default', ['build']);
106+
grunt.registerTask('test', ['karma:unit']);
52107
grunt.registerTask('build', [
108+
'jshint',
53109
'clean',
54110
'bower',
55111
'cssmin',
56112
'uglify'
57113
]);
58-
59-
grunt.registerTask('default', ['build']);
60114
};

karma.conf.js

Lines changed: 26 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,27 @@
1-
/*
2-
* angular-google-places-autocomplete
3-
*
4-
* Copyright (c) 2014 "kuhnza" David Kuhn
5-
* Licensed under the MIT license.
6-
* https://github.com/kuhnza/angular-google-places-autocomplete/blob/master/LICENSE
7-
*/
8-
9-
'use strict';
10-
11-
module.exports = function (config) {
12-
config.set({
13-
basePath: '',
14-
frameworks: ['jasmine'],
15-
logLevel: 'INFO',
16-
browsers: ['PhantomJS'],
17-
autoWatch: true,
18-
reporters: ['progress', 'coverage'],
19-
files: [
20-
'https://maps.googleapis.com/maps/api/js?libraries=places',
21-
'bower_components/angular/angular.js',
22-
'bower_components/angular-mocks/angular-mocks.js',
23-
'src/**/*.js',
24-
'test/**/*.js'
25-
],
26-
preprocessors: {
27-
'src/**/*.js': 'coverage'
28-
},
29-
coverageReporter: {
30-
type: 'html',
31-
dir: 'coverage/'
32-
}
33-
});
1+
module.exports = function(config) {
2+
config.set({
3+
basePath: '',
4+
frameworks: ['jasmine'],
5+
files: [
6+
'bower_components/angular/angular.js',
7+
'bower_components/angular-mocks/angular-mocks.js',
8+
'src/**/*.js',
9+
'spec/**/*.js'
10+
],
11+
exclude: [],
12+
preprocessors: {
13+
'src/**/*.js': 'coverage'
14+
},
15+
port: 9876,
16+
colors: true,
17+
logLevel: config.LOG_INFO,
18+
coverageReporter: {
19+
dir: 'spec/coverage/',
20+
includeAllSources: true,
21+
reporters: [
22+
{ type: 'html', subdir: '.'},
23+
{ type: 'json', subdir: '.', file: 'coverage.json' }
24+
]
25+
}
26+
});
3427
};

package.json

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,20 @@
1010
},
1111
"devDependencies": {
1212
"grunt": "~0.4.1",
13-
"load-grunt-tasks": "0.4.0",
13+
"grunt-bower-task": "^0.4.0",
14+
"grunt-contrib-clean": "^0.5.0",
15+
"grunt-contrib-jshint": "^0.11.2",
1416
"grunt-contrib-uglify": "~0.4.0",
15-
"grunt-contrib-jshint": "~0.10.0",
16-
"grunt-karma": "~0.8.2",
17-
"karma": "~0.12.0",
18-
"karma-coverage": "~0.2.0",
17+
"grunt-karma": "~0.11.0",
18+
"jshint-stylish": "^2.0.1",
19+
"karma": "0.12.0",
20+
"karma-chrome-launcher": "~0.1.2",
21+
"karma-coverage": "^0.5.0",
22+
"karma-firefox-launcher": "~0.1.3",
1923
"karma-jasmine": "~0.2.1",
24+
"karma-mocha-reporter": "^1.1.1",
2025
"karma-phantomjs-launcher": "~0.1.1",
21-
"grunt-contrib-clean": "^0.5.0",
22-
"grunt-bower-task": "^0.4.0"
26+
"load-grunt-tasks": "0.4.0"
2327
},
2428
"engines": {
2529
"node": ">=0.10.0"

test/autocomplete-test.js renamed to spec/autocomplete_spec.js

Lines changed: 6 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66
* https://github.com/kuhnza/angular-google-places-autocomplete/blob/master/LICENSE
77
*/
88

9-
'use strict';
10-
9+
"use strict";
1110

1211
// Sample set of AutocompleteService predictions
1312
var PREDICTIONS = [
@@ -168,13 +167,10 @@ var PREDICTIONS = [
168167
}
169168
];
170169

171-
172170
describe('Factory: googlePlacesApi', function () {
173-
174171
var googlePlacesApi;
175172

176173
beforeEach(module('google.places'));
177-
178174
beforeEach(inject(function (_$window_, _googlePlacesApi_) {
179175
googlePlacesApi = _googlePlacesApi_;
180176
}));
@@ -184,9 +180,7 @@ describe('Factory: googlePlacesApi', function () {
184180
});
185181
});
186182

187-
188183
describe('Directive: gPlacesAutocomplete', function () {
189-
190184
var $parentScope, $isolatedScope, $compile, googlePlacesApi;
191185

192186
function compileAndDigest(html) {
@@ -197,13 +191,10 @@ describe('Directive: gPlacesAutocomplete', function () {
197191
}
198192

199193
beforeEach(module('google.places'));
200-
201194
beforeEach(inject(function ($rootScope, _$compile_) {
202195
$parentScope = $rootScope.$new();
203196
$compile = _$compile_;
204-
205197
$parentScope.place = null;
206-
207198
compileAndDigest('<input type="text" g-places-autocomplete ng-model="place" />');
208199
}));
209200

@@ -212,11 +203,8 @@ describe('Directive: gPlacesAutocomplete', function () {
212203
});
213204
});
214205

215-
216206
describe('Directive: gPlacesAutocompleteDrawer', function () {
217-
218207
var $parentScope, $isolatedScope, $compile, element;
219-
220208
var template = '<div g-places-autocomplete-drawer input="input" query="query" predictions="predictions" active="active" selected="selected"></div>';
221209

222210
function compileAndDigest(html) {
@@ -227,19 +215,15 @@ describe('Directive: gPlacesAutocompleteDrawer', function () {
227215
}
228216

229217
beforeEach(module('google.places'));
230-
231218
beforeEach(inject(function ($rootScope, _$compile_) {
232219
$parentScope = $rootScope.$new();
233220
$compile = _$compile_;
234-
235221
$parentScope.input = angular.element('<input type="text"/>');
236222
$parentScope.query = '';
237223
$parentScope.predictions = [];
238224
}));
239225

240-
241226
describe('when there are no predictions', function () {
242-
243227
beforeEach(function () {
244228
compileAndDigest(template);
245229
});
@@ -250,14 +234,11 @@ describe('Directive: gPlacesAutocompleteDrawer', function () {
250234
});
251235

252236
describe('when there are predictions', function () {
253-
254237
var predictionElements;
255238

256239
beforeEach(function () {
257240
$parentScope.predictions = angular.copy(PREDICTIONS);
258-
259241
compileAndDigest(template);
260-
261242
predictionElements = element.children().children();
262243
});
263244

@@ -284,12 +265,10 @@ describe('Directive: gPlacesAutocompleteDrawer', function () {
284265
it('should set the drawer position', function () {
285266
expect($isolatedScope.position).toBeDefined();
286267
});
287-
})
268+
});
288269
});
289270

290-
291271
describe('Directive: gPlacesAutocompletePrediction', function () {
292-
293272
var $parentScope, $isolatedScope, $compile;
294273

295274
function compileAndDigest(html) {
@@ -304,11 +283,9 @@ describe('Directive: gPlacesAutocompletePrediction', function () {
304283
beforeEach(inject(function ($rootScope, _$compile_) {
305284
$parentScope = $rootScope.$new();
306285
$compile = _$compile_;
307-
308286
$parentScope.$index = 0;
309287
$parentScope.prediction = angular.copy(PREDICTIONS[0]);
310288
$parentScope.query = '18';
311-
312289
compileAndDigest('<div g-places-autocomplete-prediction index="$index" prediction="prediction" query="query"></div>');
313290
}));
314291

@@ -317,46 +294,30 @@ describe('Directive: gPlacesAutocompletePrediction', function () {
317294
});
318295
});
319296

320-
321297
describe('Filter: unmatchedTermsOnly', function () {
322-
323298
var unmatchedTermsOnlyFilter;
324299

325300
beforeEach(module('google.places'));
326-
327301
beforeEach(inject(function (_unmatchedTermsOnlyFilter_) {
328302
unmatchedTermsOnlyFilter = _unmatchedTermsOnlyFilter_;
329303
}));
330304

331305
it('should only return unmatched terms for a prediction', function () {
332306
var prediction = angular.copy(PREDICTIONS[0]);
333-
334307
var result = unmatchedTermsOnlyFilter(prediction.terms, prediction);
335308

336309
expect(result).toEqual([
337-
{
338-
"offset": 21,
339-
"value": "Waterloo"
340-
},
341-
{
342-
"offset": 31,
343-
"value": "New South Wales"
344-
},
345-
{
346-
"offset": 48,
347-
"value": "Australia"
348-
}
310+
{ "offset": 21, "value": "Waterloo" },
311+
{ "offset": 31, "value": "New South Wales" },
312+
{ "offset": 48, "value": "Australia" }
349313
]);
350314
});
351315
});
352316

353-
354317
describe('Filter: trailingComma', function () {
355-
356318
var trailingCommaFilter;
357319

358320
beforeEach(module('google.places'));
359-
360321
beforeEach(inject(function (_trailingCommaFilter_) {
361322
trailingCommaFilter = _trailingCommaFilter_;
362323
}));
@@ -372,4 +333,4 @@ describe('Filter: trailingComma', function () {
372333

373334
expect(result).toEqual('a string');
374335
});
375-
});
336+
});

spec/support/jasmine.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"spec_dir": "spec",
3+
"spec_files": [
4+
"**/*[sS]pec.js"
5+
],
6+
"helpers": [
7+
"helpers/**/*.js"
8+
]
9+
}

0 commit comments

Comments
 (0)