Skip to content

Commit

Permalink
Merge pull request #366 from Turbo87/deprecate-old-apis
Browse files Browse the repository at this point in the history
Deprecate `setupTest()`, `setupComponentTest()`, `setupModelTest()` and `setupAcceptanceTest()` functions
  • Loading branch information
Turbo87 authored May 11, 2019
2 parents 5412e76 + c7be040 commit 3673b83
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
8 changes: 4 additions & 4 deletions addon-test-support/ember-mocha/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ import {
TestModuleForAcceptance,
} from 'ember-test-helpers';

const setupTestLegacy = setupTestFactory(TestModule);
const setupAcceptanceTest = setupTestFactory(TestModuleForAcceptance);
const setupComponentTest = setupTestFactory(TestModuleForComponent);
const setupModelTest = setupTestFactory(TestModuleForModel);
const setupTestLegacy = setupTestFactory(TestModule, 'setupTest');
const setupAcceptanceTest = setupTestFactory(TestModuleForAcceptance, 'setupAcceptanceTest');
const setupComponentTest = setupTestFactory(TestModuleForComponent, 'setupComponentTest');
const setupModelTest = setupTestFactory(TestModuleForModel, 'setupModelTest');

// wrapper function that supports the old and the new testing APIs, depending on its arguments
function setupTest(moduleName) {
Expand Down
24 changes: 23 additions & 1 deletion addon-test-support/ember-mocha/setup-test-factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,24 @@ import Ember from 'ember';
import { before, beforeEach, afterEach, after } from 'mocha';
import { getContext } from '@ember/test-helpers';

export default function(Constructor) {
export default function(Constructor, functionName) {
return function setupTest(moduleName, options = {}) {
let deprecationMessage;
if (functionName === 'setupTest') {
deprecationMessage = 'The `setupTest()` function that accepts a module ' +
'name has been deprecated. Please use `setupTest()` without a module ' +
'name and look it up via `this.owner.lookup(moduleName)` instead.';
} else if (functionName === 'setupComponentTest') {
deprecationMessage = 'The `setupComponentTest()` function is deprecated. ' +
'Please use the `setupRenderingTest()` function instead.';
} else if (functionName === 'setupAcceptanceTest') {
deprecationMessage = 'The `setupAcceptanceTest()` function is deprecated. ' +
'Please use the `setupApplicationTest()` function instead.';
} else {
deprecationMessage = `The \`${functionName}()\` function is deprecated. ` +
`Please use the \`setupTest()\` function instead.`;
}

var module;

if (Ember.typeOf(moduleName) === 'object') {
Expand All @@ -16,6 +32,12 @@ export default function(Constructor) {
});

beforeEach(function() {
Ember.deprecate(deprecationMessage, false, {
id: 'ember-mocha.setup-test',
until: '0.16.0',
url: 'https://github.com/emberjs/ember-mocha#upgrading',
});

return module.setup().then(() => {
var context = getContext();
Object.keys(context).forEach(key => {
Expand Down

0 comments on commit 3673b83

Please sign in to comment.