Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Quick fix for PhantomJS launcher #40

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,7 @@ before_script:
- grunt build

script:
- grunt test
- grunt test:unit
- grunt test:client
- grunt test:e2e:basic
- grunt test:e2e:mocha
39 changes: 28 additions & 11 deletions lib/launcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ var Browser = function(id) {
return [url];
};

this._tempDir = (env.TMPDIR || env.TMP || env.TEMP || '/tmp') + '/testacular-' + id;
this._tempDir = (env.TMPDIR || env.TMP || env.TEMP || '/tmp') + '/testacular-' + id.toString();

try {
log.debug('Creating temp dir at ' + this._tempDir);
Expand Down Expand Up @@ -112,25 +112,42 @@ var FirefoxBrowser = function() {
var self = this;
var command = this._getCommand();

if (fs.existsSync(this._tempDir + '/prefs.js')) {
log.warn('Profile already exists at %s', this._tempDir);
self._execCommand(command + ' ' + url);
return;
}

// create profile first
exec(command + ' -CreateProfile testacular', function(e, stdout, stderr) {
// https://developer.mozilla.org/en-US/docs/Command_Line_Options
exec(command + ' -CreateProfile "testacular ' + this._tempDir + '"', function(e, stdout, stderr) {
if (e) {
log.error(e);
return;
}

console.log(stderr);
var match = /at\s\'(.*)\/prefs\.js\'/.exec(stderr.toString());

if (match) {
var profile = self._tempDir = match[1];
var prefs = 'user_pref("browser.shell.checkDefaultBrowser", false);\n' +
'user_pref("browser.bookmarks.restore_default_bookmarks", false);\n';

fs.createWriteStream(profile + '/prefs.js', {flags: 'a'}).write(prefs);
self._execCommand(command + ' -profile "' + profile + '" ' + url);
} else {
log.warn('Can not create Firefox profile');
self._execCommand(command + ' ' + url);
log.debug('changing temp dir to %s', match[1])
self._tempDir = match[1];
}

var prefsFile = self._tempDir + '/prefs.js';

fs.exists(prefsFile, function(exists) {
if (exists) {
var prefs = 'user_pref("browser.shell.checkDefaultBrowser", false);\n' +
'user_pref("browser.bookmarks.restore_default_bookmarks", false);\n';

fs.createWriteStream(prefsFile, {flags: 'a'}).write(prefs);
self._execCommand(command + ' -profile "' + self._tempDir + '" ' + url);
} else {
log.warn('Firefox can not create profile');
self._execCommand(command + ' ' + url);
}
});
});
};
};
Expand Down
6 changes: 3 additions & 3 deletions tasks/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ module.exports = function(grunt) {
if (this.target === 'e2e') {
var tests = grunt.file.expand(this.data);
var processToKill;
var cmd = './bin/testacular';
var cmd = 'testacular';
var args = [
'start', null, '--single-run', '--no-auto-watch', '--reporter=dots', '--browsers=' + BROWSERS
'start', null, '--log-level=debug', '--single-run', '--no-auto-watch', '--reporter=dots', '--browsers=' + BROWSERS
];

var next = function(err, result, code) {
Expand Down Expand Up @@ -89,7 +89,7 @@ module.exports = function(grunt) {

// CLIENT unit tests
else if (this.target === 'client') {
exec('testacular', ['start', this.data, '--single-run', '--no-auto-watch', '--reporter=dots',
exec('testacular', ['start', this.data, '--single-run', '--log-level=debug', '--no-auto-watch', '--reporter=dots',
'--browsers=' + BROWSERS], 'Client unit tests failed.');
}
});
Expand Down