I'm trying to setup blanket to run with my in-browser mocha tests. To do this, I'm following the pattern in the mocha-blanket.js file here, but trying to integrate into my existing runner. I want to add some code to run when the start event is emitted from mocha.
The issue I'm having is that I can't seem to get it to trigger from my adapter. Here is a simple version of an adapter, with just the start event:
function run_mocha() {
mocha.checkLeaks();
mocha.globals(['jQuery']);
mocha.run()
.on('start', function() {
console.log("start2");
});
}
mocha.setup({ ui: 'bdd', timeout: 5000});
My HTML page (without the blanket parts looks like this:
<html>
<head>
<meta charset="utf-8" />
</head>
<body>
<script src="https://code.jquery.com/jquery-3.1.1.js"
integrity="sha256-16cdPddA6VdVInumRGo6IbivbERE8p7CQR3HzTBuELA="
crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/mocha/3.2.0/mocha.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/chai/3.5.0/chai.min.js" type="text/javascript"></script>
<script defer src="sitecode.js"></script>
<script defer src="testsetup.js"></script>
<script defer src="tests.js"></script>
</html>
</body>
Now, when I run run_mocha() in Chrome dev tools, I don't see start2 printed, and breakpoints there aren't hit. I tried to see if it happens during mocha.setup, but also didn't hit the breakpoints there.
So I downloaded mocha.js and noticed this code:
runner.on('start', function () {
console.log("start"); //this line was added by me.
stats.start = new Date();
});
This emits start to the console, so the start event is being fired. Why can't I attach to this event? Other events (suite, test, etc) seem to be working for me.
Thank you for any help!