Skip to content

Commit

Permalink
Merge pull request #129 from bitovi/3.1.0-pre
Browse files Browse the repository at this point in the history
Jasmine 2.x adapter
  • Loading branch information
Alexis Abril committed Aug 26, 2015
2 parents 80d9e94 + 8951eb6 commit 01f767b
Show file tree
Hide file tree
Showing 38 changed files with 2,180 additions and 109 deletions.
1 change: 0 additions & 1 deletion Gruntfile.js
Expand Up @@ -50,7 +50,6 @@ module.exports = function (grunt) {
}
return depName;
},
ignore: ["jquery"],
exports: {
"jquery": "jQuery"
}
Expand Down
17 changes: 12 additions & 5 deletions bower.json
@@ -1,7 +1,7 @@
{
"name": "funcunit",
"main": "dist/funcunit.js",
"version": "3.0.0",
"version": "3.1.0-pre.0",
"homepage": "http://funcunit.com",
"author": {
"name": "Bitovi",
Expand All @@ -20,12 +20,13 @@
}
],
"dependencies": {
"jquery": "1.11.0",
"syn": "^0.1.2"

},
"devDependencies": {
"jasmine": "1.3.x",
"jquerypp": "1.0.x"
"jquerypp": "1.0.x",
"jquery": "1.11.0",
"syn": "^0.1.2"
},
"ignore": [
"browser",
Expand All @@ -36,6 +37,12 @@
"/funcunit.js"
],
"system": {
"main": "funcunit"
"main": "dist/funcunit",
"meta": {
"funcunit": {
"format": "global",
"exports": "F"
}
}
}
}
7 changes: 7 additions & 0 deletions browser/adapters/adapters.js
@@ -1,4 +1,5 @@
var jasmineAdapter = require("funcunit/browser/adapters/jasmine");
var jasmine2Adapter = require("funcunit/browser/adapters/jasmine2");
var qunitAdapter = require("funcunit/browser/adapters/qunit");
var mochaAdapter = require("funcunit/browser/adapters/mocha");
var FuncUnit = require("funcunit/browser/core");
Expand Down Expand Up @@ -71,6 +72,8 @@ FuncUnit.attach = function(runner){
unit = mochaAdapter(runner);
} else if(isJasmine(runner)) {
unit = jasmineAdapter(runner);
} else if(isJasmine2(runner)) {
unit = jasmine2Adapter(runner);
} else {
unit = defaultAdapter;
}
Expand All @@ -90,6 +93,10 @@ function isJasmine(runner) {
return !!(runner.getEnv && typeof window.waitsFor === "function");
}

function isJasmine2(runner) {
return !!(runner.getEnv && typeof runner.clock === "function" && !window.waitsFor);
}

/**
* @parent utilities
* @function FuncUnit.detach F.detach()
Expand Down
14 changes: 14 additions & 0 deletions browser/adapters/jasmine2.js
@@ -0,0 +1,14 @@
module.exports = function(jasmine) {
FuncUnit.timeout = 4900;
return {
pauseTest:function(){},
resumeTest: function(){},
assertOK: function(assertion, message){
expect(assertion).toBeTruthy();
},
equiv: function(expected, actual) {
expect(actual).toEqual(expected);
return expected === actual;
}
};
};
14 changes: 14 additions & 0 deletions browser/adapters/test/jasmine2.html
@@ -0,0 +1,14 @@
<!doctype html>
<html>
<head>
<link rel="stylesheet" href="../../../lib/jasmine2/jasmine.css"/>
</head>

<body>
<script src="../../../lib/jasmine2/jasmine.js"></script>
<script src="../../../lib/jasmine2/jasmine-html.js"></script>

<script src="../../../node_modules/steal/steal.js"
main="funcunit/browser/adapters/test/jasmine2"></script>
</body>
</html>
27 changes: 27 additions & 0 deletions browser/adapters/test/jasmine2.js
@@ -0,0 +1,27 @@
var F = require('funcunit');
var $ = require('jquery');
require('../../../lib/jasmine2/boot');

F.attach(jasmine);

describe('Adapters', function() {
beforeEach(function() {
$('body').append('<a class=\'clickme\' href=\'javascript://\'>clickme</a><div class=\'clickresult\'></div>');
$('.clickme').click(function() {
$('.clickresult').text("clicked");
});
});

afterEach(function() {
$('.clickme, .clickresult').remove();
});

it('should use the jasmine adapter', function(done) {
F('.clickme').click();
F('.clickresult').text('clicked');

F.add(done);
});
});

window.onload();
133 changes: 133 additions & 0 deletions dist/amd/browser/actions.js
@@ -0,0 +1,133 @@
/*funcunit@3.1.0-pre.0#browser/actions*/
define(function (require, exports, module) {
var $ = require('./jquery');
var FuncUnit = require('./core');
var syn = window.syn = require('syn');
var clicks = [
'click',
'dblclick',
'rightClick'
], makeClick = function (name) {
FuncUnit.prototype[name] = function (options, success) {
this._addExists();
if (typeof options == 'function') {
success = options;
options = {};
}
var selector = this.selector;
FuncUnit.add({
method: function (success, error) {
options = options || {};
syn('_' + name, this.bind[0], options, success);
},
success: success,
error: 'Could not ' + name + ' \'' + this.selector + '\'',
bind: this,
type: 'action'
});
return this;
};
};
for (var i = 0; i < clicks.length; i++) {
makeClick(clicks[i]);
}
$.extend(FuncUnit.prototype, {
_addExists: function () {
this.exists(false);
},
type: function (text, success) {
this._addExists();
this.click();
var selector = this.selector;
if (text === '') {
text = '[ctrl]a[ctrl-up]\b';
}
FuncUnit.add({
method: function (success, error) {
syn('_type', this.bind[0], text, success);
},
success: success,
error: 'Could not type ' + text + ' into ' + this.selector,
bind: this,
type: 'action'
});
return this;
},
trigger: function (evName, success) {
this._addExists();
FuncUnit.add({
method: function (success, error) {
if (!FuncUnit.win.jQuery) {
throw 'Can not trigger custom event, no jQuery found on target page.';
}
FuncUnit.win.jQuery(this.bind.selector).trigger(evName);
success();
},
success: success,
error: 'Could not trigger ' + evName,
bind: this,
type: 'action'
});
return this;
},
drag: function (options, success) {
this._addExists();
if (typeof options == 'string') {
options = { to: options };
}
options.from = this.selector;
var selector = this.selector;
FuncUnit.add({
method: function (success, error) {
syn('_drag', this.bind[0], options, success);
},
success: success,
error: 'Could not drag ' + this.selector,
bind: this,
type: 'action'
});
return this;
},
move: function (options, success) {
this._addExists();
if (typeof options == 'string') {
options = { to: options };
}
options.from = this.selector;
var selector = this.selector;
FuncUnit.add({
method: function (success, error) {
syn('_move', this.bind[0], options, success);
},
success: success,
error: 'Could not move ' + this.selector,
bind: this,
type: 'action'
});
return this;
},
scroll: function (direction, amount, success) {
this._addExists();
var selector = this.selector, direction;
if (direction == 'left' || direction == 'right') {
direction = 'Left';
} else if (direction == 'top' || direction == 'bottom') {
direction = 'Top';
}
FuncUnit.add({
method: function (success, error) {
this.bind.each(function (i, el) {
this['scroll' + direction] = amount;
});
success();
},
success: success,
error: 'Could not scroll ' + this.selector,
bind: this,
type: 'action'
});
return this;
}
});
module.exports = FuncUnit;
});
49 changes: 49 additions & 0 deletions dist/amd/browser/adapters/adapters.js
@@ -0,0 +1,49 @@
/*funcunit@3.1.0-pre.0#browser/adapters/adapters*/
define(function (require, exports, module) {
var jasmineAdapter = require('./jasmine');
var jasmine2Adapter = require('./jasmine2');
var qunitAdapter = require('./qunit');
var mochaAdapter = require('./mocha');
var FuncUnit = require('../core');
var noop = function () {
};
var defaultAdapter = {
pauseTest: noop,
resumeTest: noop,
assertOK: noop,
equiv: function (expected, actual) {
return expected == actual;
}
};
FuncUnit.unit = defaultAdapter;
FuncUnit.attach = function (runner) {
var unit;
if (isQUnit(runner)) {
unit = qunitAdapter(runner);
} else if (isMocha(runner)) {
unit = mochaAdapter(runner);
} else if (isJasmine(runner)) {
unit = jasmineAdapter(runner);
} else if (isJasmine2(runner)) {
unit = jasmine2Adapter(runner);
} else {
unit = defaultAdapter;
}
FuncUnit.unit = unit;
};
function isQUnit(runner) {
return !!(runner.ok && runner.start && runner.stop);
}
function isMocha(runner) {
return !!(runner.setup && runner.globals && runner.reporter);
}
function isJasmine(runner) {
return !!(runner.getEnv && typeof window.waitsFor === 'function');
}
function isJasmine2(runner) {
return !!(runner.getEnv && typeof runner.clock === 'function' && !window.waitsFor);
}
FuncUnit.detach = function () {
FuncUnit.unit = defaultAdapter;
};
});
23 changes: 23 additions & 0 deletions dist/amd/browser/adapters/jasmine.js
@@ -0,0 +1,23 @@
/*funcunit@3.1.0-pre.0#browser/adapters/jasmine*/
define(function (require, exports, module) {
module.exports = function (jasmine) {
var paused = false;
return {
pauseTest: function () {
paused = true;
waitsFor(function () {
return paused === false;
}, 60000);
},
resumeTest: function () {
paused = false;
},
assertOK: function (assertion, message) {
expect(assertion).toBeTruthy();
},
equiv: function (expected, actual) {
return jasmine.getEnv().equals_(expected, actual);
}
};
};
});
19 changes: 19 additions & 0 deletions dist/amd/browser/adapters/jasmine2.js
@@ -0,0 +1,19 @@
/*funcunit@3.1.0-pre.0#browser/adapters/jasmine2*/
define(function (require, exports, module) {
module.exports = function (jasmine) {
FuncUnit.timeout = 4900;
return {
pauseTest: function () {
},
resumeTest: function () {
},
assertOK: function (assertion, message) {
expect(assertion).toBeTruthy();
},
equiv: function (expected, actual) {
expect(actual).toEqual(expected);
return expected === actual;
}
};
};
});
23 changes: 23 additions & 0 deletions dist/amd/browser/adapters/mocha.js
@@ -0,0 +1,23 @@
/*funcunit@3.1.0-pre.0#browser/adapters/mocha*/
define(function (require, exports, module) {
var FuncUnit = require('../core');
var ok = function (expr, msg) {
if (!expr)
throw new Error(msg);
};
module.exports = function (mocha) {
FuncUnit.timeout = 1900;
return {
pauseTest: function () {
},
resumeTest: function () {
},
assertOK: function (assertion, message) {
ok(assertion, message);
},
equiv: function (expected, actual) {
return expected == actual;
}
};
};
});

0 comments on commit 01f767b

Please sign in to comment.