Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #129 from bitovi/3.1.0-pre
Jasmine 2.x adapter
- Loading branch information
Showing
38 changed files
with
2,180 additions
and
109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
}; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
}; | ||
}; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
}; | ||
}; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
}; | ||
}; | ||
}); |
Oops, something went wrong.