From 8d4e8f11648e4bcd4c91ca1e4b9d7f1e042a0dea Mon Sep 17 00:00:00 2001 From: Joe Fiorini Date: Thu, 9 Jul 2015 11:55:29 -0400 Subject: [PATCH] Reorganize test directory structure --- awx/ui/static/lib/loader.js/loader.js | 6 +- .../directives/job-status-graph-test.js | 4 +- .../features/features.controller-test.js | 2 +- .../features/features.service-test.js | 4 +- .../delete-job-template.service-test.js | 4 +- .../multi-select-list.controller-test.js | 0 .../multi-select-list.directive-test.js | 4 +- .../select-all.directive-test.js | 4 +- awx/ui/tests/phantomjs-polyfill.js | 28 -------- .../services/job-status-graph-data-test.js | 4 +- .../lodash-as-promised-test.js} | 2 +- .../{unit.js => support/browser/index.js} | 0 .../{unit => support}/describe-module.js | 0 awx/ui/tests/support/node/export-global.js | 4 ++ awx/ui/tests/support/node/index.js | 26 +++++++ .../tests/support/node/setup/angular-mocks.js | 5 ++ .../support/node/setup/angular-templates.js | 2 + awx/ui/tests/support/node/setup/angular.js | 5 ++ .../tests/support/node/setup/chai-plugins.js | 8 +++ awx/ui/tests/support/node/setup/chai.js | 5 ++ awx/ui/tests/support/node/setup/d3.js | 6 ++ awx/ui/tests/support/node/setup/jquery.js | 7 ++ awx/ui/tests/support/node/setup/jsdom.js | 6 ++ .../tests/support/node/setup/local-storage.js | 7 ++ awx/ui/tests/support/node/setup/lodash.js | 4 ++ awx/ui/tests/support/node/setup/mocha.js | 7 ++ awx/ui/tests/support/node/setup/moment.js | 5 ++ awx/ui/tests/support/node/setup/nv.js | 6 ++ awx/ui/tests/support/node/setup/sinon.js | 4 ++ awx/ui/tests/{unit => support}/rest-stub.js | 0 .../compare-facts/flat-test.js | 2 +- .../compare-facts/nested-test.js | 2 +- .../single-host-data.service-test.js | 4 +- awx/ui/tests/unit/setup-browser.js | 68 ------------------- 34 files changed, 130 insertions(+), 115 deletions(-) rename awx/ui/tests/{unit => }/directives/job-status-graph-test.js (96%) rename awx/ui/tests/{unit => }/features/features.controller-test.js (96%) rename awx/ui/tests/{unit => }/features/features.service-test.js (94%) rename awx/ui/tests/{unit => }/job-templates/delete-job-template.service-test.js (86%) rename awx/ui/tests/{unit => }/multi-select-list/multi-select-list.controller-test.js (100%) rename awx/ui/tests/{unit => }/multi-select-list/multi-select-list.directive-test.js (98%) rename awx/ui/tests/{unit => }/multi-select-list/select-all.directive-test.js (97%) delete mode 100644 awx/ui/tests/phantomjs-polyfill.js rename awx/ui/tests/{unit => }/services/job-status-graph-data-test.js (96%) rename awx/ui/tests/{unit/shared/lodash-as-promised_test.js => shared/lodash-as-promised-test.js} (98%) rename awx/ui/tests/{unit.js => support/browser/index.js} (100%) rename awx/ui/tests/{unit => support}/describe-module.js (100%) create mode 100644 awx/ui/tests/support/node/export-global.js create mode 100644 awx/ui/tests/support/node/index.js create mode 100644 awx/ui/tests/support/node/setup/angular-mocks.js create mode 100644 awx/ui/tests/support/node/setup/angular-templates.js create mode 100644 awx/ui/tests/support/node/setup/angular.js create mode 100644 awx/ui/tests/support/node/setup/chai-plugins.js create mode 100644 awx/ui/tests/support/node/setup/chai.js create mode 100644 awx/ui/tests/support/node/setup/d3.js create mode 100644 awx/ui/tests/support/node/setup/jquery.js create mode 100644 awx/ui/tests/support/node/setup/jsdom.js create mode 100644 awx/ui/tests/support/node/setup/local-storage.js create mode 100644 awx/ui/tests/support/node/setup/lodash.js create mode 100644 awx/ui/tests/support/node/setup/mocha.js create mode 100644 awx/ui/tests/support/node/setup/moment.js create mode 100644 awx/ui/tests/support/node/setup/nv.js create mode 100644 awx/ui/tests/support/node/setup/sinon.js rename awx/ui/tests/{unit => support}/rest-stub.js (100%) rename awx/ui/tests/{unit => }/system-tracking/compare-facts/flat-test.js (99%) rename awx/ui/tests/{unit => }/system-tracking/compare-facts/nested-test.js (99%) rename awx/ui/tests/{unit => }/system-tracking/single-host-data.service-test.js (96%) delete mode 100644 awx/ui/tests/unit/setup-browser.js diff --git a/awx/ui/static/lib/loader.js/loader.js b/awx/ui/static/lib/loader.js/loader.js index 0c9559c39b..4f3f7f6e38 100644 --- a/awx/ui/static/lib/loader.js/loader.js +++ b/awx/ui/static/lib/loader.js/loader.js @@ -55,7 +55,11 @@ var define, requireModule, require, requirejs; } if (!registry[name]) { - throw new Error('Could not find module ' + name); + name = name + '/index'; + + if (!registry[name]) { + throw new Error('Could not find module ' + name); + } } var mod = registry[name]; diff --git a/awx/ui/tests/unit/directives/job-status-graph-test.js b/awx/ui/tests/directives/job-status-graph-test.js similarity index 96% rename from awx/ui/tests/unit/directives/job-status-graph-test.js rename to awx/ui/tests/directives/job-status-graph-test.js index 0ea4c1265f..f0c49d1ef0 100644 --- a/awx/ui/tests/unit/directives/job-status-graph-test.js +++ b/awx/ui/tests/directives/job-status-graph-test.js @@ -1,8 +1,8 @@ /* jshint node: true */ -import '../setup-browser'; +import '../support/node'; -import {describeModule} from '../describe-module'; +import {describeModule} from '../support/describe-module'; import 'tower/shared/Utilities'; import 'tower/shared/RestServices'; import JobStatusGraph from 'tower/dashboard/graphs/job-status/main'; diff --git a/awx/ui/tests/unit/features/features.controller-test.js b/awx/ui/tests/features/features.controller-test.js similarity index 96% rename from awx/ui/tests/unit/features/features.controller-test.js rename to awx/ui/tests/features/features.controller-test.js index c607cf3d2d..08c159a881 100644 --- a/awx/ui/tests/unit/features/features.controller-test.js +++ b/awx/ui/tests/features/features.controller-test.js @@ -1,4 +1,4 @@ -import '../setup-browser'; +import '../support/node'; import featuresController from 'tower/shared/features/features.controller'; diff --git a/awx/ui/tests/unit/features/features.service-test.js b/awx/ui/tests/features/features.service-test.js similarity index 94% rename from awx/ui/tests/unit/features/features.service-test.js rename to awx/ui/tests/features/features.service-test.js index 62da79c14c..320ed0fd46 100644 --- a/awx/ui/tests/unit/features/features.service-test.js +++ b/awx/ui/tests/features/features.service-test.js @@ -1,7 +1,7 @@ -import '../setup-browser'; +import '../support/node'; import features from 'tower/shared/features/main'; -import {describeModule} from '../describe-module'; +import {describeModule} from '../support/describe-module'; //test that it returns features, as well as test that it is returned in rootScope diff --git a/awx/ui/tests/unit/job-templates/delete-job-template.service-test.js b/awx/ui/tests/job-templates/delete-job-template.service-test.js similarity index 86% rename from awx/ui/tests/unit/job-templates/delete-job-template.service-test.js rename to awx/ui/tests/job-templates/delete-job-template.service-test.js index f30dfd1621..5766287f51 100644 --- a/awx/ui/tests/unit/job-templates/delete-job-template.service-test.js +++ b/awx/ui/tests/job-templates/delete-job-template.service-test.js @@ -1,7 +1,7 @@ -import '../setup-browser'; +import '../support/node'; import jobTemplates from 'tower/job-templates/main'; -import {describeModule} from '../describe-module'; +import {describeModule} from '../support/describe-module'; describeModule(jobTemplates.name) .testService('deleteJobTemplate', function(test, restStub) { diff --git a/awx/ui/tests/unit/multi-select-list/multi-select-list.controller-test.js b/awx/ui/tests/multi-select-list/multi-select-list.controller-test.js similarity index 100% rename from awx/ui/tests/unit/multi-select-list/multi-select-list.controller-test.js rename to awx/ui/tests/multi-select-list/multi-select-list.controller-test.js diff --git a/awx/ui/tests/unit/multi-select-list/multi-select-list.directive-test.js b/awx/ui/tests/multi-select-list/multi-select-list.directive-test.js similarity index 98% rename from awx/ui/tests/unit/multi-select-list/multi-select-list.directive-test.js rename to awx/ui/tests/multi-select-list/multi-select-list.directive-test.js index debd765b1a..5af5770cb2 100644 --- a/awx/ui/tests/unit/multi-select-list/multi-select-list.directive-test.js +++ b/awx/ui/tests/multi-select-list/multi-select-list.directive-test.js @@ -1,6 +1,6 @@ -import '../setup-browser'; +import '../support/node'; -import {describeModule} from '../describe-module'; +import {describeModule} from '../support/describe-module'; import mod from 'tower/shared/multi-select-list/main'; describeModule(mod.name) diff --git a/awx/ui/tests/unit/multi-select-list/select-all.directive-test.js b/awx/ui/tests/multi-select-list/select-all.directive-test.js similarity index 97% rename from awx/ui/tests/unit/multi-select-list/select-all.directive-test.js rename to awx/ui/tests/multi-select-list/select-all.directive-test.js index 9f080cc494..8bdf295111 100644 --- a/awx/ui/tests/unit/multi-select-list/select-all.directive-test.js +++ b/awx/ui/tests/multi-select-list/select-all.directive-test.js @@ -1,6 +1,6 @@ -import '../setup-browser'; +import '../support/node'; -import {describeModule} from '../describe-module'; +import {describeModule} from '../support/describe-module'; import mod from 'tower/shared/multi-select-list/main'; var mockController = { diff --git a/awx/ui/tests/phantomjs-polyfill.js b/awx/ui/tests/phantomjs-polyfill.js deleted file mode 100644 index 46c4204283..0000000000 --- a/awx/ui/tests/phantomjs-polyfill.js +++ /dev/null @@ -1,28 +0,0 @@ -// Phantom.js is missing the standard Function.prototype.bind -// function. See https://code.google.com/p/phantomjs/issues/detail?id=522 -// for more details. -// -if (!Function.prototype.bind) { - Function.prototype.bind = function(oThis) { - if (typeof this !== 'function') { - // closest thing possible to the ECMAScript 5 - // internal IsCallable function - throw new TypeError('Function.prototype.bind - what is trying to be bound is not callable'); - } - - var aArgs = Array.prototype.slice.call(arguments, 1), - fToBind = this, - fNOP = function() {}, - fBound = function() { - return fToBind.apply(this instanceof fNOP - ? this - : oThis, - aArgs.concat(Array.prototype.slice.call(arguments))); - }; - - fNOP.prototype = this.prototype; - fBound.prototype = new fNOP(); - - return fBound; - }; -} diff --git a/awx/ui/tests/unit/services/job-status-graph-data-test.js b/awx/ui/tests/services/job-status-graph-data-test.js similarity index 96% rename from awx/ui/tests/unit/services/job-status-graph-data-test.js rename to awx/ui/tests/services/job-status-graph-data-test.js index d5121cbdcb..e810b7e708 100644 --- a/awx/ui/tests/unit/services/job-status-graph-data-test.js +++ b/awx/ui/tests/services/job-status-graph-data-test.js @@ -1,6 +1,6 @@ -import '../setup-browser'; +import '../support/node'; -import {describeModule} from '../describe-module'; +import {describeModule} from '../support/describe-module'; import JobStatusGraph from 'tower/dashboard/graphs/job-status/main'; var processErrors = sinon.spy(); diff --git a/awx/ui/tests/unit/shared/lodash-as-promised_test.js b/awx/ui/tests/shared/lodash-as-promised-test.js similarity index 98% rename from awx/ui/tests/unit/shared/lodash-as-promised_test.js rename to awx/ui/tests/shared/lodash-as-promised-test.js index d9d01759de..80105306bc 100644 --- a/awx/ui/tests/unit/shared/lodash-as-promised_test.js +++ b/awx/ui/tests/shared/lodash-as-promised-test.js @@ -1,4 +1,4 @@ -import '../setup-browser'; +import '../support/node'; import 'tower/shared/main'; diff --git a/awx/ui/tests/unit.js b/awx/ui/tests/support/browser/index.js similarity index 100% rename from awx/ui/tests/unit.js rename to awx/ui/tests/support/browser/index.js diff --git a/awx/ui/tests/unit/describe-module.js b/awx/ui/tests/support/describe-module.js similarity index 100% rename from awx/ui/tests/unit/describe-module.js rename to awx/ui/tests/support/describe-module.js diff --git a/awx/ui/tests/support/node/export-global.js b/awx/ui/tests/support/node/export-global.js new file mode 100644 index 0000000000..c1fccb23a1 --- /dev/null +++ b/awx/ui/tests/support/node/export-global.js @@ -0,0 +1,4 @@ +module.exports = + function exportGlobal(varName, value) { + global[varName] = global.window[varName] = value; + }; diff --git a/awx/ui/tests/support/node/index.js b/awx/ui/tests/support/node/index.js new file mode 100644 index 0000000000..91ef218cf6 --- /dev/null +++ b/awx/ui/tests/support/node/index.js @@ -0,0 +1,26 @@ +/* jshint node: true */ + +(function() { + var isNode = typeof window === 'undefined'; + + if (!isNode) { + window.expect = chai.expect; + return; + } + + require('./setup/jsdom'); + require('./setup/mocha'); + require('./setup/jquery'); + require('./setup/angular'); + require('./setup/angular-mocks'); + require('./setup/angular-templates'); + require('./setup/sinon'); + require('./setup/chai'); + require('./setup/chai-plugins'); + require('./setup/d3'); + require('./setup/nv'); + require('./setup/lodash'); + require('./setup/local-storage'); + require('./setup/moment'); + +})(); diff --git a/awx/ui/tests/support/node/setup/angular-mocks.js b/awx/ui/tests/support/node/setup/angular-mocks.js new file mode 100644 index 0000000000..fbf1a88ac4 --- /dev/null +++ b/awx/ui/tests/support/node/setup/angular-mocks.js @@ -0,0 +1,5 @@ +var exportGlobal = require('../export-global'); +require('angular-mocks/angular-mocks'); + +exportGlobal('inject', window.inject); + diff --git a/awx/ui/tests/support/node/setup/angular-templates.js b/awx/ui/tests/support/node/setup/angular-templates.js new file mode 100644 index 0000000000..75837d0ad8 --- /dev/null +++ b/awx/ui/tests/support/node/setup/angular-templates.js @@ -0,0 +1,2 @@ +angular.module('templates', []); +require('../../../../templates'); diff --git a/awx/ui/tests/support/node/setup/angular.js b/awx/ui/tests/support/node/setup/angular.js new file mode 100644 index 0000000000..90749a49bc --- /dev/null +++ b/awx/ui/tests/support/node/setup/angular.js @@ -0,0 +1,5 @@ +var exportGlobal = require('../export-global'); +require('angular/angular'); + +exportGlobal('angular', window.angular); + diff --git a/awx/ui/tests/support/node/setup/chai-plugins.js b/awx/ui/tests/support/node/setup/chai-plugins.js new file mode 100644 index 0000000000..dde64dd10c --- /dev/null +++ b/awx/ui/tests/support/node/setup/chai-plugins.js @@ -0,0 +1,8 @@ +var sinonChai = require('sinon-chai'); +var chaiAsPromised = require('chai-as-promised'); +var chaiThings = require('chai-things'); + +chai.use(sinonChai); +chai.use(chaiAsPromised); +chai.use(chaiThings); + diff --git a/awx/ui/tests/support/node/setup/chai.js b/awx/ui/tests/support/node/setup/chai.js new file mode 100644 index 0000000000..570b230185 --- /dev/null +++ b/awx/ui/tests/support/node/setup/chai.js @@ -0,0 +1,5 @@ +var exportGlobal = require('../export-global'); +var chai = require('chai'); + +exportGlobal('chai', chai); +exportGlobal('expect', chai.expect); diff --git a/awx/ui/tests/support/node/setup/d3.js b/awx/ui/tests/support/node/setup/d3.js new file mode 100644 index 0000000000..ec8f384ccb --- /dev/null +++ b/awx/ui/tests/support/node/setup/d3.js @@ -0,0 +1,6 @@ +var exportGlobal = require('../export-global'); +var d3 = require('d3'); + +exportGlobal('d3', d3); + + diff --git a/awx/ui/tests/support/node/setup/jquery.js b/awx/ui/tests/support/node/setup/jquery.js new file mode 100644 index 0000000000..d10af4298c --- /dev/null +++ b/awx/ui/tests/support/node/setup/jquery.js @@ -0,0 +1,7 @@ +var exportGlobal = require('../export-global'); +var jquery = require('jquery'); + +exportGlobal('$', jquery); +exportGlobal('jQuery', jquery); + + diff --git a/awx/ui/tests/support/node/setup/jsdom.js b/awx/ui/tests/support/node/setup/jsdom.js new file mode 100644 index 0000000000..5a5a7b68e5 --- /dev/null +++ b/awx/ui/tests/support/node/setup/jsdom.js @@ -0,0 +1,6 @@ +var jsdom = require('jsdom').jsdom; +var document = jsdom('tower'); +var window = document.parentWindow; + +global.document = document; +global.window = window; diff --git a/awx/ui/tests/support/node/setup/local-storage.js b/awx/ui/tests/support/node/setup/local-storage.js new file mode 100644 index 0000000000..fff3ab7861 --- /dev/null +++ b/awx/ui/tests/support/node/setup/local-storage.js @@ -0,0 +1,7 @@ +var exportGlobal = require('../export-global'); +var LocalStorage = require('node-localstorage').LocalStorage; + +exportGlobal('localStorage', + new LocalStorage('./scratch')); + + diff --git a/awx/ui/tests/support/node/setup/lodash.js b/awx/ui/tests/support/node/setup/lodash.js new file mode 100644 index 0000000000..8af57a2da5 --- /dev/null +++ b/awx/ui/tests/support/node/setup/lodash.js @@ -0,0 +1,4 @@ +var exportGlobal = require('../export-global'); +var lodash = require('lodash'); + +exportGlobal('_', lodash); diff --git a/awx/ui/tests/support/node/setup/mocha.js b/awx/ui/tests/support/node/setup/mocha.js new file mode 100644 index 0000000000..b7d366a4b7 --- /dev/null +++ b/awx/ui/tests/support/node/setup/mocha.js @@ -0,0 +1,7 @@ +var exportGlobal = require('../export-global'); +var mocha = require('mocha'); + +exportGlobal('mocha', mocha); +exportGlobal('beforeEach', beforeEach); +exportGlobal('afterEach', afterEach); + diff --git a/awx/ui/tests/support/node/setup/moment.js b/awx/ui/tests/support/node/setup/moment.js new file mode 100644 index 0000000000..28822e411c --- /dev/null +++ b/awx/ui/tests/support/node/setup/moment.js @@ -0,0 +1,5 @@ +var exportGlobal = require('../export-global'); +var moment = require('moment'); + +exportGlobal('moment', moment); + diff --git a/awx/ui/tests/support/node/setup/nv.js b/awx/ui/tests/support/node/setup/nv.js new file mode 100644 index 0000000000..733b7dbad6 --- /dev/null +++ b/awx/ui/tests/support/node/setup/nv.js @@ -0,0 +1,6 @@ +var exportGlobal = require('../export-global'); +var nv = require('nvd3'); + +exportGlobal('nv', nv); + + diff --git a/awx/ui/tests/support/node/setup/sinon.js b/awx/ui/tests/support/node/setup/sinon.js new file mode 100644 index 0000000000..bfaf5cacec --- /dev/null +++ b/awx/ui/tests/support/node/setup/sinon.js @@ -0,0 +1,4 @@ +var exportGlobal = require('../export-global'); +var sinon = require('sinon'); + +exportGlobal('sinon', sinon); diff --git a/awx/ui/tests/unit/rest-stub.js b/awx/ui/tests/support/rest-stub.js similarity index 100% rename from awx/ui/tests/unit/rest-stub.js rename to awx/ui/tests/support/rest-stub.js diff --git a/awx/ui/tests/unit/system-tracking/compare-facts/flat-test.js b/awx/ui/tests/system-tracking/compare-facts/flat-test.js similarity index 99% rename from awx/ui/tests/unit/system-tracking/compare-facts/flat-test.js rename to awx/ui/tests/system-tracking/compare-facts/flat-test.js index 634a3230c1..c277a19641 100644 --- a/awx/ui/tests/unit/system-tracking/compare-facts/flat-test.js +++ b/awx/ui/tests/system-tracking/compare-facts/flat-test.js @@ -1,6 +1,6 @@ /* jshint node: true */ -import '../../setup-browser'; +import '../../support/node'; import compareFacts from 'tower/system-tracking/compare-facts/flat'; diff --git a/awx/ui/tests/unit/system-tracking/compare-facts/nested-test.js b/awx/ui/tests/system-tracking/compare-facts/nested-test.js similarity index 99% rename from awx/ui/tests/unit/system-tracking/compare-facts/nested-test.js rename to awx/ui/tests/system-tracking/compare-facts/nested-test.js index 5cbed586ca..a7ff98452b 100644 --- a/awx/ui/tests/unit/system-tracking/compare-facts/nested-test.js +++ b/awx/ui/tests/system-tracking/compare-facts/nested-test.js @@ -1,6 +1,6 @@ /* jshint node: true */ -import '../../setup-browser'; +import '../../support/node'; import compareFacts from 'tower/system-tracking/compare-facts/nested'; diff --git a/awx/ui/tests/unit/system-tracking/single-host-data.service-test.js b/awx/ui/tests/system-tracking/single-host-data.service-test.js similarity index 96% rename from awx/ui/tests/unit/system-tracking/single-host-data.service-test.js rename to awx/ui/tests/system-tracking/single-host-data.service-test.js index f8a07498dc..f9da3c2770 100644 --- a/awx/ui/tests/unit/system-tracking/single-host-data.service-test.js +++ b/awx/ui/tests/system-tracking/single-host-data.service-test.js @@ -1,7 +1,7 @@ -import '../setup-browser'; +import '../support/node'; import systemTracking from 'tower/system-tracking/data-services/main'; -import {describeModule} from '../describe-module'; +import {describeModule} from '../support/describe-module'; import moment from 'tower/shared/moment/moment'; describeModule(systemTracking.name) diff --git a/awx/ui/tests/unit/setup-browser.js b/awx/ui/tests/unit/setup-browser.js deleted file mode 100644 index a2b3c3db85..0000000000 --- a/awx/ui/tests/unit/setup-browser.js +++ /dev/null @@ -1,68 +0,0 @@ -/* jshint node: true */ - -(function() { - var isNode = typeof window === 'undefined'; - - if (!isNode) { - window.expect = chai.expect; - return; - } - - setupNode(); - - function setupNode() { - - var jsdom = require('jsdom').jsdom; - var document = jsdom('tower'); - var window = document.parentWindow; - var mocha = require('mocha'); - window.mocha = mocha; - window.beforeEach = beforeEach; - window.afterEach = afterEach; - - global.document = document; - global.window = window; - - var jquery = require('jquery'); - global.$ = window.$ = global.jQuery = window.jQuery = jquery; - - require('angular/angular'); - - require('angular-mocks/angular-mocks'); - - var chai = require('chai'); - var expect = chai.expect; - var sinonChai = require('sinon-chai'); - var chaiAsPromised = require('chai-as-promised'); - var sinon = require('sinon'); - var chaiThings = require('chai-things'); - - chai.use(sinonChai); - chai.use(chaiAsPromised); - chai.use(chaiThings); - - global.angular = window.angular; - global.inject = window.inject; - global.expect = chai.expect; - global.sinon = require('sinon'); - - angular.module('templates', []); - require('../../templates'); - - var d3 = require('d3'); - global.d3 = d3; - - var nv = require('nvd3'); - global.nv = nv; - - var lodash = require('lodash'); - global._ = lodash; - - var LocalStorage = require('node-localstorage').LocalStorage; - global.localStorage = window.localStorage = new LocalStorage('./scratch'); - - var moment = require('moment'); - window.moment = moment; - } - -})();