Skip to content

Commit

Permalink
feat(boot): expose Jasmine 2.x methods
Browse files Browse the repository at this point in the history
- expose public Jasmine API directly
- avoid proxying the API through own methods
- use native `execute` which takes care of
  focused tests by itself
- add 'use strict' and JSLint/Hint
  • Loading branch information
olegskl committed Dec 22, 2014
1 parent a37fe58 commit 207018b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 128 deletions.
142 changes: 15 additions & 127 deletions lib/boot.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,107 +3,30 @@
* This file is registered in `index.js`. This version
* does not include `HtmlReporter` setup.
*/
(function(){
(function (global) {

/*global jasmineRequire */
'use strict';

/**
* Require Jasmine's core files. Specifically, this requires and
* attaches all of Jasmine's code to the `jasmine` reference.
*/
window.jasmine = jasmineRequire.core(jasmineRequire);

var jasmine = jasmineRequire.core(jasmineRequire);

/**
* Create the Jasmine environment. This is used to run all specs
* in a project.
* Obtain the public Jasmine API.
*/
var env = jasmine.getEnv();

var focusedSuites = [];
var focusedSpecs = [];
var insideFocusedSuite = false;

var focuseSpec = function(env, description, body) {
var spec = env.it(description, body);
focusedSpecs.push(spec.id);
return spec;
};

var focuseSuite = function(env, description, body) {
if (insideFocusedSuite) {
return env.describe(description, body);
}

insideFocusedSuite = true;
var suite = env.describe(description, body);
insideFocusedSuite = false
focusedSuites.push(suite.id);
return suite;
};
var jasmineInterface = jasmineRequire.interface(jasmine, jasmine.getEnv());

/**
* Setting up timing functions to be able to be overridden. Certain browsers (Safari, IE 8, phantomjs) require
* this hack.
* Setting up timing functions to be able to be overridden.
* Certain browsers (Safari, IE 8, PhantomJS) require this hack.
*/
window.setTimeout = window.setTimeout;
window.setInterval = window.setInterval;
window.clearTimeout = window.clearTimeout;
window.clearInterval = window.clearInterval;


/**
* Build up the functions that will be exposed as the Jasmine
* public interface.
*/
var jasmineInterface = {
describe: function(description, specDefinitions) {
return env.describe(description, specDefinitions);
},

xdescribe: function(description, specDefinitions) {
return env.xdescribe(description, specDefinitions);
},

ddescribe: function(description, specDefinitions) {
return focuseSuite(env, description, specDefinitions);
},

it: function(desc, func) {
return env.it(desc, func);
},

xit: function(desc, func) {
return env.xit(desc, func);
},

iit: function(desc, func) {
return focuseSpec(env, desc, func);
},

beforeEach: function(beforeEachFunction) {
return env.beforeEach(beforeEachFunction);
},

afterEach: function(afterEachFunction) {
return env.afterEach(afterEachFunction);
},

expect: function(actual) {
return env.expect(actual);
},

pending: function() {
return env.pending();
},

spyOn: function(obj, methodName) {
return env.spyOn(obj, methodName);
},

jsApiReporter: new jasmine.JsApiReporter({
timer: new jasmine.Timer()
})
};

global.setTimeout = global.setTimeout;
global.setInterval = global.setInterval;
global.clearTimeout = global.clearTimeout;
global.clearInterval = global.clearInterval;

/**
* Add all of the Jasmine global/public interface to the proper
Expand All @@ -113,43 +36,8 @@
*/
for (var property in jasmineInterface) {
if (jasmineInterface.hasOwnProperty(property)) {
window[property] = jasmineInterface[property];
global[property] = jasmineInterface[property];
}
}

env.executeFiltered = function() {
if (focusedSpecs.length) {
env.execute(focusedSpecs);
} else if (focusedSuites.length) {
env.execute(focusedSuites);
} else {
env.execute();
}
};


/**
* Expose the interface for adding custom equality testers.
*/
jasmine.addCustomEqualityTester = function(tester) {
env.addCustomEqualityTester(tester);
};


/**
* Expose the interface for adding custom expectation matchers
*/
jasmine.addMatchers = function(matchers) {
return env.addMatchers(matchers);
};


/**
* Expose the mock interface for the JavaScript timeout functions
*/
jasmine.clock = function() {
return env.clock;
};


})();
}(window));
2 changes: 1 addition & 1 deletion src/adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,6 @@ var createStartFn = function(tc, jasmineEnvPassedIn) {
var jasmineEnv = jasmineEnvPassedIn || window.jasmine.getEnv();

jasmineEnv.addReporter(new KarmaReporter(tc, jasmineEnv));
jasmineEnv.executeFiltered();
jasmineEnv.execute();
};
};

1 comment on commit 207018b

@KeithWoods
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For anyone else arriving at this and wondering why ddescribe iit etc doesn't work any more, check out http://jasmine.github.io/2.1/focused_specs.html, as olegskl said in the commit it's handled natively now.

Please sign in to comment.