Provide an option for NOT auto-starting the runner
mike-north opened this issue · 4 comments
Currently this addon kicks off the test runner after waiting for a while (an attempt to address a chrome sourcemap bug that may or may not still exist)
ember-mocha/vendor/ember-mocha/test-loader.js
Lines 35 to 39 in 13be23a
Moving away from this, and toward an "explicit start" model like what's done in ember-qunit would provide us with several improvements
- Get rid of the
setTimeout
hack. Developers can callstart()
whenever appropriate - Provide an opportunity to do things AFTER tests complete loading but BEFORE they start running (currently there's no reasonable opportunity for userland code to run between these two events!)
- Provide userland access to the return value of
mocha.run()
(aRunner
instance) such as subscribing to its events - Pass mocha.run a function to invoke when the run is complete
While I think that there's ample reason to make this the default way to use ember-mocha
, we should at least be able to easily offer an opt-in path for now, without disturbing the public API
related: #208
Hacky workaround:
vendor/mocha-patch.js
(function() {
mocha.originalRun = mocha.run;
mocha.run = function () {};
}());
ember-cli-build.js
app.import('vendor/mocha-patch.js', {
type: 'test'
});
tests/test-helper.js
import Application from '../app';
import config from '../config/environment';
import { setApplication } from '@ember/test-helpers';
setApplication(Application.create(config.APP));
setTimeout(function() {
/** @type {mocha.Runner} */
const runner = mocha.originalRun();
// now we can capture events!
runner.on('suite end', function (evt) {
console.log(evt);
})
}, 400); // < required due to existing 250ms wait in test-loader + some other stuff
@mike-north Did this recently cause you trouble? I have a flaky test that is throwing at mocha.run
now where it was previously warning.
@rondale-sc I did not post this in response to something breaking -- I'm just hoping for better consistency between this addon and ember-qunit
.
We need to work to push forward the same declarative start()
system that exists in ember-qunit. It will likely be "another major bump", but the required app changes are pretty small and the reduction in complexity seems definitely worth it...