added Function.prototype.bind polyfill for PhantomJS. Make Casper happy.

This commit is contained in:
jdescottes 2013-08-04 21:20:25 +02:00
parent 8acd91b4d9
commit a16e1bab09
4 changed files with 44 additions and 27 deletions

View File

@ -14,11 +14,11 @@ module.exports = function (grunt) {
grunt.initConfig({
jshint : {
/*options: {
"evil": true,
"asi": true,
"smarttabs": true,
"eqnull": true
},*/
"evil": true,
"asi": true,
"smarttabs": true,
"eqnull": true
},*/
files : [
'Gruntfile.js',
'package.json',
@ -39,10 +39,10 @@ module.exports = function (grunt) {
filesSrc : ['tests/integration/casperjs/*_test.js'],
options : {
args : {
baseUrl : 'http://localhost:' + '<%= connect.www.options.port %>/?debug'
baseUrl : 'http://localhost:' + '<%= connect.www.options.port %>/'
},
direct : false,
logLevel : 'error',
logLevel : 'debug',
printCommand : false,
printFilePaths : true
}

View File

@ -121,29 +121,30 @@
<script type="text/javascript">
(function () {
var loadScript = function (src, callback) {
document.write('<scr'+'ipt src ="'+src+'" onload="'+callback+'"></sc'+'ript>');
var script = window.document.createElement('script');
script.setAttribute('src',src);
script.setAttribute('onload',callback);
window.document.body.appendChild(script);
};
if (window.location.href.indexOf("debug") != -1) {
window.exports = {};
loadScript("script-load-list.js", "loadDebugScripts()");
window.loadDebugScripts = function () {
exports.scripts.forEach(function (script){
loadScript(script, "done()")
})
}
var loaded = 0;
window.done = function () {
loaded ++;
if (loaded == exports.scripts.length) {
var scriptIndex = 0;
window.loadNextScript = function () {
if (scriptIndex == exports.scripts.length) {
pskl.app.init();
// cleanup
delete window.exports;
delete window.loadDebugScripts;
delete window.done;
} else {
loadScript(exports.scripts[scriptIndex], "loadNextScript()");
scriptIndex ++;
}
};
loadScript("script-load-list.js", "loadNextScript()");
} else {
var script;
if (window.location.href.indexOf("pack") != -1) {
@ -154,7 +155,6 @@
loadScript(script, "pskl.app.init()");
}
})();
</script>
</body>
</html>

View File

@ -11,6 +11,19 @@ jQuery.namespace = function() {
return o;
};
/**
* Need a polyfill for PhantomJS
*/
if (typeof Function.prototype.bind !== "function") {
Function.prototype.bind = function(scope) {
"use strict";
var _function = this;
return function() {
return _function.apply(scope, arguments);
};
};
}
/*
* @provide pskl.utils
*

View File

@ -1,8 +1,12 @@
casper
.start(casper.cli.get('baseUrl'))
.then(function () {
this.test.assertExists('#drawing-canvas-container canvas', 'Check if drawing canvas element is created');
})
.run(function () {
this.test.done();
});
.start(casper.cli.get('baseUrl')+"?debug")
.then(function () {
// If there was a JS error after the page load, casper won't perform asserts
this.test.assertExists('html', 'Casper JS cannot assert DOM elements. A JS error has probably occured.');
this.test.assertExists('#drawing-canvas-container canvas', 'Check if drawing canvas element is created');
})
.run(function () {
this.test.done();
});