UNPKG

1.46 kBJavaScriptView Raw
1import * as QUnit from 'qunit';
2import AbstractTestLoader, {
3 addModuleExcludeMatcher,
4 addModuleIncludeMatcher,
5} from 'ember-cli-test-loader/test-support/index';
6
7addModuleExcludeMatcher(function (moduleName) {
8 return QUnit.urlParams.nolint && moduleName.match(/\.(jshint|lint-test)$/);
9});
10
11addModuleIncludeMatcher(function (moduleName) {
12 return moduleName.match(/\.jshint$/);
13});
14
15let moduleLoadFailures = [];
16
17QUnit.done(function () {
18 let length = moduleLoadFailures.length;
19
20 try {
21 if (length === 0) {
22 // do nothing
23 } else if (length === 1) {
24 throw moduleLoadFailures[0];
25 } else {
26 throw new Error('\n' + moduleLoadFailures.join('\n'));
27 }
28 } finally {
29 // ensure we release previously captured errors.
30 moduleLoadFailures = [];
31 }
32});
33
34export class TestLoader extends AbstractTestLoader {
35 moduleLoadFailure(moduleName, error) {
36 moduleLoadFailures.push(error);
37
38 QUnit.module('TestLoader Failures');
39 QUnit.test(moduleName + ': could not be loaded', function () {
40 throw error;
41 });
42 }
43}
44
45/**
46 Load tests following the default patterns:
47
48 * The module name ends with `-test`
49 * The module name ends with `.jshint`
50
51 Excludes tests that match the following
52 patterns when `?nolint` URL param is set:
53
54 * The module name ends with `.jshint`
55 * The module name ends with `-lint-test`
56
57 @method loadTests
58 */
59export function loadTests() {
60 new TestLoader().loadModules();
61}