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

Browser map refactor #18

Merged
merged 20 commits into from
Mar 1, 2016
Merged
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: 5 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
language: node_js
node_js:
- '4.1'
script:
- npm test
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
## Upcoming Release

#### Breaking changes
- None yet
- Type `phantom` is now `phantomjs`, which is a little more consistent
- The property "name" is more descriptive for variant channels, e.g. "chrome-canary"

#### User features
- None yet
Expand Down
6 changes: 3 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var path = require( 'path' ),
_ = require( 'lodash' ),
pick = require( 'lodash/pick' ),
configModule = require( './lib/config' ),
detect = require( './lib/detect' ),
run = require( './lib/run' ),
Expand Down Expand Up @@ -75,14 +75,14 @@ function getLauncher( configFile, callback ) {
getLauncher.detect = function( callback ) {
detect( function( browsers ) {
callback( browsers.map( function( browser ) {
return _.pick( browser, [ 'name', 'version', 'type', 'command' ] );
return pick( browser, [ 'name', 'version', 'type', 'command' ] );
} ) );
} );
};

/**
* Update the browsers cache and create new profiles if necessary
* @param {String} configDir Path to the configuration file
* @param {String} configFile Path to the configuration file
* @param {Function} callback Callback function
*/
getLauncher.update = function( configFile, callback ) {
Expand Down
95 changes: 95 additions & 0 deletions lib/browsers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/**
* Created by mitch on 2/29/16.
*/
var omit = require('lodash/omit');

var browsers = {
chrome: {
regex: /Google Chrome (\S+)/,
profile: true,
variants: {
'chrome': ['google-chrome', 'google-chrome-stable'],
'chrome-beta': ['google-chrome-beta'],
'chrome-canary': ['google-chrome-canary']
}
},
chromium: {
regex: /Chromium (\S+)/,
profile: true,
variants: {
'chromium': ['chromium', 'chromium-browser']
}
},
firefox: {
regex: /Mozilla Firefox (\S+)/,
profile: true,
variants: {
'firefox': ['firefox'],
'firefox-developer': ['firefox-developer']
}
},
phantomjs: {
regex: /(\S+)/,
profile: false,
headless: true
},
safari: {
profile: false
},
ie: {
profile: false
},
opera: {
regex: /Opera (\S+)/,
profile: true
}
};

/**
* Used to get browser information and configuration. By default, uses internal browser list
* @param [browserList] list of browsers, configuration and variants
* @constructor
*/
function Browsers(browserList) {
this.browserList = browserList || browsers;
}

/**
* Compiles each browser into the relevant data for Linux or Darwin. The structure of each object returned is:
* type: type of browser, e.g.: "chrome", "chromium", "ie"
* darwin: name of browser, used to look up "darwin detector" (see "./darwin" folder)
* linux: array of commands that the browser might run as on a 'nix environment
* regex: extracts version code when browser is run as a command
*
* @returns {Array}
*/
Browsers.prototype.browserPlatforms = function browserPlatforms() {
var _browsers = [];
var browsers = this.browserList;

Object.keys(browsers).forEach(function(type) {
var regex = browsers[type].regex;
var variants = browsers[type].variants;

if (!variants) {
return _browsers.push({type: type, darwin: type, linux: [type], regex: regex});
}

Object.keys(variants).map(function(name) {
return _browsers.push({type: type, darwin: name, linux: variants[name], regex: regex});
});
});

return _browsers;
};

/**
* Returns the configuration for the browser type specified
* @param type type of browser
* @returns {Object} config for the specified browser type
*/
Browsers.prototype.typeConfig = function typeConfig(type) {
return omit(this.browserList[type], 'variants');
};

module.exports = Browsers;
File renamed without changes.
4 changes: 2 additions & 2 deletions lib/darwin/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
exports.safari = require( './safari' );
exports.firefox = require( './firefox' );
exports.chrome = exports[ 'google-chrome' ] = require( './chrome' );
exports.chrome = require( './chrome' );
exports.chromium = require( './chromium' );
exports.canary = exports[ 'chrome-canary' ] = exports[ 'google-chrome-canary' ] = require( './canary' );
exports[ 'chrome-canary' ] = require( './chrome-canary' );
exports.opera = require( './opera' );
exports.phantomjs = require( './phantomjs' );
Loading