diff --git a/packages/electrode-archetype-react-component-dev/config/karma/browser-settings.js b/packages/electrode-archetype-react-component-dev/config/karma/browser-settings.js new file mode 100644 index 000000000..3277bc51f --- /dev/null +++ b/packages/electrode-archetype-react-component-dev/config/karma/browser-settings.js @@ -0,0 +1,25 @@ +"use strict"; + +const archetype = require("electrode-archetype-react-component/config/archetype"); +const browser = archetype.karma.browser.toLowerCase(); + +module.exports = function(settings) { + if (browser === "chrome") { + settings.browsers = ["ChromeHeadless"]; + settings.frameworks = ["mocha"]; + settings.crossOriginAttribute = false; + console.log("Using Chrome Headless to run Karma test"); + + } else if (browser === "phantomjs") { + settings.browsers = ["PhantomJS"]; + settings.frameworks = ["mocha", "phantomjs-shim"]; + console.warn( + "Using PhantomJS to run Karma test. It's been deprecated and may be removed in the future." + ); + } else { + console.error(`Unknown browser ${browser} set for Karma test. Failed.`); + return process.exit(1); + } + + return settings; +}; diff --git a/packages/electrode-archetype-react-component-dev/config/karma/karma.conf.dev.js b/packages/electrode-archetype-react-component-dev/config/karma/karma.conf.dev.js index 8df909f58..b4b5c8fcc 100644 --- a/packages/electrode-archetype-react-component-dev/config/karma/karma.conf.dev.js +++ b/packages/electrode-archetype-react-component-dev/config/karma/karma.conf.dev.js @@ -1,5 +1,7 @@ "use strict"; +const browserSettings = require("./browser-settings"); + /* * Karma Configuration: "dev" version. * @@ -9,10 +11,8 @@ * server during the test run. */ module.exports = function (config) { - config.set({ - frameworks: ["mocha", "phantomjs-shim"], + const base = { reporters: ["spec"], - browsers: ["PhantomJS"], basePath: process.cwd(), // repository root. files: [ // Test bundle (must be created via `npm run dev|hot|server-test`) @@ -26,5 +26,9 @@ module.exports = function (config) { ui: "bdd" } } - }); + }; + + browserSettings(base); + + config.set(base); }; diff --git a/packages/electrode-archetype-react-component-dev/config/karma/karma.conf.js b/packages/electrode-archetype-react-component-dev/config/karma/karma.conf.js index 718d83117..9f942292a 100644 --- a/packages/electrode-archetype-react-component-dev/config/karma/karma.conf.js +++ b/packages/electrode-archetype-react-component-dev/config/karma/karma.conf.js @@ -4,19 +4,20 @@ var path = require("path"); var webpackCfg = require("../webpack/webpack.config.test"); -var MAIN_PATH = require.resolve("electrode-archetype-react-component-dev/config/karma/entry.js"); // eslint-disable-line max-len +var MAIN_PATH = require.resolve( + "electrode-archetype-react-component-dev/config/karma/entry.js" +); + +const browserSettings = require("./browser-settings"); var PREPROCESSORS = {}; PREPROCESSORS[MAIN_PATH] = ["webpack"]; -module.exports = function (config) { - config.set({ +module.exports = function(config) { + const base = { basePath: process.cwd(), - frameworks: ["mocha", "phantomjs-shim", "intl-shim"], - files: [ - MAIN_PATH - ], + files: [MAIN_PATH], preprocessors: PREPROCESSORS, webpack: webpackCfg, webpackServer: { @@ -38,7 +39,6 @@ module.exports = function (config) { logLevel: config.LOG_INFO, colors: true, autoWatch: false, - browsers: ["PhantomJS"], reporters: ["spec", "coverage"], browserNoActivityTimeout: 60000, coverageReporter: { @@ -51,5 +51,9 @@ module.exports = function (config) { }, captureTimeout: 100000, singleRun: true - }); + }; + + browserSettings(base); + + config.set(base); }; diff --git a/packages/electrode-archetype-react-component-dev/package.json b/packages/electrode-archetype-react-component-dev/package.json index ac6ff155d..098f7dfff 100644 --- a/packages/electrode-archetype-react-component-dev/package.json +++ b/packages/electrode-archetype-react-component-dev/package.json @@ -53,7 +53,7 @@ "json-loader": "^0.5.3", "jsonfile": "^2.2.2", "karma": "^1.5.0", - "karma-chrome-launcher": "^0.2.0", + "karma-chrome-launcher": "^2.1.1", "karma-coverage": "^1.1.1", "karma-firefox-launcher": "^1", "karma-ie-launcher": "^1.0.0", diff --git a/packages/electrode-archetype-react-component/config/archetype.js b/packages/electrode-archetype-react-component/config/archetype.js index 54b0e64f1..005dadc5a 100644 --- a/packages/electrode-archetype-react-component/config/archetype.js +++ b/packages/electrode-archetype-react-component/config/archetype.js @@ -13,5 +13,8 @@ module.exports = { devPort: 2992, testPort: 3001, modulesDirectories: ["node_modules"] + }, + karma: { + browser: process.env.KARMA_BROWSER === undefined ? "chrome" : process.env.KARMA_BROWSER } };