Skip to content
This repository was archived by the owner on Feb 26, 2024. It is now read-only.

Commit 639d5e7

Browse files
committed
feat(jasmine): export the jasmine patch
1 parent 95c9dc2 commit 639d5e7

10 files changed

+143
-43
lines changed

Diff for: dist/jasmine-patch.js

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
2+
var jasminePatch = require('../jasmine/patch');
3+
4+
jasminePatch.apply();
5+
6+
},{"../jasmine/patch":2}],2:[function(require,module,exports){
7+
(function (global){
8+
'use strict';
9+
// Patch jasmine's it and fit functions so that the `done` callback always resets the zone
10+
// to the jasmine zone, which should be the root zone. (angular/zone.js#91)
11+
12+
function apply() {
13+
if (!global.zone) {
14+
throw new Error('zone.js does not seem to be installed');
15+
}
16+
17+
if (!global.zone.isRootZone()) {
18+
throw new Error('The jasmine patch should be called from the root zone');
19+
}
20+
21+
var jasmineZone = global.zone;
22+
var originalIt = global.it;
23+
var originalFit = global.fit;
24+
25+
global.it = function zoneResettingIt(description, specFn) {
26+
if (specFn.length) {
27+
originalIt(description, function zoneResettingSpecFn(originalDone) {
28+
specFn(function zoneResettingDone() {
29+
jasmineZone.run(originalDone);
30+
});
31+
});
32+
} else {
33+
originalIt(description, specFn);
34+
}
35+
};
36+
37+
global.fit = function zoneResettingFit(description, specFn) {
38+
if (specFn.length) {
39+
originalFit(description, function zoneResettingSpecFn(originalDone) {
40+
specFn(function zoneResettingDone() {
41+
jasmineZone.run(originalDone);
42+
});
43+
});
44+
} else {
45+
originalFit(description, specFn);
46+
}
47+
};
48+
49+
// global beforeEach to check if we always start from the root zone
50+
beforeEach(function() {
51+
expect(global.zone.isRootZone()).toBe(true);
52+
});
53+
}
54+
55+
if (global.jasmine) {
56+
module.exports = {
57+
apply: apply
58+
};
59+
} else {
60+
module.exports = {
61+
apply: function() { }
62+
};
63+
}
64+
65+
}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
66+
},{}]},{},[1]);

Diff for: dist/jasmine-patch.min.js

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: gulpfile.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,15 @@ gulp.task('build/zone-microtask.js', function() {
3737
return generateBrowserScript('./lib/browser/zone-microtask.js', 'zone-microtask.js');
3838
});
3939

40-
gulp.task('build', ['build/zone.js', 'build/zone-microtask.js']);
40+
gulp.task('build/jasmine-patch.js', function() {
41+
return generateBrowserScript('./lib/browser/jasmine-patch.js', 'jasmine-patch.js');
42+
});
43+
44+
gulp.task('build', [
45+
'build/zone.js',
46+
'build/zone-microtask.js',
47+
'build/jasmine-patch.js'
48+
]);
4149

4250

4351

Diff for: karma-microtasks.conf.js

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ module.exports = function (config) {
77
'test/util.js',
88
'test/setup-microtask.js',
99
'dist/*-zone.js',
10-
'test/jasmine-patch.js',
1110
'test/**/*.spec.js',
1211
{pattern: 'test/assets/**/*.html', watched: true, served: true, included: false},
1312
{pattern: 'lib/**/*.js', watched: true, served: false, included: false}

Diff for: karma.conf.js

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ module.exports = function (config) {
77
'test/util.js',
88
'test/setup.js',
99
'dist/*-zone.js',
10-
'test/jasmine-patch.js',
1110
//'test/lib/brick.js',
1211
'test/**/*.spec.js',
1312
{pattern: 'test/assets/**/*.html', watched: true, served: true, included: false},

Diff for: lib/browser/jasmine-patch.js

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
var jasminePatch = require('../jasmine/patch');
2+
3+
jasminePatch.apply();

Diff for: lib/jasmine/patch.js

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
'use strict';
2+
// Patch jasmine's it and fit functions so that the `done` callback always resets the zone
3+
// to the jasmine zone, which should be the root zone. (angular/zone.js#91)
4+
5+
function apply() {
6+
if (!global.zone) {
7+
throw new Error('zone.js does not seem to be installed');
8+
}
9+
10+
if (!global.zone.isRootZone()) {
11+
throw new Error('The jasmine patch should be called from the root zone');
12+
}
13+
14+
var jasmineZone = global.zone;
15+
var originalIt = global.it;
16+
var originalFit = global.fit;
17+
18+
global.it = function zoneResettingIt(description, specFn) {
19+
if (specFn.length) {
20+
originalIt(description, function zoneResettingSpecFn(originalDone) {
21+
specFn(function zoneResettingDone() {
22+
jasmineZone.run(originalDone);
23+
});
24+
});
25+
} else {
26+
originalIt(description, specFn);
27+
}
28+
};
29+
30+
global.fit = function zoneResettingFit(description, specFn) {
31+
if (specFn.length) {
32+
originalFit(description, function zoneResettingSpecFn(originalDone) {
33+
specFn(function zoneResettingDone() {
34+
jasmineZone.run(originalDone);
35+
});
36+
});
37+
} else {
38+
originalFit(description, specFn);
39+
}
40+
};
41+
42+
// global beforeEach to check if we always start from the root zone
43+
beforeEach(function() {
44+
expect(global.zone.isRootZone()).toBe(true);
45+
});
46+
}
47+
48+
if (global.jasmine) {
49+
module.exports = {
50+
apply: apply
51+
};
52+
} else {
53+
module.exports = {
54+
apply: function() { }
55+
};
56+
}

Diff for: test/jasmine-patch.js

-40
This file was deleted.

Diff for: test/setup-microtask.js

+4
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
11
// Setup tests for Zone with microtask support
22
require('../lib/browser/zone-microtask.js');
3+
4+
// Patch jasmine
5+
require('../lib/browser/jasmine-patch.js');
6+

Diff for: test/setup.js

+4
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
11
// Setup tests for Zone without microtask support
22
require('../lib/browser/zone.js');
3+
4+
// Patch jasmine
5+
require('../lib/browser/jasmine-patch.js');
6+

0 commit comments

Comments
 (0)