From a4d05d469f0c3986b900eba37228155065567955 Mon Sep 17 00:00:00 2001 From: Robert Knight Date: Wed, 25 Nov 2015 12:18:56 +0000 Subject: [PATCH] Add configuration for running client tests using Sauce Labs This gives us the capability to test the client-side JS rewriting against a suite of different browsers on different platforms. Note that getting Karma running on Travis CI requires some additional configuration documented at github.com/karma-runner/karma-sauce-launcher/issues/73 which is not made clear in the original documentation. In order to run the Karma tests, the Sauce Labs username and access keys need to be passed in via the SAUCE_USERNAME and SAUCE_ACCESS_KEYS env vars. --- .travis.yml | 2 +- karma-tests/karma.conf.js | 84 ++++++++++++++++++++++++-------------- karma-tests/wombat.spec.js | 3 ++ package.json | 1 + 4 files changed, 58 insertions(+), 32 deletions(-) diff --git a/.travis.yml b/.travis.yml index ac5cef39..728e6689 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,7 +6,7 @@ python: os: - linux -# - osx + sudo: false diff --git a/karma-tests/karma.conf.js b/karma-tests/karma.conf.js index 61127d7d..b40190f2 100644 --- a/karma-tests/karma.conf.js +++ b/karma-tests/karma.conf.js @@ -1,18 +1,56 @@ +if (!process.env['SAUCE_USERNAME'] || !process.env['SAUCE_ACCESS_KEY']) { + console.error('Sauce Labs account details not set, skipping Karma tests'); + process.exit(0); +} + +var sauceLabsConfig = { + testName: 'PyWB Client Tests', +}; + +// see https://github.com/karma-runner/karma-sauce-launcher/issues/73 +if (process.env.TRAVIS_JOB_NUMBER) { + sauceLabsConfig.startConnect = false; + sauceLabsConfig.tunnelIdentifier = process.env.TRAVIS_JOB_NUMBER; +} + var WOMBAT_JS_PATH = 'pywb/static/wombat.js'; +var customLaunchers = { + sl_chrome: { + base: 'SauceLabs', + browserName: 'chrome', + }, + + sl_firefox: { + base: 'SauceLabs', + browserName: 'firefox', + }, + +/* Safari and Edge are currently broken in + pywb. + + See: https://github.com/ikreymer/pywb/issues/148 (Edge) + https://github.com/ikreymer/pywb/issues/147 (Safari) + + sl_safari: { + base: 'SauceLabs', + browserName: 'safari', + platform: 'OS X 10.11', + version: '9.0', + }, + sl_edge: { + base: 'SauceLabs', + browserName: 'MicrosoftEdge', + }, +*/ +}; + module.exports = function(config) { config.set({ - - // base path that will be used to resolve all patterns (eg. files, exclude) basePath: '../', - - // frameworks to use - // available frameworks: https://npmjs.org/browse/keyword/karma-adapter frameworks: ['mocha', 'chai'], - - // list of files / patterns to load in the browser files: [ { pattern: WOMBAT_JS_PATH, @@ -23,46 +61,30 @@ module.exports = function(config) { 'karma-tests/*.spec.js', ], - - // preprocess matching files before serving them to the browser - // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor preprocessors: {}, - - // test results reporter to use - // possible values: 'dots', 'progress' - // available reporters: https://npmjs.org/browse/keyword/karma-reporter reporters: ['progress'], - - // web server port port: 9876, - - // enable / disable colors in the output (reporters and logs) colors: true, - - // level of logging - // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG logLevel: config.LOG_INFO, - - // enable / disable watching file and executing tests whenever any file changes autoWatch: true, + sauceLabs: sauceLabsConfig, - // start these browsers - // available browser launchers: https://npmjs.org/browse/keyword/karma-launcher - browsers: ['Chrome'], + // use an extended timeout for capturing Sauce Labs + // browsers in case the service is busy + captureTimeout: 3 * 60000, + customLaunchers: customLaunchers, + + browsers: Object.keys(customLaunchers), - // Continuous Integration mode - // if true, Karma captures browsers, runs the tests and exits singleRun: false, - // Concurrency level - // how many browser should be started simultanous concurrency: Infinity }) -} +}; diff --git a/karma-tests/wombat.spec.js b/karma-tests/wombat.spec.js index a1b681af..7012da83 100644 --- a/karma-tests/wombat.spec.js +++ b/karma-tests/wombat.spec.js @@ -1,4 +1,5 @@ var WOMBAT_SRC = '../pywb/static/wombat.js'; +var DEFAULT_TIMEOUT = 20000; // creates a new document in an