mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
2807202ee7
fixes #634 fixes #551
84 lines
2.4 KiB
JavaScript
84 lines
2.4 KiB
JavaScript
/* jshint evil: true */
|
|
|
|
'use strict';
|
|
|
|
var grunt = require("grunt");
|
|
var wd = require('wd');
|
|
|
|
module.exports = function(){
|
|
var config = this.data;
|
|
var taskSucceeded = this.async();
|
|
|
|
var desiredCapabilities = {};
|
|
if (config.desiredCapabilities) {
|
|
Object.keys(config.desiredCapabilities).forEach(function(key) {
|
|
if (config.desiredCapabilities[key] === undefined) {
|
|
return;
|
|
}
|
|
desiredCapabilities[key] = config.desiredCapabilities[key];
|
|
});
|
|
}
|
|
grunt.verbose.writeln("desiredCapabilities", JSON.stringify(desiredCapabilities));
|
|
|
|
var browser = wd.promiseChainRemote(config.webdriver.remote);
|
|
|
|
browser.on('status', function(info) {
|
|
grunt.verbose.writeln(info);
|
|
});
|
|
|
|
browser.on('command', function(meth, path, data) {
|
|
grunt.verbose.writeln(' > ' + meth, path, data || '');
|
|
});
|
|
|
|
var results = null;
|
|
|
|
// browser._debugPromise();
|
|
browser
|
|
.init(desiredCapabilities)
|
|
.then(config.onStart && config.onStart.bind(config, browser))
|
|
.get(config.url)
|
|
.then(function(){return browser;})
|
|
.then(getJSReport)
|
|
.then(function(data){ results = data; })
|
|
.fail(function(error){
|
|
grunt.log.error(error);
|
|
return browser
|
|
.eval('document.documentElement.innerText || document.documentElement.textContent')
|
|
.then(grunt.verbose.writeln.bind(grunt.verbose))
|
|
.then(function(){ throw error; })
|
|
;
|
|
})
|
|
.finally(function(){
|
|
if (grunt.option('webdriver-keep-open')) {
|
|
return;
|
|
}
|
|
grunt.verbose.writeln('Closing the browser window. To keep it open, pass the --webdriver-keep-open flag to grunt.');
|
|
return browser.quit();
|
|
})
|
|
.done(
|
|
function() {
|
|
if (config.onComplete) {
|
|
config.onComplete(results);
|
|
}
|
|
taskSucceeded(true);
|
|
},
|
|
function(error) {
|
|
if (config.onError) {
|
|
config.onError(error);
|
|
}
|
|
taskSucceeded(false);
|
|
}
|
|
);
|
|
};
|
|
|
|
function getJSReport(browser){
|
|
return browser
|
|
.waitFor(wd.asserters.jsCondition("typeof window.jasmine != 'undefined'"), 5e3, 50)
|
|
.fail(function(error){
|
|
throw Error("The test page didn't load properly. " + error);
|
|
})
|
|
.waitFor(wd.asserters.jsCondition("typeof window.jasmine.getJSReport != 'undefined'"), 60e3, 100)
|
|
.waitFor(wd.asserters.jsCondition("window.postDataToURL.running <= 0"), 30e3, 500)
|
|
.eval("jasmine.getJSReport().passed");
|
|
}
|