52 lines
1.5 KiB
JavaScript
52 lines
1.5 KiB
JavaScript
var fs = require('fs');
|
|
|
|
|
|
var PhantomJSBrowser = function(baseBrowserDecorator, config, args) {
|
|
baseBrowserDecorator(this);
|
|
|
|
var options = args && args.options || config && config.options || {};
|
|
var flags = args && args.flags || config && config.flags || [];
|
|
|
|
this._start = function(url) {
|
|
// create the js file that will open karma
|
|
var captureFile = this._tempDir + '/capture.js';
|
|
var optionsCode = Object.keys(options).map(function (key) {
|
|
if (key !== 'settings') { // settings cannot be overriden, it should be extended!
|
|
return 'page.' + key + ' = ' + JSON.stringify(options[key]) + ';';
|
|
}
|
|
});
|
|
|
|
if (options.settings) {
|
|
optionsCode = optionsCode.concat(Object.keys(options.settings).map(function (key) {
|
|
return 'page.settings.' + key + ' = ' + JSON.stringify(options.settings[key]) + ';';
|
|
}));
|
|
}
|
|
|
|
var captureCode = 'var page = require("webpage").create();\n' +
|
|
optionsCode.join('\n') + '\npage.open("' + url + '");\n';
|
|
fs.writeFileSync(captureFile, captureCode);
|
|
|
|
// and start phantomjs
|
|
this._execCommand(this._getCommand(), flags.concat(captureFile));
|
|
};
|
|
};
|
|
|
|
PhantomJSBrowser.prototype = {
|
|
name: 'PhantomJS',
|
|
|
|
DEFAULT_CMD: {
|
|
linux: require('phantomjs').path,
|
|
darwin: require('phantomjs').path,
|
|
win32: require('phantomjs').path
|
|
},
|
|
ENV_CMD: 'PHANTOMJS_BIN'
|
|
};
|
|
|
|
PhantomJSBrowser.$inject = ['baseBrowserDecorator', 'config.phantomjsLauncher', 'args'];
|
|
|
|
|
|
// PUBLISH DI MODULE
|
|
module.exports = {
|
|
'launcher:PhantomJS': ['type', PhantomJSBrowser]
|
|
};
|