diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 00000000..20fd7a19 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,3 @@ +[*.js] +indent_style=space +indent_size=4 diff --git a/.gitignore b/.gitignore index d48db0e7..e9ba91e2 100644 --- a/.gitignore +++ b/.gitignore @@ -41,3 +41,6 @@ nosetests.xml .pydevproject .vagrant + +# Node +node_modules/ diff --git a/.travis.yml b/.travis.yml index 77b52ef5..3ddcdff5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,7 +6,14 @@ python: os: - linux -# - osx + +addons: + sauce_connect: true + +cache: + directories: + - $HOME/.cache/pip + - node_modules sudo: false @@ -16,9 +23,15 @@ install: - pip install git+https://github.com/esnme/ultrajson.git - python setup.py -q install - pip install coverage pytest-cov coveralls --use-mirrors + - npm install + +before_script: + - export DISPLAY=:99.0 + - sh -e /etc/init.d/xvfb start script: - python setup.py test + - python setup.py test + - cd karma-tests && make test after_success: coveralls diff --git a/karma-tests/Makefile b/karma-tests/Makefile new file mode 100644 index 00000000..bb80eeec --- /dev/null +++ b/karma-tests/Makefile @@ -0,0 +1,4 @@ +NODE_BIN_DIR=../node_modules/.bin + +test: + $(NODE_BIN_DIR)/karma start --single-run diff --git a/karma-tests/dummy.html b/karma-tests/dummy.html new file mode 100644 index 00000000..52e695fa --- /dev/null +++ b/karma-tests/dummy.html @@ -0,0 +1,9 @@ + + + + + + diff --git a/karma-tests/karma.conf.js b/karma-tests/karma.conf.js new file mode 100644 index 00000000..9972fac9 --- /dev/null +++ b/karma-tests/karma.conf.js @@ -0,0 +1,108 @@ +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 sauceLaunchers = { + sl_chrome: { + base: 'SauceLabs', + browserName: 'chrome', + }, + + sl_firefox: { + base: 'SauceLabs', + browserName: 'firefox', + }, + + sl_safari: { + base: 'SauceLabs', + browserName: 'safari', + platform: 'OS X 10.11', + version: '9.0', + }, + + sl_edge: { + base: 'SauceLabs', + browserName: 'MicrosoftEdge', + }, +}; + +var localLaunchers = { + localFirefox: { + base: 'Firefox', + }, +}; + +var customLaunchers = {}; + +if (process.env['SAUCE_USERNAME'] && process.env['SAUCE_ACCESS_KEY']) { + customLaunchers = sauceLaunchers; +} else { + console.error('Sauce Labs account details not set, ' + + 'Karma tests will be run only against local browsers.' + + 'Set SAUCE_USERNAME and SAUCE_ACCESS_KEY environment variables to ' + + 'run tests against Sauce Labs browsers'); + customLaunchers = localLaunchers; +} + +module.exports = function(config) { + config.set({ + basePath: '../', + + frameworks: ['mocha', 'chai'], + + files: [ + { + pattern: WOMBAT_JS_PATH, + watched: true, + included: false, + served: true, + }, + { + pattern: 'karma-tests/dummy.html', + included: false, + served: true, + }, + 'karma-tests/*.spec.js', + ], + + preprocessors: {}, + + reporters: ['progress'], + + port: 9876, + + colors: true, + + logLevel: config.LOG_INFO, + + autoWatch: true, + + sauceLabs: sauceLabsConfig, + + // Set extended timeouts to account for the slowness + // in connecting to remote browsers (eg. when using + // Sauce Labs) + // + // See https://oligofren.wordpress.com/2014/05/27/running-karma-tests-on-browserstack/ + captureTimeout: 3 * 60000, + browserNoActivityTimeout: 30 * 1000, + browserDisconnectTimeout: 10 * 1000, + browserDisconnectTolerance: 1, + + customLaunchers: customLaunchers, + + browsers: Object.keys(customLaunchers), + + singleRun: false, + + concurrency: Infinity + }) +}; diff --git a/karma-tests/wombat.spec.js b/karma-tests/wombat.spec.js new file mode 100644 index 00000000..56e6af7e --- /dev/null +++ b/karma-tests/wombat.spec.js @@ -0,0 +1,212 @@ +var DEFAULT_TIMEOUT = 20000; + +// creates a new document in an