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

Commit

Permalink
feat(jasmine): export the jasmine patch
Browse files Browse the repository at this point in the history
  • Loading branch information
vicb committed May 13, 2015
1 parent 95c9dc2 commit 639d5e7
Show file tree
Hide file tree
Showing 10 changed files with 143 additions and 43 deletions.
66 changes: 66 additions & 0 deletions dist/jasmine-patch.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
(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){
var jasminePatch = require('../jasmine/patch');

jasminePatch.apply();

},{"../jasmine/patch":2}],2:[function(require,module,exports){
(function (global){
'use strict';
// Patch jasmine's it and fit functions so that the `done` callback always resets the zone
// to the jasmine zone, which should be the root zone. (angular/zone.js#91)

function apply() {
if (!global.zone) {
throw new Error('zone.js does not seem to be installed');
}

if (!global.zone.isRootZone()) {
throw new Error('The jasmine patch should be called from the root zone');
}

var jasmineZone = global.zone;
var originalIt = global.it;
var originalFit = global.fit;

global.it = function zoneResettingIt(description, specFn) {
if (specFn.length) {
originalIt(description, function zoneResettingSpecFn(originalDone) {
specFn(function zoneResettingDone() {
jasmineZone.run(originalDone);
});
});
} else {
originalIt(description, specFn);
}
};

global.fit = function zoneResettingFit(description, specFn) {
if (specFn.length) {
originalFit(description, function zoneResettingSpecFn(originalDone) {
specFn(function zoneResettingDone() {
jasmineZone.run(originalDone);
});
});
} else {
originalFit(description, specFn);
}
};

// global beforeEach to check if we always start from the root zone
beforeEach(function() {
expect(global.zone.isRootZone()).toBe(true);
});
}

if (global.jasmine) {
module.exports = {
apply: apply
};
} else {
module.exports = {
apply: function() { }
};
}

}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
},{}]},{},[1]);
1 change: 1 addition & 0 deletions dist/jasmine-patch.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 9 additions & 1 deletion gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,15 @@ gulp.task('build/zone-microtask.js', function() {
return generateBrowserScript('./lib/browser/zone-microtask.js', 'zone-microtask.js');
});

gulp.task('build', ['build/zone.js', 'build/zone-microtask.js']);
gulp.task('build/jasmine-patch.js', function() {
return generateBrowserScript('./lib/browser/jasmine-patch.js', 'jasmine-patch.js');
});

gulp.task('build', [
'build/zone.js',
'build/zone-microtask.js',
'build/jasmine-patch.js'
]);



1 change: 0 additions & 1 deletion karma-microtasks.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ module.exports = function (config) {
'test/util.js',
'test/setup-microtask.js',
'dist/*-zone.js',
'test/jasmine-patch.js',
'test/**/*.spec.js',
{pattern: 'test/assets/**/*.html', watched: true, served: true, included: false},
{pattern: 'lib/**/*.js', watched: true, served: false, included: false}
Expand Down
1 change: 0 additions & 1 deletion karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ module.exports = function (config) {
'test/util.js',
'test/setup.js',
'dist/*-zone.js',
'test/jasmine-patch.js',
//'test/lib/brick.js',
'test/**/*.spec.js',
{pattern: 'test/assets/**/*.html', watched: true, served: true, included: false},
Expand Down
3 changes: 3 additions & 0 deletions lib/browser/jasmine-patch.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
var jasminePatch = require('../jasmine/patch');

jasminePatch.apply();
56 changes: 56 additions & 0 deletions lib/jasmine/patch.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
'use strict';
// Patch jasmine's it and fit functions so that the `done` callback always resets the zone
// to the jasmine zone, which should be the root zone. (angular/zone.js#91)

function apply() {
if (!global.zone) {
throw new Error('zone.js does not seem to be installed');
}

if (!global.zone.isRootZone()) {
throw new Error('The jasmine patch should be called from the root zone');
}

var jasmineZone = global.zone;
var originalIt = global.it;
var originalFit = global.fit;

global.it = function zoneResettingIt(description, specFn) {
if (specFn.length) {
originalIt(description, function zoneResettingSpecFn(originalDone) {
specFn(function zoneResettingDone() {
jasmineZone.run(originalDone);
});
});
} else {
originalIt(description, specFn);
}
};

global.fit = function zoneResettingFit(description, specFn) {
if (specFn.length) {
originalFit(description, function zoneResettingSpecFn(originalDone) {
specFn(function zoneResettingDone() {
jasmineZone.run(originalDone);
});
});
} else {
originalFit(description, specFn);
}
};

// global beforeEach to check if we always start from the root zone
beforeEach(function() {
expect(global.zone.isRootZone()).toBe(true);
});
}

if (global.jasmine) {
module.exports = {
apply: apply
};
} else {
module.exports = {
apply: function() { }
};
}
40 changes: 0 additions & 40 deletions test/jasmine-patch.js

This file was deleted.

4 changes: 4 additions & 0 deletions test/setup-microtask.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
// Setup tests for Zone with microtask support
require('../lib/browser/zone-microtask.js');

// Patch jasmine
require('../lib/browser/jasmine-patch.js');

4 changes: 4 additions & 0 deletions test/setup.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
// Setup tests for Zone without microtask support
require('../lib/browser/zone.js');

// Patch jasmine
require('../lib/browser/jasmine-patch.js');

0 comments on commit 639d5e7

Please sign in to comment.