Skip to content

Commit

Permalink
test(bundle): adding ability to run unit tests agains built bundle
Browse files Browse the repository at this point in the history
  • Loading branch information
rodneyrehm committed Apr 25, 2016
1 parent 9dfe765 commit 829484e
Show file tree
Hide file tree
Showing 3 changed files with 175 additions and 59 deletions.
27 changes: 27 additions & 0 deletions test/browser.bundle.js
@@ -0,0 +1,27 @@
define(function(require) {
'use strict';

var config = require('./browser');
var allyModules = require('./helper/ally-modules');
var allyBundle = require('../dist/ally.min');

// intercept all ally.js modules and redirect them to
// the functions exposed in the built bundle
allyModules.map(function(namespace, module, internal) {
if (!namespace || internal) {
// not all modules are exposed in the dist bundle,
// but we'll want to run tests regardless
return;
}

var path = 'ally/' + namespace + '/' + module;
// for some reason the loader won't resolve this
// define(path, ['dist/ally.min'], function(ally) {});
define(path, [], function() {
var _module = allyModules.camelCase(module);
return allyBundle[namespace][_module];
});
});

return config;
});
142 changes: 142 additions & 0 deletions test/helper/ally-modules.js
@@ -0,0 +1,142 @@
define([], function() {
'use strict';

// to ignore sorting for now, we'll simply use what the core.worker.test requires:
// because all files are loaded in the same worker,
// we'll load the ones with the fewest dependencies first,
// so we don't hit timeouts caused by slow networks or VMs
var source = {
event: [
'active-element',
'shadow-focus',
],
prototype: [
'element.prototype.matches',
'window.customevent',
],
util: [
'context-to-element',
'decorate-context',
'decorate-service',
'merge-dom-order',
'node-array',
'tabindex-value',
'visible-area',
],
is: [
'disabled',
'active-element',
'focus-relevant',
'focusable',
'native-disabled-supported',
'only-tabbable',
'shadowed',
'tabbable',
'valid-area',
'valid-tabindex',
'visible',
],
get: [
'active-elements',
'focus-redirect-target',
'focus-target',
'insignificant-branches',
'parents',
'shadow-host-parents',
'shadow-host',
],
element: [
'blur',
'disabled',
'focus',
],
observe: [
'interaction-type',
'shadow-mutations',
],
query: [
'first-tabbable',
'focusable',
'shadow-hosts',
'tabbable',
'tabsequence.sort-area',
'tabsequence.sort-tabindex',
'tabsequence',
],
style: [
'focus-within',
'focus-source',
],
when: [
'focusable',
'key',
'visible-area',
],
fix: [
'pointer-focus-children',
'pointer-focus-input',
'pointer-focus-parent',
],
maintain: [
'disabled',
'hidden',
'tab-focus',
],
};

var internal = {
prototype: [
'element.prototype.matches',
'window.customevent',
],
util: [
'context-to-element',
'decorate-context',
'decorate-service',
'merge-dom-order',
'node-array',
'tabindex-value',
'visible-area',
],
is: [
'native-disabled-supported',
],
query: [
'tabsequence.sort-area',
'tabsequence.sort-tabindex',
],
};

function isInternal(namespace, name) {
return Boolean(internal[namespace] && internal[namespace].indexOf(name) !== -1);
}

function map(callback) {
var list = [];
Object.keys(source).forEach(function(namespace) {
source[namespace].forEach(function(name) {
list.push(callback(namespace, name, isInternal(namespace, name)));
});
});

list.push(callback(null, 'version'));
list.push(callback(null, 'ally'));

return list;
}

function camelCase(name) {
return name.replace(/-([a-z])/g, function(m, c) {
return c.toUpperCase();
});
}

return {
source: source,
internal: internal,
isInternal: isInternal,
camelCase: camelCase,
map: map,
};

});
65 changes: 6 additions & 59 deletions test/unit/core.worker.test.js
Expand Up @@ -4,69 +4,16 @@ define(function(require) {
var registerSuite = require('intern!object');
var expect = require('intern/chai!expect');
var TestWorker = require('../helper/test-worker');
var allyModules = require('../helper/ally-modules');

registerSuite(function() {
var worker;

// because all files are loaded in the same worker,
// we'll load the ones with the fewest dependencies first,
// so we don't hit timeouts caused by slow networks or VMs
var modules = [
'ally.js/event/active-element',
'ally.js/event/shadow-focus',
'ally.js/prototype/element.prototype.matches',
'ally.js/prototype/window.customevent',
'ally.js/util/context-to-element',
'ally.js/util/decorate-context',
'ally.js/util/decorate-service',
'ally.js/util/merge-dom-order',
'ally.js/util/node-array',
'ally.js/util/tabindex-value',
'ally.js/util/visible-area',
'ally.js/is/disabled',
'ally.js/is/active-element',
'ally.js/is/focus-relevant',
'ally.js/is/focusable',
'ally.js/is/native-disabled-supported',
'ally.js/is/only-tabbable',
'ally.js/is/shadowed',
'ally.js/is/tabbable',
'ally.js/is/valid-area',
'ally.js/is/valid-tabindex',
'ally.js/is/visible',
'ally.js/get/active-elements',
'ally.js/get/focus-redirect-target',
'ally.js/get/focus-target',
'ally.js/get/insignificant-branches',
'ally.js/get/parents',
'ally.js/get/shadow-host-parents',
'ally.js/get/shadow-host',
'ally.js/element/blur',
'ally.js/element/disabled',
'ally.js/element/focus',
'ally.js/observe/interaction-type',
'ally.js/observe/shadow-mutations',
'ally.js/query/first-tabbable',
'ally.js/query/focusable',
'ally.js/query/shadow-hosts',
'ally.js/query/tabbable',
'ally.js/query/tabsequence.sort-area',
'ally.js/query/tabsequence.sort-tabindex',
'ally.js/query/tabsequence',
'ally.js/style/focus-within',
'ally.js/style/focus-source',
'ally.js/when/focusable',
'ally.js/when/key',
'ally.js/when/visible-area',
'ally.js/version',
'ally.js/fix/pointer-focus-children',
'ally.js/fix/pointer-focus-input',
'ally.js/fix/pointer-focus-parent',
'ally.js/maintain/disabled',
'ally.js/maintain/hidden',
'ally.js/maintain/tab-focus',
'ally.js/ally',
];
// 'ally.js/<namespace>/<module>'
// 'ally.js/<module>'
var modules = allyModules.map(function(namespace, module) {
return ['ally.js', namespace, module].filter(Boolean).join('/');
});

var suite = {
name: 'core: WebWorker',
Expand Down

0 comments on commit 829484e

Please sign in to comment.