Skip to content

Commit b4ffc75

Browse files
authored
upgrade to grunt-contrib-jasmine 1.x (#2724)
* move to latest grunt-contrib-jasmine, adding a shim to declare globals now that phantomjs implements strict mode * collapse the two jasmine spec helpers into one * remove non-existent promise-polyfill.js test helper * remove arraybuffer-slice dependency, no longer needed by phantomjs * make all the test helpers and shims into vendor
1 parent 23d299d commit b4ffc75

File tree

4 files changed

+29
-29
lines changed

4 files changed

+29
-29
lines changed

Gruntfile.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -890,7 +890,9 @@ module.exports = function(grunt) {
890890
},
891891
//-------------------------------------------------------------------------
892892
jasmine: {
893-
chrome_extension: Rule.jasmineSpec('chrome/extension/scripts/', [path.join('build/src/mocks/chrome_mocks.js')])
893+
chrome_core_connector: Rule.jasmineSpec('chrome/extension/scripts/chrome_core_connector', [
894+
path.join('build/src/mocks/chrome_mocks.js')
895+
])
894896
},
895897
jasmine_chromeapp: {
896898
all: {
@@ -1177,7 +1179,7 @@ module.exports = function(grunt) {
11771179
grunt.registerTask('test_chrome', [
11781180
'build_chrome',
11791181
'browserify:chromeExtensionCoreConnectorSpec',
1180-
'jasmine:chrome_extension'
1182+
'jasmine:chrome_core_connector'
11811183
]);
11821184
grunt.registerTask('tcpIntegrationTestModule', [
11831185
'base',

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
}
2222
],
2323
"devDependencies": {
24-
"arraybuffer-slice": "^0.1.2",
2524
"bower": "^1.4.1",
2625
"browserify-zlib": "^0.1.4",
2726
"cca": "^0.8.0",
@@ -47,7 +46,7 @@
4746
"grunt-cli": "^0.1.13",
4847
"grunt-contrib-clean": "^0.6.0",
4948
"grunt-contrib-copy": "^0.8.0",
50-
"grunt-contrib-jasmine": "^0.9.0",
49+
"grunt-contrib-jasmine": "^1.0.3",
5150
"grunt-contrib-jshint": "^1.0.0",
5251
"grunt-contrib-symlink": "^0.3.0",
5352
"grunt-contrib-watch": "^1.0.0",

src/lib/build-tools/common-grunt-rules.ts

Lines changed: 14 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@ export interface RuleConfig {
1717
}
1818

1919
export interface JasmineRule {
20-
src :string[];
20+
src ?:string[];
2121
options ?:{
22+
vendor ?:string|string[];
2223
specs :string[];
2324
outfile ?:string;
2425
keepRunner ?:boolean;
@@ -78,39 +79,27 @@ export class Rule {
7879
return spec;
7980
}
8081

81-
// Grunt Jasmine target creator
82-
// Assumes that the each spec file is a fully browserified js file.
82+
// grunt-contrib-jasmine target creator. Assumes that the spec
83+
// is browserified, i.e. has a .spec.static.js suffix.
8384
public jasmineSpec(name:string, morefiles?:string[]) :JasmineRule {
8485
if (!morefiles) { morefiles = []; }
8586
return {
86-
src: [
87-
require.resolve('arraybuffer-slice'),
88-
require.resolve('es6-promise'),
89-
path.join(this.config.thirdPartyBuildPath, 'promise-polyfill.js'),
90-
].concat(morefiles),
9187
options: {
92-
specs: [ path.join(this.config.devBuildPath, name, '/**/*.spec.static.js') ],
88+
vendor: [
89+
// phantomjs does not yet understand Promises natively:
90+
// https://github.com/ariya/phantomjs/issues/14166
91+
require.resolve('es6-promise'),
92+
// Declares globals, notably freedom, without which test
93+
// environments implementing strict mode will fail.
94+
'./src/lib/build-tools/testing/globals.js'
95+
].concat(morefiles),
96+
specs: [ path.join(this.config.devBuildPath, name + '.spec.static.js') ],
9397
outfile: path.join(this.config.devBuildPath, name, '/SpecRunner.html'),
9498
keepRunner: true
9599
}
96100
}
97101
}
98102

99-
public jasmineSingleSpec(file :string) :JasmineRule {
100-
return {
101-
src: [
102-
require.resolve('arraybuffer-slice'),
103-
require.resolve('es6-promise'),
104-
path.join(this.config.thirdPartyBuildPath, 'promise-polyfill.js'),
105-
],
106-
options: {
107-
specs: [ path.join(this.config.devBuildPath, file + '.spec.static.js') ],
108-
outfile: path.join(this.config.devBuildPath, file, '/SpecRunner.html'),
109-
keepRunner: true
110-
}
111-
}
112-
}
113-
114103
// Grunt browserify target creator
115104
public browserify(filepath:string, options = {
116105
browserifyOptions: {
@@ -253,7 +242,7 @@ export class Rule {
253242
public buildAndRunTest(test :string, grunt :any, coverage?:boolean) :string[] {
254243
var name = test + 'Spec';
255244
var browserifyRule = this.browserifySpec(test);
256-
var jasmineRule = this.jasmineSingleSpec(test);
245+
var jasmineRule = this.jasmineSpec(test);
257246

258247
if (coverage) {
259248
name += 'Cov';
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Include this file to avoid ECMAScript 5 strict mode errors
2+
// related to creation of global objects, in particular freedom.js
3+
// in unit tests - while neither the Chrome nor Firefox extension
4+
// environments implement strict mode, recent versions of phantomjs
5+
// (used by jasmine), do as of course do Chrome and Firefox when
6+
// loading and debugging the SpecRunner manually.
7+
8+
// There are a bunch of helpers under src/freedom/mocks which can
9+
// inject behaviour into this object.
10+
var freedom = {};

0 commit comments

Comments
 (0)