mirror of
https://github.com/ansible/awx.git
synced 2026-01-16 12:20:45 -03:30
Make front-end tests run in node
This commit is contained in:
parent
d2440f6cd7
commit
f1fe118c10
@ -7,9 +7,9 @@ function moment() {
|
||||
// lists the user's preferred languages, the first in the array
|
||||
// being the user's top choice. navigator.languages is currently
|
||||
// comptabile with chrome>v32, ffox>32, but not IE/Safari
|
||||
var lang = navigator.languages ?
|
||||
navigator.languages[0] :
|
||||
(navigator.language || navigator.userLanguage);
|
||||
var lang = window.navigator.languages ?
|
||||
window.navigator.languages[0] :
|
||||
(window.navigator.language || window.navigator.userLanguage);
|
||||
|
||||
originalMoment.locale(lang);
|
||||
return originalMoment.apply(this, arguments);
|
||||
|
||||
@ -2,9 +2,10 @@ import factScanDataService from './fact-scan-data.service';
|
||||
import getDataForComparison from './get-data-for-comparison.factory';
|
||||
import getModuleOptions from './get-module-options.factory';
|
||||
import resolveEmptyVersions from './resolve-empty-versions.factory';
|
||||
import shared from 'tower/shared/main';
|
||||
|
||||
export default
|
||||
angular.module('systemTracking.dataServices', [])
|
||||
angular.module('systemTracking.dataServices', [shared.name])
|
||||
.factory('getModuleOptions', getModuleOptions)
|
||||
.factory('getDataForComparison', getDataForComparison)
|
||||
.factory('resolveEmptyVersions', resolveEmptyVersions)
|
||||
|
||||
5
awx/ui/tests/.jshintrc
Normal file
5
awx/ui/tests/.jshintrc
Normal file
@ -0,0 +1,5 @@
|
||||
{
|
||||
"expr": true,
|
||||
"esnext": true,
|
||||
"node": true
|
||||
}
|
||||
@ -1,4 +1,4 @@
|
||||
import RestStub from 'tests/unit/rest-stub';
|
||||
import RestStub from './rest-stub';
|
||||
|
||||
var $provide;
|
||||
|
||||
@ -7,7 +7,7 @@ function wrapInjected(dslFn) {
|
||||
// }));
|
||||
return function(fn) {
|
||||
dslFn.apply(this,
|
||||
[inject(
|
||||
[window.inject(
|
||||
[ '$injector',
|
||||
function($injector) {
|
||||
var $compile = $injector.get('$compile');
|
||||
@ -28,18 +28,19 @@ function TestModule(name, deps) {
|
||||
registerPreHooks: function() {
|
||||
|
||||
var self = this;
|
||||
beforeEach("tower module", module('Tower'));
|
||||
beforeEach(name + " module", module(name));
|
||||
beforeEach("templates module", module('templates'));
|
||||
beforeEach("mock app setup", module(['$provide', function(_provide_) {
|
||||
// beforeEach("tower module", window.module('Tower'));
|
||||
beforeEach(name + " module", window.module(name));
|
||||
beforeEach("templates module", window.module('templates'));
|
||||
beforeEach("mock app setup", window.module(['$provide', function(_provide_) {
|
||||
|
||||
var getBasePath = function(path) {
|
||||
return '/' + path + '/';
|
||||
}
|
||||
};
|
||||
|
||||
$provide = _provide_;
|
||||
$provide.value('LoadBasePaths', angular.noop);
|
||||
$provide.value('GetBasePath', getBasePath);
|
||||
$provide.value('ProcessErrors', angular.noop);
|
||||
|
||||
for (var name in self.mockedProviders) {
|
||||
$provide.value(name, self.mockedProviders[name]);
|
||||
@ -47,12 +48,12 @@ function TestModule(name, deps) {
|
||||
|
||||
}]));
|
||||
|
||||
wrapInjected(beforeEach)(function($httpBackend) {
|
||||
// wrapInjected(beforeEach)(function($httpBackend) {
|
||||
|
||||
$httpBackend
|
||||
.expectGET('/static/js/local_config.js')
|
||||
.respond({});
|
||||
});
|
||||
// $httpBackend
|
||||
// .expectGET('/static/js/local_config.js')
|
||||
// .respond({});
|
||||
// });
|
||||
},
|
||||
mockProvider: function(name, value) {
|
||||
this.mockedProviders[name] = value;
|
||||
@ -64,7 +65,7 @@ function TestModule(name, deps) {
|
||||
});
|
||||
},
|
||||
registerPostHooks: function() {
|
||||
afterEach(inject(['$httpBackend', function($httpBackend) {
|
||||
afterEach(window.inject(['$httpBackend', function($httpBackend) {
|
||||
$httpBackend.verifyNoOutstandingExpectation();
|
||||
$httpBackend.verifyNoOutstandingRequest();
|
||||
}]));
|
||||
@ -81,7 +82,7 @@ function TestService(name) {
|
||||
|
||||
return {
|
||||
withService: function(fn) {
|
||||
beforeEach(name + " service", inject([name, function() {
|
||||
beforeEach(name + " service", window.inject([name, function() {
|
||||
var service = arguments[0];
|
||||
fn(service);
|
||||
}]));
|
||||
@ -104,7 +105,7 @@ function TestDirective(name, deps) {
|
||||
// by the test
|
||||
withScope: function(fn) {
|
||||
var self = this;
|
||||
beforeEach("capture outer $scope", inject(['$rootScope', function($rootScope) {
|
||||
beforeEach("capture outer $scope", window.inject(['$rootScope', function($rootScope) {
|
||||
var $scope = self.$scope = self.$scope || $rootScope.$new();
|
||||
// `this` refers to mocha test suite
|
||||
fn.apply(this, [$scope]);
|
||||
@ -112,7 +113,7 @@ function TestDirective(name, deps) {
|
||||
},
|
||||
withIsolateScope: function(fn) {
|
||||
var self = this;
|
||||
beforeEach("capture isolate scope", inject(['$rootScope', function($rootScope) {
|
||||
beforeEach("capture isolate scope", window.inject(['$rootScope', function($rootScope) {
|
||||
// `this` refers to mocha test suite
|
||||
fn.apply(this, [self.$element.isolateScope()]);
|
||||
}]));
|
||||
@ -165,7 +166,7 @@ function TestDirective(name, deps) {
|
||||
}
|
||||
|
||||
beforeEach("compile directive element",
|
||||
inject(['$compile', '$httpBackend', '$rootScope', function($compile, $httpBackend, $rootScope) {
|
||||
window.inject(['$compile', '$httpBackend', '$rootScope', function($compile, $httpBackend, $rootScope) {
|
||||
|
||||
if (!self.$scope) {
|
||||
self.$scope = $rootScope.$new();
|
||||
@ -176,13 +177,14 @@ function TestDirective(name, deps) {
|
||||
|
||||
self.$scope.$digest();
|
||||
|
||||
$httpBackend.flush();
|
||||
// $httpBackend.flush();
|
||||
|
||||
}]));
|
||||
|
||||
afterEach("cleanup directive element", function() {
|
||||
self.$element.trigger('$destroy');
|
||||
$(self.$element).trigger('$destroy');
|
||||
self.$element.remove();
|
||||
delete self.$scope;
|
||||
});
|
||||
|
||||
this._compileRegistered = true;
|
||||
@ -200,7 +202,7 @@ function TestDirective(name, deps) {
|
||||
},
|
||||
provideTemplate: function(url, template) {
|
||||
var $scope = this.$scope;
|
||||
beforeEach("mock template endpoint", inject(['$httpBackend', function($httpBackend) {
|
||||
beforeEach("mock template endpoint", window.inject(['$httpBackend', function($httpBackend) {
|
||||
$httpBackend
|
||||
.whenGET(url)
|
||||
.respond(template);
|
||||
@ -233,7 +235,7 @@ function ModuleDescriptor(name, deps) {
|
||||
testModule.mockProvider('$cookieStore', { get: angular.noop });
|
||||
testModule.registerPreHooks();
|
||||
|
||||
beforeEach("$q", inject(['$q', function($q) {
|
||||
beforeEach("$q", window.inject(['$q', function($q) {
|
||||
testService.restStub.$q = $q;
|
||||
}]));
|
||||
|
||||
|
||||
@ -1,11 +1,22 @@
|
||||
import Tower from 'tower/app';
|
||||
import {describeModule} from 'tests/unit/describe-module';
|
||||
import JobStatusGraph from 'tower/dashboard/graphs/job-status/main'
|
||||
/* jshint node: true */
|
||||
|
||||
import '../setup-browser';
|
||||
|
||||
import {describeModule} from '../describe-module';
|
||||
import 'tower/shared/Utilities';
|
||||
import 'tower/shared/RestServices';
|
||||
import JobStatusGraph from 'tower/dashboard/graphs/job-status/main';
|
||||
|
||||
var sinon = require('sinon');
|
||||
|
||||
var resizeHandler = sinon.spy();
|
||||
|
||||
window.$.fn.removeResize = angular.noop;
|
||||
|
||||
describeModule(JobStatusGraph.name)
|
||||
.mockProvider('adjustGraphSize', resizeHandler)
|
||||
.mockProvider('Wait', angular.noop)
|
||||
.mockProvider('Rest', angular.noop)
|
||||
.testDirective('jobStatusGraph', function(directive) {
|
||||
|
||||
|
||||
|
||||
@ -1,8 +1,10 @@
|
||||
import '../setup-browser';
|
||||
|
||||
import featuresController from 'tower/shared/features/features.controller';
|
||||
|
||||
describe('featuresController', function() {
|
||||
|
||||
it('checks if a feature is enabled', inject(['$rootScope', function($rootScope) {
|
||||
it('checks if a feature is enabled', window.inject(['$rootScope', function($rootScope) {
|
||||
var actual;
|
||||
|
||||
$rootScope.features = {
|
||||
|
||||
@ -1,3 +1,5 @@
|
||||
import '../setup-browser';
|
||||
|
||||
import features from 'tower/shared/features/main';
|
||||
import {describeModule} from '../describe-module';
|
||||
|
||||
@ -31,7 +33,7 @@ describeModule(features.name)
|
||||
|
||||
});
|
||||
|
||||
it('caches in rootScope', inject(['$rootScope',
|
||||
it('caches in rootScope', window.inject(['$rootScope',
|
||||
function($rootScope){
|
||||
var features = {},
|
||||
result = {
|
||||
|
||||
@ -1,3 +1,5 @@
|
||||
import '../setup-browser';
|
||||
|
||||
import jobTemplates from 'tower/job-templates/main';
|
||||
import {describeModule} from '../describe-module';
|
||||
|
||||
|
||||
@ -1,5 +1,8 @@
|
||||
import {describeModule} from 'tests/unit/describe-module';
|
||||
import '../setup-browser';
|
||||
|
||||
import {describeModule} from '../describe-module';
|
||||
import mod from 'tower/shared/multi-select-list/main';
|
||||
var sinon = require('sinon');
|
||||
|
||||
describeModule(mod.name)
|
||||
.testDirective('multiSelectList', function(test) {
|
||||
@ -18,9 +21,9 @@ describeModule(mod.name)
|
||||
});
|
||||
|
||||
it('works as an attribute on elements', function() {
|
||||
inject(['$compile', function($compile) {
|
||||
window.inject(['$compile', function($compile) {
|
||||
var node = $compile('<div multi-select-list></div>')($scope);
|
||||
var classes = Array.prototype.slice.apply(node[0].classList)
|
||||
var classes = Array.prototype.slice.apply(node.attr('class').split(' '));
|
||||
expect(classes).to.contain('ng-scope');
|
||||
}]);
|
||||
});
|
||||
|
||||
@ -1,4 +1,9 @@
|
||||
import {describeModule} from 'tests/unit/describe-module';
|
||||
import '../setup-browser';
|
||||
|
||||
import {describeModule} from '../describe-module';
|
||||
import mod from 'tower/shared/multi-select-list/main';
|
||||
|
||||
var sinon = require('sinon');
|
||||
|
||||
var mockController = {
|
||||
selectAll: sinon.spy(),
|
||||
@ -7,7 +12,7 @@ var mockController = {
|
||||
deselectAllExtended: sinon.spy()
|
||||
};
|
||||
|
||||
describeModule('multiSelectList')
|
||||
describeModule(mod.name)
|
||||
.testDirective('selectAll', function(directive) {
|
||||
|
||||
var $scope;
|
||||
@ -36,7 +41,7 @@ describeModule('multiSelectList')
|
||||
});
|
||||
|
||||
it('works as an element tag', function() {
|
||||
var classes = Array.prototype.slice.apply(directive.$element[0].classList);
|
||||
var classes = directive.$element.attr('class').split(' ');
|
||||
expect(classes).to.contain('ng-scope');
|
||||
});
|
||||
|
||||
@ -91,4 +96,4 @@ describeModule('multiSelectList')
|
||||
|
||||
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@ -63,7 +63,7 @@ RestStub.prototype =
|
||||
inject(['$rootScope', function($rootScope) {
|
||||
$rootScope.$apply();
|
||||
}]);
|
||||
}, 1000);
|
||||
}, 10);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@ -1,5 +1,9 @@
|
||||
import {describeModule} from 'tests/unit/describe-module';
|
||||
import JobStatusGraph from 'tower/dashboard/graphs/job-status/main'
|
||||
import '../setup-browser';
|
||||
|
||||
import {describeModule} from '../describe-module';
|
||||
import JobStatusGraph from 'tower/dashboard/graphs/job-status/main';
|
||||
|
||||
var sinon = require('sinon');
|
||||
|
||||
var processErrors = sinon.spy();
|
||||
|
||||
|
||||
@ -1,3 +1,5 @@
|
||||
/* jshint node: true */
|
||||
|
||||
var jsdom = require('jsdom').jsdom;
|
||||
var document = jsdom('tower');
|
||||
var window = document.parentWindow;
|
||||
@ -9,8 +11,11 @@ window.afterEach = afterEach;
|
||||
global.document = document;
|
||||
global.window = window;
|
||||
|
||||
require('angular/angular');
|
||||
var jquery = require('jquery');
|
||||
global.$ = window.$ = global.jQuery = window.jQuery = jquery;
|
||||
|
||||
require('angular/angular');
|
||||
|
||||
require('angular-mocks/angular-mocks');
|
||||
|
||||
var chai = require('chai');
|
||||
@ -24,16 +29,24 @@ chai.use(sinonChai);
|
||||
chai.use(chaiAsPromised);
|
||||
chai.use(chaiThings);
|
||||
|
||||
global.$ = window.$ = jquery;
|
||||
global.angular = window.angular;
|
||||
global.inject = window.inject;
|
||||
global.expect = chai.expect;
|
||||
|
||||
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;
|
||||
|
||||
@ -1,3 +1,5 @@
|
||||
import '../setup-browser';
|
||||
|
||||
import 'tower/shared/main';
|
||||
|
||||
describe('LodashAsPromised', function() {
|
||||
@ -17,7 +19,7 @@ describe('LodashAsPromised', function() {
|
||||
return memo + value;
|
||||
}
|
||||
|
||||
beforeEach(module('shared'));
|
||||
beforeEach(window.module('shared'));
|
||||
|
||||
beforeEach(inject(['lodashAsPromised', '$q', function(_lodash, _$q) {
|
||||
_ = _lodash;
|
||||
|
||||
@ -1,33 +1,32 @@
|
||||
import compareFacts from 'tower/system-tracking/compare-facts/flat';
|
||||
|
||||
/* jshint node: true */
|
||||
/* globals -expect, -_ */
|
||||
|
||||
var _, expect;
|
||||
import '../../setup-browser';
|
||||
|
||||
import compareFacts from 'tower/system-tracking/compare-facts/flat';
|
||||
|
||||
// This makes this test runnable in node OR karma. The sheer
|
||||
// number of times I had to run this test made the karma
|
||||
// workflow just too dang slow for me. Maybe this can
|
||||
// be a pattern going forward? Not sure...
|
||||
//
|
||||
(function(global) {
|
||||
var chai = global.chai || require('chai');
|
||||
// (function(global) {
|
||||
// var chai = global.chai || require('chai');
|
||||
|
||||
if (typeof window === 'undefined') {
|
||||
var chaiThings = global.chaiThings || require('chai-things');
|
||||
chai.use(chaiThings);
|
||||
}
|
||||
// if (typeof window === 'undefined') {
|
||||
// var chaiThings = global.chaiThings || require('chai-things');
|
||||
// chai.use(chaiThings);
|
||||
// }
|
||||
|
||||
_ = global._ || require('lodash');
|
||||
expect = global.expect || chai.expect;
|
||||
// _ = global._ || require('lodash');
|
||||
// expect = global.expect || chai.expect;
|
||||
|
||||
global.expect = expect;
|
||||
// global.expect = expect;
|
||||
|
||||
|
||||
|
||||
global._ = _;
|
||||
// global._ = _;
|
||||
|
||||
})(typeof window === 'undefined' ? global : window);
|
||||
// })(typeof window === 'undefined' ? global : window);
|
||||
|
||||
describe('CompareFacts.Flat', function() {
|
||||
|
||||
|
||||
@ -1,34 +1,8 @@
|
||||
import compareFacts from 'tower/system-tracking/compare-facts/nested';
|
||||
|
||||
/* jshint node: true */
|
||||
/* globals -expect, -_ */
|
||||
|
||||
var _, expect;
|
||||
|
||||
// This makes this test runnable in node OR karma. The sheer
|
||||
// number of times I had to run this test made the karma
|
||||
// workflow just too dang slow for me. Maybe this can
|
||||
// be a pattern going forward? Not sure...
|
||||
//
|
||||
(function(global) {
|
||||
var chai = global.chai || require('chai');
|
||||
|
||||
if (typeof window === 'undefined') {
|
||||
var chaiThings = global.chaiThings || require('chai-things');
|
||||
chai.use(chaiThings);
|
||||
}
|
||||
|
||||
_ = global._ || require('lodash');
|
||||
expect = global.expect || chai.expect;
|
||||
|
||||
global.expect = expect;
|
||||
|
||||
|
||||
|
||||
global._ = _;
|
||||
|
||||
})(typeof window === 'undefined' ? global : window);
|
||||
import '../../setup-browser';
|
||||
|
||||
import compareFacts from 'tower/system-tracking/compare-facts/nested';
|
||||
|
||||
describe('CompareFacts.Nested', function() {
|
||||
|
||||
|
||||
@ -1,4 +1,6 @@
|
||||
import systemTracking from 'tower/system-tracking/main';
|
||||
import '../setup-browser';
|
||||
|
||||
import systemTracking from 'tower/system-tracking/data-services/main';
|
||||
import {describeModule} from '../describe-module';
|
||||
import moment from 'tower/shared/moment/moment';
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user