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

chore(ci): disable browserstack for community PRs #150

Merged
merged 4 commits into from
Jun 29, 2018
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
@@ -1,3 +1,8 @@
language: node_js

addons:
chrome: beta
firefox: latest

node_js:
- "9"
104 changes: 83 additions & 21 deletions config/karma/karmaConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ const baseConfig = {
webpackMiddleware: {}
};

/**
* Local testing - headless browsers
*/

const headlessConfig = karmaConfig => {
process.env.CHROME_BIN = require("puppeteer").executablePath();
const headlessConfig = {
Expand All @@ -39,6 +43,10 @@ const headlessConfig = karmaConfig => {
karmaConfig.set(headlessConfig);
};

/**
* Local testing - full browsers
*/

const localConfig = karmaConfig => {
const browsers = [
"ChromeHeadless",
Expand Down Expand Up @@ -66,9 +74,9 @@ const localConfig = karmaConfig => {
});
};

const browserslist = require("browserslist");

const browsers = browserslist();
/**
* CI testing - Chrome, Firefox, and (if available) BrowserStack
*/

const availableOnWindows = browser =>
["ie", "edge", "chrome", "firefox"].includes(browser);
Expand All @@ -81,8 +89,10 @@ const oldestVersionFromRange = versionRange => {
}
return versionRange;
};

const isDesktop = browserOrPlatform =>
["chrome", "firefox", "safari", "edge", "ie"].includes(browserOrPlatform);

// Update these values from https://www.browserstack.com/automate/capabilities#test-configuration-capabilities if the build fails
const getOSVersionAndDeviceForMobileChromeVersion = version => {
if (Number.parseFloat(version) >= 5) {
Expand Down Expand Up @@ -117,6 +127,7 @@ const getOSVersionAndDeviceForMobileSafariVersion = version => {
device: "iPhone 8"
};
};

const ensureBrowserVersionExistsOnBrowserStack = (browser, version) => {
const versionNumber = Number.parseFloat(version);
if (browser.toLowerCase() === "safari") {
Expand All @@ -129,7 +140,6 @@ const ensureBrowserVersionExistsOnBrowserStack = (browser, version) => {
}
return version;
};

const ensureOSXVersionIsCorrect = (browser, version) => {
const versionNumber = Number.parseFloat(version);
if (browser.toLowerCase() === "safari") {
Expand All @@ -142,6 +152,7 @@ const ensureOSXVersionIsCorrect = (browser, version) => {
}
return "High Sierra";
};

const mapBrowsersListToBrowserStackLaunchers = browserslistList => {
let browserStackConfigurationObjects = {};
browserslistList.forEach(browsersListItem => {
Expand Down Expand Up @@ -197,29 +208,80 @@ const mapBrowsersListToBrowserStackLaunchers = browserslistList => {
};

const fullConfig = karmaConfig => {
const browserslist = require("browserslist");
const { browsers, customLaunchers } = mapBrowsersListToBrowserStackLaunchers(
browserslist()
);
console.log(
"Testing on browsers:\n",
browsers.map(browser => ` - ${browser}`).join("\n")
);

karmaConfig.set({
let config = {
...baseConfig,
browserStack: {
reporters: [...baseConfig.reporters],
browsers: ["ChromeTravis", "FirefoxHeadless"],
customLaunchers: {
ChromeTravis: {
base: "ChromeHeadless",
flags: ["--no-sandbox"]
},
FirefoxHeadless: {
base: "Firefox",
flags: ["-headless"]
}
},
plugins: [...baseConfig.plugins]
};

if (isBrowserStackAvailable()) {
const browserslist = require("browserslist");
const {
browsers: bsBrowsers,
customLaunchers: customBSLaunchers
} = mapBrowsersListToBrowserStackLaunchers(browserslist());

config.browserStack = {
username: process.env.BROWSERSTACK_USERNAME,
accessKey: process.env.BROWSERSTACK_ACCESS_KEY
},
reporters: [...baseConfig.reporters, "BrowserStack"],
};

config.reporters = [...config.reporters, "BrowserStack"];

const bsBrowsersWithoutChromeAndFirefox = bsBrowsers.filter(
browser => !(browser.includes("chrome") || browser.includes("firefox"))
);
// TODO: Enable iPhone tests when BrowserStack support replies
browsers: browsers.filter(v => !v.includes("iPhone")),
customLaunchers,
plugins: [...baseConfig.plugins, "karma-browserstack-launcher"]
});
const bsBrowsersWithoutChromeAndFirefoxAndIOS = bsBrowsersWithoutChromeAndFirefox.filter(
browser => !browser.includes("iPhone")
);

config.browsers = [
...config.browsers,
...bsBrowsersWithoutChromeAndFirefoxAndIOS
];

config.customLaunchers = {
...config.customLaunchers,
...customBSLaunchers
};

config.plugins = [...config.plugins, "karma-browserstack-launcher"];
}

console.log(
"Testing on browsers:\n",
config.browsers.map(browser => ` - ${browser}`).join("\n")
);

karmaConfig.set(config);
};

function isBrowserStackAvailable() {
if (
!(process.env.BROWSERSTACK_USERNAME && process.env.BROWSERSTACK_ACCESS_KEY)
) {
return false;
}

// If the slugs are different, the PR comes from an outsider (not a collaborator)
return (
process.env.TRAVIS_EVENT_TYPE !== "pull_request" ||
process.env.TRAVIS_PULL_REQUEST_SLUG === process.env.TRAVIS_REPO_SLUG
);
}

exports.full = fullConfig;
exports.local = localConfig;
exports.headless = headlessConfig;