ember-material-icons
Version:
Google Material icons for your ember-cli app
127 lines (101 loc) • 3.4 kB
JavaScript
import Ember from 'ember';
import QUnit from 'qunit';
import { QUnitAdapter } from 'ember-qunit';
import AbstractTestLoader, {
addModuleExcludeMatcher,
addModuleIncludeMatcher
} from 'ember-cli-test-loader/test-support/index';
addModuleExcludeMatcher(function(moduleName) {
return QUnit.urlParams.nolint &&
moduleName.match(/\.(jshint|lint-test)$/);
});
addModuleIncludeMatcher(function(moduleName) {
return moduleName.match(/\.jshint$/);
});
let moduleLoadFailures = [];
QUnit.done(function() {
if (moduleLoadFailures.length) {
throw new Error('\n' + moduleLoadFailures.join('\n'));
}
});
export class TestLoader extends AbstractTestLoader {
moduleLoadFailure(moduleName, error) {
moduleLoadFailures.push(error);
QUnit.module('TestLoader Failures');
QUnit.test(moduleName + ': could not be loaded', function() {
throw error;
});
}
}
/**
Uses current URL configuration to setup the test container.
* If `?nocontainer` is set, the test container will be hidden.
* If `?dockcontainer` or `?devmode` are set the test container will be
absolutely positioned.
* If `?devmode` is set, the test container will be made full screen.
@method setupTestContainer
*/
export function setupTestContainer() {
let testContainer = document.getElementById('ember-testing-container');
if (!testContainer) { return; }
let params = QUnit.urlParams;
let containerVisibility = params.nocontainer ? 'hidden' : 'visible';
let containerPosition = (params.dockcontainer || params.devmode) ? 'absolute' : 'relative';
if (params.devmode) {
testContainer.className = ' full-screen';
}
testContainer.style.visibility = containerVisibility;
testContainer.style.position = containerPosition;
}
/**
Load tests following the default patterns:
* The module name ends with `-test`
* The module name ends with `.jshint`
Excludes tests that match the following
patterns when `?nolint` URL param is set:
* The module name ends with `.jshint`
* The module name ends with `-lint-test`
@method loadTests
*/
export function loadTests() {
new TestLoader().loadModules();
}
/**
Instruct QUnit to start the tests.
@method startTests
*/
export function startTests() {
QUnit.start();
}
/**
Sets up the `Ember.Test` adapter for usage with QUnit 2.x.
@method setupTestAdapter
*/
export function setupTestAdapter() {
Ember.Test.adapter = QUnitAdapter.create();
}
/**
@method start
@param {Object} [options] Options to be used for enabling/disabling behaviors
@param {Boolean} [options.loadTests] If `false` tests will not be loaded automatically.
@param {Boolean} [options.setupTestContainer] If `false` the test container will not
be setup based on `devmode`, `dockcontainer`, or `nocontainer` URL params.
@param {Boolean} [options.startTests] If `false` tests will not be automatically started
(you must run `QUnit.start()` to kick them off).
@param {Boolean} [options.setupTestAdapter] If `false` the default Ember.Test adapter will
not be updated.
*/
export function start(options = { }) {
if (options.loadTests !== false) {
loadTests();
}
if (options.setupTestContainer !== false) {
setupTestContainer();
}
if (options.setupTestAdapter !== false) {
setupTestAdapter();
}
if (options.startTests !== false) {
startTests();
}
}