From 721663b60b7f54ce9213222951b9904176352d6e Mon Sep 17 00:00:00 2001 From: Travis Kaufman Date: Thu, 21 Jul 2016 15:49:06 -0400 Subject: [PATCH] chore(infrastructure): Set up continuous integration * Add .travis.yml file to the repo, enabling TravisCI to run against PRs for master and branches of. * Set up Sauce Labs running on the last two versions of every major browser (excluding Android 4 and Opera). Android 4 is quite old, and Opera is very similar to Chrome as it uses blink/chromium under the hood. * Work around [SauceLabs PR restriction](https://docs.travis-ci.com/user/pull-requests#Pull-Requests-and-Security-Restrictions) by falling back to running tests on Chrome and FF latest only when PR comes from a repo fork. SL Tests are then run when the PR gets merged to master. * Fix false negative in IE11 for mdl-auto-init test. Part of #4464 --- .travis.yml | 25 +++++ karma.conf.js | 92 ++++++++++++++++++- package.json | 2 + test/unit/mdl-auto-init/mdl-auto-init.test.js | 2 +- 4 files changed, 119 insertions(+), 2 deletions(-) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000000..e36a0346bd --- /dev/null +++ b/.travis.yml @@ -0,0 +1,25 @@ +sudo: required +language: node_js +node_js: + - node # stable + - '4' # LTS +branches: + only: + - master +before_install: + - '[ -n "$SAUCE_ACCESS_KEY" ] || echo "NON-SECURE BUILD. Falling back to Chrome + FF only."' + - '[ -n "$SAUCE_ACCESS_KEY" ] || export CHROME_BIN=/usr/bin/google-chrome' + - '[ -n "$SAUCE_ACCESS_KEY" ] || export DISPLAY=:99.0' + - '[ -n "$SAUCE_ACCESS_KEY" ] || sh -e /etc/init.d/xvfb start' + - '[ -n "$SAUCE_ACCESS_KEY" ] || sudo apt-get update' + - '[ -n "$SAUCE_ACCESS_KEY" ] || sudo apt-get install -y libappindicator1 fonts-liberation' + - '[ -n "$SAUCE_ACCESS_KEY" ] || wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb' + - '[ -n "$SAUCE_ACCESS_KEY" ] || sudo dpkg -i google-chrome*.deb' +env: + global: + - SAUCE_USERNAME=material-sauce + - + secure: aJ9IOc3ngZAujpeNdRRfEZf32tEiPJhNEt/QeoKspP+ivDDxtX4tP+5PlefnQqu5z4M1puF4A6UyiKXZJ5AThFBX0L+FP531lCNibZppyK7KZgl68O92iBooA0EZH45Pb36v9rN5Xl4ZwzJhcx8QiFWXwHp3fQHCgtoxiSdaOBt3l63Wg1vCFPSPPI/8BGiJDwxrOretholor63gMBXUoxJl2ZCMG8NnT5KF1YBzi6ZEWtMLBnuEeKxQcgi3l70UJfR9K/VTfxaoctGrc9UfmyJmD27gGHdBZc0HfZF0Z00SufXn7hILUqfaioJPzRylKxEy0h0KTeX5ZBEQNeLXSIxfcnFHbKk5OeTCkIF+cs9hUrhQfwTpoxyLNPNNeg8P2DMkUvBy/QllEuiESg3LcJlM/ziLhHJpZ7MerbSAZC91rQKX7N/2R8UkaKH6GkEMf5JtK+t1s1fgInBMfPt6oqY250GFq6QJaO/n9a5ndBnDIkjBqbUQYD+8IE793t9HjAN7XwYBk+WgLiStWR+FACLN1VLg8+9K6SfnQujOO2ZYXe2Q2Bdbwk5QqJQCvvb1WHKRMOG2+DN9A2S8zOVfGdC1B9Ih/UZXmXF0r+fEOiY2yuWhgSwd5r16KERxgnG189Gs+7kveT0gfl8SUdEXTEF+fATGEcG+RIv2LSrCNVY= +addons: + firefox: latest + sauce_connect: true diff --git a/karma.conf.js b/karma.conf.js index 4d71696fc5..6cc019f46b 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -1,6 +1,85 @@ const path = require('path'); const webpackConfig = require('./webpack.config')[0]; +const USING_TRAVISCI = Boolean(process.env.TRAVIS); +const USING_SL = Boolean(process.env.SAUCE_USERNAME && process.env.SAUCE_ACCESS_KEY); + +const SL_LAUNCHERS = { + 'sl-chrome-stable': { + base: 'SauceLabs', + browserName: 'chrome', + version: '51' + }, + 'sl-chrome-beta': { + base: 'SauceLabs', + browserName: 'chrome', + version: 'beta' + }, + 'sl-chrome-previous': { + base: 'SauceLabs', + browserName: 'chrome', + version: '50' + }, + 'sl-firefox-stable': { + base: 'SauceLabs', + browserName: 'firefox' + }, + 'sl-firefox-previous': { + base: 'SauceLabs', + browserName: 'firefox', + version: '47' + }, + // NOTE(traviskaufman): Tried adding Firefox beta but it was consistently flaky. Holding off on adding + // it in for now. If it proves to be less flaky in the future, we should add it. + 'sl-safari-stable': { + base: 'SauceLabs', + browserName: 'safari', + version: '9', + platform: 'OS X 10.11' + }, + 'sl-safari-previous': { + base: 'SauceLabs', + browserName: 'safari', + version: '8', + platform: 'OS X 10.10' + }, + 'sl-ie': { + base: 'SauceLabs', + browserName: 'internet explorer', + version: '11', + platform: 'Windows 8.1' + }, + 'sl-edge': { + base: 'SauceLabs', + browserName: 'microsoftedge', + version: '13', + platform: 'Windows 10' + }, + 'sl-android-stable': { + base: 'SauceLabs', + browserName: 'android', + version: '5.0' + }, + 'sl-ios-safari-latest': { + base: 'SauceLabs', + browserName: 'iphone', + platform: 'OS X 10.10', + version: '9.1' + }, + 'sl-ios-safari-previous': { + base: 'SauceLabs', + browserName: 'iphone', + version: '8.4' + } +}; + +const TRAVISCI_FALLBACK_LAUNCHERS = { + 'travisci-chrome': { + base: 'Chrome', + flags: ['--no-sandbox'] + } +}; + module.exports = function(config) { config.set({ basePath: '', @@ -15,8 +94,12 @@ module.exports = function(config) { port: 9876, colors: true, logLevel: config.LOG_INFO, - browsers: ['Chrome'], + browsers: getBrowsers(), + browserDisconnectTimeout: 20000, + browserNoActivityTimeout: 240000, + captureTimeout: 120000, concurrency: Infinity, + customLaunchers: USING_SL ? SL_LAUNCHERS : TRAVISCI_FALLBACK_LAUNCHERS, coverageReporter: { dir: 'coverage', @@ -47,3 +130,10 @@ module.exports = function(config) { } }); }; + +function getBrowsers() { + if (USING_SL) { + return Object.keys(SL_LAUNCHERS); + } + return USING_TRAVISCI ? Object.keys(TRAVISCI_FALLBACK_LAUNCHERS).concat(['Firefox']) : ['Chrome']; +} diff --git a/package.json b/package.json index 70ea9bf3b0..5fa5841679 100644 --- a/package.json +++ b/package.json @@ -38,6 +38,8 @@ "karma": "^1.1.1", "karma-chrome-launcher": "^1.0.1", "karma-coverage": "^1.1.0", + "karma-firefox-launcher": "^1.0.0", + "karma-sauce-launcher": "^1.0.0", "karma-sourcemap-loader": "^0.3.7", "karma-tap": "^2.0.1", "karma-webpack": "^1.7.0", diff --git a/test/unit/mdl-auto-init/mdl-auto-init.test.js b/test/unit/mdl-auto-init/mdl-auto-init.test.js index 549562d579..ee8ff8861a 100644 --- a/test/unit/mdl-auto-init/mdl-auto-init.test.js +++ b/test/unit/mdl-auto-init/mdl-auto-init.test.js @@ -21,7 +21,7 @@ const createFixture = () => bel` const setupTest = () => { mdlAutoInit.deregisterAll(); - mdlAutoInit.register(FakeComponent.name, FakeComponent); + mdlAutoInit.register('FakeComponent', FakeComponent); return createFixture(); };