Skip to content

Commit

Permalink
Merge pull request #281 from Turbo87/test-loader
Browse files Browse the repository at this point in the history
Replace automatic test start via timeout with explicit `start()` call
  • Loading branch information
Turbo87 authored Dec 10, 2018
2 parents 32d025a + 4475c6e commit ed5ac58
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 43 deletions.
30 changes: 30 additions & 0 deletions addon-test-support/ember-mocha/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/* globals mocha */

export { loadTests } from './test-loader';

import { loadTests } from './test-loader';
import describeModule from 'ember-mocha/describe-module';
import describeComponent from 'ember-mocha/describe-component';
import describeModel from 'ember-mocha/describe-model';
Expand Down Expand Up @@ -28,6 +33,31 @@ function setupTest(moduleName) {
return setupTestNew(...arguments);
}

/**
* Instruct Mocha to start the tests.
*/
export function startTests() {
mocha.run();
}


/**
* @method start
* @param {Object} [options] Options to be used for enabling/disabling behaviors
* @param {Boolean} [options.loadTests] If `false` tests will not be loaded automatically.
* @param {Boolean} [options.startTests] If `false` tests will not be automatically started
* (you must run `startTests()` to kick them off).
*/
export function start(options = {}) {
if (options.loadTests !== false) {
loadTests();
}

if (options.startTests !== false) {
startTests();
}
}

export {
describeModule,
describeComponent,
Expand Down
33 changes: 33 additions & 0 deletions addon-test-support/ember-mocha/test-loader.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { describe, it } from 'mocha';
import AbstractTestLoader, {
addModuleIncludeMatcher,
} from 'ember-cli-test-loader/test-support/index';

addModuleIncludeMatcher(function(moduleName) {
return moduleName.match(/\.jshint$/);
});

export class TestLoader extends AbstractTestLoader {
shouldLoadModule(moduleName) {
return !moduleName.match(/^ember-mocha\//)
&& (moduleName.match(/[-_]test$/) || moduleName.match(/\.jshint$/));
}

moduleLoadFailure(moduleName, error) {
describe('TestLoader Failures', function() {
it(moduleName + ': could not be loaded', function() {
throw error;
});
});
}
}

/**
* Load tests following the default patterns:
*
* - The module name ends with `-test` or `_test`
* - The module name ends with `.jshint`
*/
export function loadTests() {
new TestLoader().loadModules();
}
3 changes: 3 additions & 0 deletions blueprints/ember-mocha/files/tests/test-helper.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import Application from '../app';
import config from '../config/environment';
import { setApplication } from '@ember/test-helpers';
import { start } from 'ember-mocha';

setApplication(Application.create(config.APP));

start();
1 change: 0 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ module.exports = {
this.import('vendor/mocha/mocha.css', { type: 'test' });
this.import('vendor/ember-mocha/mocha-configuration.js', { type: 'test' });
this.import('vendor/ember-mocha/ember-mocha-adapter.js', { type: 'test' });
this.import('vendor/ember-mocha/test-loader.js', { type: 'test' });

let addonOptions = this.targetOptions();
let explicitlyDisabledStyles = addonOptions.disableContainerStyles === true;
Expand Down
4 changes: 3 additions & 1 deletion tests/test-helper.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { setResolver } from 'ember-mocha';
import { setResolver, start } from 'ember-mocha';
import resolver from './helpers/resolver';

setResolver(resolver);

start();
41 changes: 0 additions & 41 deletions vendor/ember-mocha/test-loader.js

This file was deleted.

0 comments on commit ed5ac58

Please sign in to comment.