Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace automatic test start via timeout with explicit start() call #281

Merged
merged 5 commits into from
Dec 10, 2018
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
32 changes: 32 additions & 0 deletions addon-test-support/ember-mocha/test-loader.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
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(/[-_]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.