Skip to content

Commit

Permalink
chore(tests): Ensure TestLoader module load failures are counted as t…
Browse files Browse the repository at this point in the history
…est failures (#541)
  • Loading branch information
bantic committed Mar 15, 2017
1 parent 91041c7 commit 749eec0
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
3 changes: 1 addition & 2 deletions tests/helpers/assertions.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ function comparePostNode(actual, expected, assert, path='root', deepCompare=fals
}
}

export default function registerAssertions() {
export default function registerAssertions(QUnit) {
QUnit.assert.hasElement = function(selector,
message=`hasElement "${selector}"`) {
let found = $(selector);
Expand Down Expand Up @@ -317,5 +317,4 @@ export default function registerAssertions() {
});
}
};

}
25 changes: 25 additions & 0 deletions tests/helpers/module-load-failure.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import TestLoader from 'ember-cli/test-loader';

/**
* Ensures that when the TestLoader failures to load a test module, the error
* is reported. Without this the rest of the full test suite still passes and there is an
* error printed in the console only.
* The technique is from: https://github.com/ember-cli/ember-cli-qunit/blob/master/vendor/ember-cli-qunit/test-loader.js#L55
*/
export default function(QUnit) {
var moduleLoadFailures = [];

TestLoader.prototype.moduleLoadFailure = function(moduleName, error) {
moduleLoadFailures.push(error);
QUnit.module('TestLoader Failures');
QUnit.test(moduleName + ': could not be loaded', function() {
throw error;
});
};

QUnit.done(function() {
if (moduleLoadFailures.length) {
throw new Error('\n' + moduleLoadFailures.join('\n'));
}
});
}
6 changes: 5 additions & 1 deletion tests/test-helpers.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
/* global QUnit */
import registerAssertions from './helpers/assertions';
registerAssertions();
registerAssertions(QUnit);

import registerModuleLoadFailureHandler from './helpers/module-load-failure';
registerModuleLoadFailureHandler(QUnit);

import DOMHelpers from './helpers/dom';
import MobiledocHelpers from './helpers/mobiledoc';
Expand Down

0 comments on commit 749eec0

Please sign in to comment.