From a7a83ada9893d45d50d1440497bff97b1171e365 Mon Sep 17 00:00:00 2001 From: Rob Walch Date: Tue, 22 Nov 2016 14:49:08 -0500 Subject: [PATCH] Wallaby continuous testing configuration https://wallabyjs.com --- src/js/utils/fetch.js | 78 ----------------------------------------- test/config.js | 19 ++++++---- test/tests.js | 1 - test/unit/ajax-test.js | 2 +- test/unit/fetch-test.js | 69 ------------------------------------ wallaby.js | 35 ++++++++++++++++++ 6 files changed, 49 insertions(+), 155 deletions(-) delete mode 100644 src/js/utils/fetch.js delete mode 100644 test/unit/fetch-test.js create mode 100644 wallaby.js diff --git a/src/js/utils/fetch.js b/src/js/utils/fetch.js deleted file mode 100644 index 4437b14950..0000000000 --- a/src/js/utils/fetch.js +++ /dev/null @@ -1,78 +0,0 @@ -define([ - 'utils/underscore', - 'utils/ajax' -], function(_, utilsAjax) { - /* global Promise */ - - var supportArrayBuffer = 'ArrayBuffer' in window; - - function Request(input, options) { - options = options || {}; - this.url = input; - this.credentials = options.credentials || 'omit'; - } - - function Response(xhr) { - this._xhr = xhr; - this.url = xhr.responseURL || ''; - this.status = xhr.status; - this.statusText = xhr.statusText; - this.headers = {/* not implemented */}; - this.ok = this.status >= 200 && this.status < 300; - this.type = 'default'; - this.bodyUsed = false; - } - - Response.prototype.text = function() { - return read(this, this._xhr.responseText); - }; - - Response.prototype.json = function() { - return this.text().then(JSON.parse); - }; - - Response.prototype.arrayBuffer = function() { - if (supportArrayBuffer && ArrayBuffer.prototype.isPrototypeOf(this._xhr.response)) { - return read(this, this._xhr.response); - } - throw new Error('could not read response as ArrayBuffer'); - }; - - function read(response, returnValue) { - if (response.bodyUsed) { - return Promise.reject(new TypeError('Already read')); - } - response.bodyUsed = true; - return Promise.resolve(returnValue); - } - - var fetch = window.fetch && window.fetch.bind(window); - - return { - fetch: fetch || function(request, options) { - - if (_.isString(request)) { - request = new Request(request, options); - } - - return new Promise(function(resolve, reject) { - utilsAjax.ajax({ - url: request.url, - mimeType: '', - responseType: '', - withCredentials: (request.credentials === 'include'), - oncomplete: function(xhr) { - resolve(new Response(xhr)); - }, - onerror: function(message, url, xhr) { - if (xhr.readyState < 4) { - reject(new TypeError(message)); - } else { - resolve(new Response(xhr)); - } - } - }); - }); - } - }; -}); \ No newline at end of file diff --git a/test/config.js b/test/config.js index 2c51269750..d396ad27e8 100644 --- a/test/config.js +++ b/test/config.js @@ -1,7 +1,7 @@ -(function () { +(function() { // This allows us to test modules without loading full player - window.__BUILD_VERSION__ = '7.3.0'; + window.__BUILD_VERSION__ = '7.8.0'; window.__FLASH_VERSION__ = 11.2; window.__REPO__ = ''; window.__SELF_HOSTED__ = true; @@ -20,14 +20,21 @@ if (!('Promise' in window)) { deps.push('polyfills/promise'); } - if (!('console' in window) || !('log' in window.console) ) { + if (!('console' in window) || !('log' in window.console)) { window.console = { - log: function() {} + log: function() { + } }; } - - if (window.__karma__) { + if (window.wallaby) { + window.wallaby.delayStart(); + base = '../../'; + for (var file in window.wallaby.tests) { + deps.push(window.wallaby.tests[file]); + } + callback = window.wallaby.start; + } else if (window.__karma__) { base = '/base/'; for (var file in window.__karma__.files) { if (/test\/unit\/[^\/]+\.js$/.test(file)) { diff --git a/test/tests.js b/test/tests.js index 579d07870f..9c62f310f2 100644 --- a/test/tests.js +++ b/test/tests.js @@ -9,7 +9,6 @@ define([ 'unit/dom-test', 'unit/dfxp-test', 'unit/embed-swf-test', - 'unit/fetch-test', 'unit/extendable-test', 'unit/helpers-test', 'unit/jwplayer-selectplayer-test', diff --git a/test/unit/ajax-test.js b/test/unit/ajax-test.js index ccef4bc41f..33ca6a3d8a 100644 --- a/test/unit/ajax-test.js +++ b/test/unit/ajax-test.js @@ -210,7 +210,7 @@ define([ var done = assert.async(); utils.ajax({ - url: 'failUrl', + url: 'foobar', oncomplete: function() { assert.ok(false, 'expected error callback with invalid "File not found"'); done(); diff --git a/test/unit/fetch-test.js b/test/unit/fetch-test.js deleted file mode 100644 index 4515367561..0000000000 --- a/test/unit/fetch-test.js +++ /dev/null @@ -1,69 +0,0 @@ -define([ - 'test/underscore', - 'utils/fetch' -], function (_, utils) { - /* jshint qunit: true */ - /* global Promise */ - - QUnit.module('utils.fetch'); - var test = QUnit.test.bind(QUnit); - - function errorHandler(assert, done) { - return function(error) { - assert.ok(false, error); - done(); - }; - } - - test('response.text()', function (assert) { - var done = assert.async(); - - var uri = require.toUrl('./data/playlist.json'); - - var promise = utils.fetch(uri) - .then(function(response) { - assert.ok(response.ok, 'fetch response is ok'); - return response.text(); - }).then(function(text) { - assert.ok(_.isString(text), - 'response.text() resolved with string content'); - assert.ok(_.isArray(JSON.parse(text)), - 'content matches expected result'); - done(); - }) - .catch(errorHandler(assert, done)); - - assert.ok(Promise.prototype.isPrototypeOf(promise), - 'utils.fetch returns a Promise'); - }); - - test('response.json()', function (assert) { - var done = assert.async(); - - var uri = require.toUrl('./data/playlist.json'); - - utils.fetch(uri) - .then(function(response) { - assert.ok(response.ok, 'fetch response is ok'); - return response.json(); - }).then(function(json){ - assert.ok(_.isArray(json), - 'response.json() resolved with json content'); - done(); - }) - .catch(errorHandler(assert, done)); - }); - - test('error "File not found" (404)', function (assert) { - var done = assert.async(); - - utils.fetch('failUrl') - .then(function(response) { - assert.notOk(response.ok, 'fetch response is not ok'); - assert.equal(response.status, 404, 'fetch resolves with 404 status'); - done(); - }) - .catch(errorHandler(assert, done)); - }); - -}); diff --git a/wallaby.js b/wallaby.js new file mode 100644 index 0000000000..1542fb4b53 --- /dev/null +++ b/wallaby.js @@ -0,0 +1,35 @@ +module.exports = function() { + return { + files: [ + //3rd Party Code + {pattern: 'node_modules/handlebars/dist/*.js', load: false, instrument: false}, + {pattern: 'node_modules/handlebars-loader/*.js', load: false, instrument: false}, + {pattern: 'node_modules/jquery/dist/*.js', load: false, instrument: false}, + {pattern: 'node_modules/phantomjs-polyfill/*.js', load: false, instrument: false}, + {pattern: 'node_modules/requirejs/require.js', instrument: false}, + {pattern: 'node_modules/requirejs-handlebars/*.js', load: false, instrument: false}, + {pattern: 'node_modules/requirejs-text/*.js', load: false, instrument: false}, + {pattern: 'node_modules/require-less/*.js', load: false, instrument: false}, + {pattern: 'node_modules/simple-style-loader/addStyles.js', load: false, instrument: false}, + {pattern: 'node_modules/underscore/*.js', load: false, instrument: false}, + + // Source + {pattern: 'src/js/**/*.js', load: false}, + {pattern: 'src/css/**/*.less', load: false}, + {pattern: 'src/templates/**/*.html', load: false}, + + // Require Config + {pattern: 'test/config.js', instrument: false}, + + // Test Data + {pattern: 'test/data/*.js', load: false, instrument: false}, + {pattern: 'test/data/*.json', load: false, instrument: false}, + {pattern: 'test/data/*.xml', load: false, instrument: false}, + {pattern: 'test/mock/*.js', load: false, instrument: false}, + ], + tests: [ + {pattern: 'test/unit/*.js', load: false}, + ], + testFramework: 'qunit' + }; +};