Skip to content

Commit

Permalink
Add require.js error reporting in tests
Browse files Browse the repository at this point in the history
Adds test coverage for #989
  • Loading branch information
kpdecker committed Apr 8, 2015
1 parent afe730e commit e15af4c
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 4 deletions.
16 changes: 16 additions & 0 deletions spec/amd-runtime.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,16 @@

<script src="/spec/env/common.js"></script>
<script>
var requireFailure;

requirejs.config({
paths: {
'handlebars.runtime': '/dist/handlebars.runtime.amd'
}
});
requirejs.onError = function (err) {
requireFailure = err;
};
</script>
<script>
onload = function(){
Expand Down Expand Up @@ -60,6 +65,17 @@

runner.on('fail', logFailure);

// Inject any require initilizer failures into the first test so they are properly
// reported.
if (requireFailure) {
runner.on('hook end', function(hook){
if (requireFailure) {
runner.uncaught(requireFailure);
requireFailure = undefined;
}
});
}

function logFailure(test, err){

var flattenTitles = function(test){
Expand Down
23 changes: 19 additions & 4 deletions spec/amd.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,17 @@

<script src="/spec/env/common.js"></script>
<script>
var requireFailure;

requirejs.config({
paths: {
handlebars: '/dist/handlebars.amd',
tests: '/tmp/tests'
}
});
requirejs.onError = function (err) {
requireFailure = err;
};

var CompilerContext = {
compile: function(template, options) {
Expand Down Expand Up @@ -79,16 +84,26 @@

runner.on('fail', logFailure);

function logFailure(test, err){
// Inject any require initilizer failures into the first test so they are properly
// reported.
if (requireFailure) {
runner.on('hook end', function(hook){
if (requireFailure) {
runner.uncaught(requireFailure);
requireFailure = undefined;
}
});
}

var flattenTitles = function(test){
function logFailure(test, err){
function flattenTitles(test){
var titles = [];
while (test.parent.title){
titles.push(test.parent.title);
test = test.parent;
}
return titles.reverse();
};
}

failedTests.push({
name: test.title,
Expand All @@ -97,7 +112,7 @@
stack: err.stack,
titles: flattenTitles(test)
});
};
}
});
});
};
Expand Down

0 comments on commit e15af4c

Please sign in to comment.