Skip to content

Commit

Permalink
feat: add mocha failure messages to console output (google#5984)
Browse files Browse the repository at this point in the history
* feat: add mocha failure messages to console output

* fix: line up the messages
  • Loading branch information
maribethb authored Mar 8, 2022
1 parent 543cb8e commit 7d250fa
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
10 changes: 8 additions & 2 deletions tests/mocha/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
}
</style>
<body>

<div id="mocha"></div>
<div id="failureCount" style="display:none" tests_failed="unset"></div>
<div id="failureMessages" style="display:none"></div>
<script src="../../node_modules/chai/chai.js"></script>
<script src="../../node_modules/mocha/mocha.js"></script>
<script src="../../node_modules/sinon/pkg/sinon.js"></script>
Expand Down Expand Up @@ -173,10 +173,16 @@
</xml>

<script type="module">
mocha.run(function(failures) {
let runner = mocha.run(function(failures) {
var failureDiv = document.getElementById('failureCount');
failureDiv.setAttribute('tests_failed', failures);
});
runner.on('fail', function(test, err) {
const msg = document.createElement('p');
msg.textContent = `"${test.fullTitle()}" failed: ${err.message}`;
const div = document.getElementById('failureMessages');
div.appendChild(msg);
});
</script>
</body>
</html>
12 changes: 11 additions & 1 deletion tests/mocha/run_mocha_tests_in_browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,18 @@ async function runMochaTestsInBrowser() {
const elem = await browser.$('#failureCount');
const numOfFailure = await elem.getAttribute('tests_failed');

if (numOfFailure > 0) {
console.log('============Blockly Mocha Test Failures================')
const failureMessagesEls = await browser.$$('#failureMessages p');
if (!failureMessagesEls.length) {
console.log('There is at least one test failure, but no messages reported. Mocha may be failing because no tests are being run.');
}
for (let el of failureMessagesEls) {
console.log(await el.getText());
}
}

console.log('============Blockly Mocha Test Summary=================');
console.log(numOfFailure);
console.log(numOfFailure + ' tests failed');
console.log('============Blockly Mocha Test Summary=================');
if (parseInt(numOfFailure) !== 0) {
Expand Down

0 comments on commit 7d250fa

Please sign in to comment.