diff --git a/addon-test-support/-private/ember-exam-mocha-test-loader.js b/addon-test-support/-private/ember-exam-mocha-test-loader.js index d14bcb77..33a486ad 100644 --- a/addon-test-support/-private/ember-exam-mocha-test-loader.js +++ b/addon-test-support/-private/ember-exam-mocha-test-loader.js @@ -1,10 +1,12 @@ import getUrlParams from './get-url-params'; import splitTestModules from './split-test-modules'; -import { TestLoader } from 'ember-mocha/test-loader'; +import { describe, it } from 'mocha'; + +// get testLoader from 'ember-qunit/test-loader' once a new version get's released +import TestLoader from 'ember-cli-test-loader/test-support/index'; /** - * EmberExamMochaTestLoader extends ember-mocha/test-loader used by `ember test`, since it - * overrides moduleLoadFailure() to log a test failure when a module fails to load + * EmberExamMochaTestLoader extends ember-cli-test-loader used by `ember test` * @class EmberExamMochaTestLoader * @extends {TestLoader} */ @@ -43,6 +45,20 @@ export default class EmberExamMochaTestLoader extends TestLoader { */ unsee() {} + /** + * ensure a test failure is reported if a module cannot be loaded + * + * @param {string} moduleName + * @param {error} error + */ + moduleLoadFailure(moduleName, error) { + describe('TestLoader Failures', function() { + it(moduleName + ': could not be loaded', function() { + throw error; + }); + }); + } + /** * Loads the test modules depending on the urlParam */ diff --git a/addon-test-support/-private/get-test-loader.js b/addon-test-support/-private/get-test-loader.js index 5785b799..dbf54cbc 100644 --- a/addon-test-support/-private/get-test-loader.js +++ b/addon-test-support/-private/get-test-loader.js @@ -1,4 +1,19 @@ -/* globals require, requirejs */ +/* globals require */ + +const emberQunit = 'ember-qunit'; +const emberMocha = 'ember-mocha'; + +/** + * Returns the test framework being used + */ +export function getTestFramework() { + if (require.has(emberQunit)){ + return emberQunit; + } else if (require.has(emberMocha)){ + return emberMocha; + } + return; +} /** * Returns ember-exam-qunit-test-loader or ember-exam-mocha-test-loader @@ -6,13 +21,13 @@ * @export * @returns {Object} */ -export default function getTestLoader() { - if (requirejs.entries['ember-qunit/test-loader']) { +export function getTestLoader() { + if (require.has(emberQunit)){ const EmberExamQUnitTestLoader = require('./ember-exam-qunit-test-loader'); return EmberExamQUnitTestLoader['default']; - } else if (requirejs.entries['ember-mocha/test-loader']) { + } else if (require.has(emberMocha)){ const EmberExamMochaTestLoader = require('./ember-exam-mocha-test-loader'); - return EmberExamMochaTestLoader['default']; + return EmberExamMochaTestLoader['default']; } throw new Error( diff --git a/addon-test-support/load.js b/addon-test-support/load.js index e7c2f4b8..651eac65 100644 --- a/addon-test-support/load.js +++ b/addon-test-support/load.js @@ -1,14 +1,29 @@ import TestemOutput from './-private/patch-testem-output'; -import getTestLoader from './-private/get-test-loader'; +import { getTestLoader } from './-private/get-test-loader'; let loaded = false; +/** + * Equivalent to ember-qunit or ember-mocha's loadTest() except this does not create a new TestLoader instance + * + * @param {*} testLoader + */ +export function loadTests(testLoader) { + if (testLoader === undefined) { + throw new Error( + 'A testLoader instance has not been created. You must call `loadEmberExam()` before calling `loadTest()`.' + ); + } + + testLoader.loadModules(); +} + /** * Setup EmberExamTestLoader to enable ember exam functionalities * * @returns {*} testLoader */ -export default function loadEmberExam() { +export function loadEmberExam() { if (loaded) { // eslint-disable-next-line no-console console.warn('Attempted to load Ember Exam more than once.'); diff --git a/addon-test-support/start.js b/addon-test-support/start.js index afa885f0..46690d55 100644 --- a/addon-test-support/start.js +++ b/addon-test-support/start.js @@ -1,21 +1,7 @@ /* globals require */ -import loadEmberExam from 'ember-exam/test-support/load'; - -/** - * Equivalent to ember-qunit or ember-mocha's loadTest() except this does not create a new TestLoader instance - * - * @param {*} testLoader - */ -function loadTests(testLoader) { - if (testLoader === undefined) { - throw new Error( - 'A testLoader instance has not been created. You must call `loadEmberExam()` before calling `loadTest()`.' - ); - } - - testLoader.loadModules(); -} +import { getTestFramework } from './-private/get-test-loader'; +import { loadEmberExam, loadTests } from 'ember-exam/test-support/load'; /** * Ember-exam's own start function to set up EmberExamTestLoader, load tests and calls start() from @@ -24,14 +10,13 @@ function loadTests(testLoader) { * @param {*} qunitOptions */ export default function start(qunitOptions) { - const framework = require.has('ember-qunit') ? 'qunit' : 'mocha'; const modifiedOptions = qunitOptions || Object.create(null); modifiedOptions.loadTests = false; const testLoader = loadEmberExam(); loadTests(testLoader); - const emberTestFramework = require(`ember-${framework}`); + const emberTestFramework = require(getTestFramework()); if (emberTestFramework.start) { emberTestFramework.start(modifiedOptions);