feat(start): add new custom launcher

This commit is contained in:
vladikoff 2016-04-12 15:55:16 -04:00
Родитель 54fd55eeb1
Коммит 8a060bda8e
3 изменённых файлов: 52 добавлений и 180 удалений

Просмотреть файл

@ -1,14 +1,6 @@
var path = require('path');
var chalk = require('chalk');
var FirefoxProfile = require('firefox-profile');
var fxaProfile = new FirefoxProfile();
var LOG_DIR = path.join(__dirname, '..');
var BROWSER_LOG = path.join(LOG_DIR, 'log-browser.log');
var DRIVER_LOG = path.join(LOG_DIR, 'log-driver.log');
var CONFIGS = {
'local': {
auth: 'http://127.0.0.1:9000/v1',
@ -53,74 +45,59 @@ var FXA_DESKTOP_CONTEXT = process.env.FXA_DESKTOP_CONTEXT || 'fx_desktop_v2';
var e10s = process.env.FXA_E10S === 'true';
var fxaEnv = CONFIGS[env];
var fxaProfile = {
// enable debugger and toolbox
'devtools.chrome.enabled': true,
'devtools.debugger.remote-enabled': true,
'devtools.debugger.prompt-connection': false,
// disable signed extensions
// the WebDriver extension will not work in Nightly because signed extensions are forced
'xpinstall.signatures.required': false,
'xpinstall.whitelist.required': false,
'services.sync.prefs.sync.xpinstall.whitelist.required': false,
'extensions.checkCompatibility.nightly': false,
// enable pocket
'browser.pocket.enabled': true,
// identity logs
'identity.fxaccounts.log.appender.dump': 'Debug',
'identity.fxaccounts.loglevel': 'Debug',
'services.sync.log.appender.file.logOnSuccess': true,
'services.sync.log.appender.console': 'Debug',
'services.sync.log.appender.dump': 'Debug',
'identity.fxaccounts.auth.uri': fxaEnv.auth,
'identity.fxaccounts.allowHttp': true,
'identity.fxaccounts.remote.force_auth.uri': fxaEnv.content + 'force_auth?service=sync&context=' + FXA_DESKTOP_CONTEXT,
'identity.fxaccounts.remote.signin.uri': fxaEnv.content + 'signin?service=sync&context=' + FXA_DESKTOP_CONTEXT,
'identity.fxaccounts.remote.signup.uri': fxaEnv.content + 'signup?service=sync&context=' + FXA_DESKTOP_CONTEXT,
'identity.fxaccounts.remote.webchannel.uri': fxaEnv.content,
'identity.fxaccounts.remote.oauth.uri': fxaEnv.oauth,
'identity.fxaccounts.remote.profile.uri': fxaEnv.profile,
'identity.fxaccounts.settings.uri': fxaEnv.content + 'settings?service=sync&context=' + FXA_DESKTOP_CONTEXT,
// for some reason there are 2 settings for the token server
'identity.sync.tokenserver.uri': fxaEnv.token,
'services.sync.tokenServerURI': fxaEnv.token,
// disable auto update
'app.update.auto': false,
'app.update.enabled': false,
'app.update.silent': false,
'app.update.staging.enabled': false,
};
// Configuration for local sync development
// The loop server is either production or local, nothing on stable or latest
if (fxaEnv.loop) {
fxaProfile.setPreference('loop.server', fxaEnv.loop);
fxaProfile['loop.server'] = fxaEnv.loop;
}
// enable debugger and toolbox
fxaProfile.setPreference('devtools.chrome.enabled', true);
fxaProfile.setPreference('devtools.debugger.remote-enabled', true);
fxaProfile.setPreference('devtools.debugger.prompt-connection', false);
// disable signed extensions
// the WebDriver extension will not work in Nightly because signed extensions are forced
fxaProfile.setPreference('xpinstall.signatures.required', false);
fxaProfile.setPreference('xpinstall.whitelist.required', false);
fxaProfile.setPreference('services.sync.prefs.sync.xpinstall.whitelist.required', false);
fxaProfile.setPreference('extensions.checkCompatibility.nightly', false);
fxaProfile.setPreference('webdriver.log.browser.file', BROWSER_LOG);
fxaProfile.setPreference('webdriver.log.driver.file', DRIVER_LOG);
// enable pocket
fxaProfile.setPreference('browser.pocket.enabled', true);
if (! e10s) {
// disable e10s
fxaProfile.setPreference('browser.tabs.remote.autostart', false);
fxaProfile.setPreference('browser.tabs.remote.autostart.1', false);
fxaProfile.setPreference('browser.tabs.remote.autostart.2', false);
fxaProfile['browser.tabs.remote.autostart'] = false;
fxaProfile['browser.tabs.remote.autostart.1'] = false;
fxaProfile['browser.tabs.remote.autostart.2'] = false;
}
// enable avatars in pref pane
fxaProfile.setPreference('identity.fxaccounts.profile_image.enabled', true);
fxaProfile.setPreference('identity.fxaccounts.log.appender.dump', 'Debug');
fxaProfile.setPreference('identity.fxaccounts.loglevel', 'Debug');
fxaProfile.setPreference('services.sync.log.appender.file.logOnSuccess', true);
fxaProfile.setPreference('services.sync.log.appender.console', 'Debug');
fxaProfile.setPreference('services.sync.log.appender.dump', 'Debug');
fxaProfile.setPreference('services.sync.log.appender.file.logOnSuccess', true);
fxaProfile.setPreference('identity.fxaccounts.auth.uri', fxaEnv.auth);
fxaProfile.setPreference('identity.fxaccounts.allowHttp', true);
fxaProfile.setPreference('identity.fxaccounts.remote.force_auth.uri', fxaEnv.content + 'force_auth?service=sync&context=' + FXA_DESKTOP_CONTEXT);
fxaProfile.setPreference('identity.fxaccounts.remote.signin.uri', fxaEnv.content + 'signin?service=sync&context=' + FXA_DESKTOP_CONTEXT);
fxaProfile.setPreference('identity.fxaccounts.remote.signup.uri', fxaEnv.content + 'signup?service=sync&context=' + FXA_DESKTOP_CONTEXT);
fxaProfile.setPreference('identity.fxaccounts.remote.webchannel.uri', fxaEnv.content);
fxaProfile.setPreference('identity.fxaccounts.remote.oauth.uri', fxaEnv.oauth);
fxaProfile.setPreference('identity.fxaccounts.remote.profile.uri', fxaEnv.profile);
fxaProfile.setPreference('identity.fxaccounts.settings.uri', fxaEnv.content + 'settings?service=sync&context=' + FXA_DESKTOP_CONTEXT);
// for some reason there are 2 settings for the token server
fxaProfile.setPreference('identity.sync.tokenserver.uri', fxaEnv.token);
fxaProfile.setPreference('services.sync.tokenServerURI', fxaEnv.token);
// disable auto update
fxaProfile.setPreference("app.update.auto", false);
fxaProfile.setPreference("app.update.enabled", false);
fxaProfile.setPreference("app.update.silent", false);
fxaProfile.setPreference("app.update.staging.enabled", false);
fxaProfile.updatePreferences();
console.log(chalk.yellow('Configuration:', JSON.stringify(fxaEnv, null, 2)));
console.log(chalk.yellow('E10S Status:', e10s));
console.log(chalk.yellow('FXA_ENV:', env));
@ -128,6 +105,4 @@ console.log(chalk.yellow('FIREFOX_BIN Binary:', process.env.FIREFOX_BIN || 'Defa
console.log(chalk.yellow('FXA_DESKTOP_CONTEXT:', FXA_DESKTOP_CONTEXT));
console.log(chalk.yellow('FIREFOX_DEBUGGER:', !! process.env.FIREFOX_DEBUGGER));
module.exports = function (cb) {
if (cb) fxaProfile.encoded(cb);
};
module.exports = fxaProfile;

Просмотреть файл

@ -2,114 +2,13 @@
var fs = require('fs');
var selenium = require('selenium-standalone');
var webdriverio = require('webdriverio');
var chalk = require('chalk');
var profileOptions = require('./profile');
var profile = require('./profile');
selenium.install({
// check for more recent versions of selenium here:
// http://selenium-release.storage.googleapis.com/index.html
version: '2.47.1',
}, function() {
// clear previous logs
fs.openSync('log-browser.log', 'w');
fs.openSync('log-driver.log', 'w');
selenium.start({
version: '2.47.1',
},function(err, cp) {
process.on('exit', function(code) {
cp.kill();
});
if (err) {
if (err.message && err.message === 'Another Selenium process is already running') {
console.log('Did not start Selenium, already running..');
} else {
throw err
}
};
profile(function (profile) {
var opts = {
desiredCapabilities: {
//loggingPrefs: {"driver": "ALL", "server": "ALL", "browser": "ALL", "client": "ALL"},
browserName: 'firefox',
// set a custom profile
firefox_profile: profile
}
};
// support $FIREFOX_BIN
if (process.env.FIREFOX_BIN) {
opts.desiredCapabilities.firefox_binary = process.env.FIREFOX_BIN;
}
var openDebuggerKeys = '';
if (process.env.FIREFOX_DEBUGGER === 'true' && process.platform === 'darwin') {
// ALT + COMMAND + SHIFT + I keyboard shortcut
openDebuggerKeys = '\uE008\uE03D\uE00AI';
}
setTimeout(function () {
webdriverio
.remote(opts)
.init()
.keys(openDebuggerKeys)
.url('http://www.example.org')
}, 3000);
});
tailLogs();
});
var foxfire = require('foxfire')
foxfire({
args: [
!! process.env.FIREFOX_DEBUGGER ? '-jsdebugger' : ''
],
profileOptions: profileOptions
});
var tailLogs = function() {
Tail = require('tail').Tail;
tail = new Tail('log-browser.log');
tail.on('line', function(data) {
if (data) {
var parsed = true;
try {
data = JSON.parse(data.toString());
} catch (e) {
parsed = false;
w(chalk.blue(data.toString()));
}
if (! parsed) {
return;
}
var msg = data.message.trim();
if (data.level === 'SEVERE') {
w(chalk.red(data.level + ':', msg));
} else if (data.level === 'WARNING') {
// WARNING log is ignored
} else if (msg.toLowerCase().indexOf('fxa') >= 0 || msg.toLowerCase().indexOf('account') >= 0 ) {
w(chalk.green(data.level + ':', msg));
} else {
w(chalk.blue(data.level + ':', msg));
}
}
});
tail.on("error", function(error) {
console.log('ERROR: ', error);
});
};
var w = function(s) {
console.log(s);
};

Просмотреть файл

@ -25,12 +25,10 @@
"dependencies": {
"bluebird": "2.10.2",
"chalk": "1.1.1",
"firefox-profile": "0.3.11",
"foxfire": "1.0.1",
"minimist": "1.1.1",
"pm2": "0.15.10",
"replace-in-file": "0.2.1",
"selenium-standalone": "4.4.0",
"tail": "0.4.0",
"webdriverio": "2.4.5"
"selenium-standalone": "4.4.0"
}
}