grunt-contrib-jasmine/simplechrome.js
2017-08-25 18:09:32 +02:00

63 lines
2.1 KiB
JavaScript
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

var Chrome = require('simple-headless-chrome');
var grunt = require('grunt');
var browser = new Chrome({
headless: true,
});
function consume (tab) {
return tab.evaluate(function () {
return ChromeQueue.splice(0, ChromeQueue.length);
});
}
var duration;
var finishedResult = {
failed: 0
};
var fails = [];
// All of this would be much more straightforward with async/await
browser.init()
.then(browser => browser.newTab({ privateTab: false }))
.then(tab => {
return tab.goTo("http://localhost:8088/_SpecRunner-affected.html")
// Return a promise that resolves when we get the FINISHED event from our ChromeReporter
.then(() => new Promise(resolve => {
// Periodically evaluate
var interval = setInterval(function () {
consume(tab)
.then(result => {
var events = result.result.value;
events.forEach(e => {
if (e.type === 'JASMINE_STARTED') {
duration = e.when;
}
if (e.type === 'FINISHED') {
duration = e.when - duration;
}
if (e.type === 'SPEC_FINISHED') {
if (e.payload.status === 'passed') {
process.stdout.write('.')
} else if (e.payload.status === 'pending') {
process.stdout.write('*');
} else if (e.payload.status === 'failed') {
process.stdout.write('x');
}
if (e.payload.failedExpectations.length > 0) {
finishedResult.failed++;
fails.concat(e.payload.failedExpectations);
}
}
// process.stdout.write('.')
})
if (events.length > 0 && events[events.length - 1].type === 'FINISHED') {
clearInterval(interval);
resolve();
}
})
}, 100);
}))
.then(() => { grunt.log.writeln('\nFinished testing (' + (duration / 1000) + ' seconds)')})
.then(() => browser.close())
}
)