From a65f4e57e78b17fcaf7f0470ddcf17ff1da64a01 Mon Sep 17 00:00:00 2001 From: Robert Jackson Date: Tue, 17 Oct 2017 13:17:07 -0400 Subject: [PATCH 1/8] Update to ember-test-helpers@0.7.0-beta.7. --- package.json | 2 +- yarn.lock | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index ba9bdcf1..0d317111 100644 --- a/package.json +++ b/package.json @@ -31,7 +31,7 @@ "common-tags": "^1.4.0", "ember-cli-babel": "^6.3.0", "ember-cli-test-loader": "^2.2.0", - "ember-test-helpers": "^0.7.0-beta.2", + "ember-test-helpers": "^0.7.0-beta.7", "qunitjs": "^2.4.0" }, "devDependencies": { diff --git a/yarn.lock b/yarn.lock index 1c8b95cf..ac82139f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2133,9 +2133,9 @@ ember-source@~2.15.0: simple-dom "^0.3.0" simple-html-tokenizer "^0.4.1" -ember-test-helpers@^0.7.0-beta.2: - version "0.7.0-beta.4" - resolved "https://registry.yarnpkg.com/ember-test-helpers/-/ember-test-helpers-0.7.0-beta.4.tgz#bdd1b538719072da1206637fe7aef3aec089fa0d" +ember-test-helpers@^0.7.0-beta.7: + version "0.7.0-beta.7" + resolved "https://registry.yarnpkg.com/ember-test-helpers/-/ember-test-helpers-0.7.0-beta.7.tgz#7a8d594af90875e2fc75ff0face5494d27b68446" dependencies: broccoli-funnel "^2.0.1" ember-cli-babel "^6.8.1" From e19ad75b47b10b2193bb13080b83440a1972e679 Mon Sep 17 00:00:00 2001 From: Robert Jackson Date: Tue, 17 Oct 2017 13:43:20 -0400 Subject: [PATCH 2/8] Move legacy testing system into legacy-2-x subfolder. This is in prep for the work needed to support the new testing API's proposed in emberjs/rfcs#232. --- addon-test-support/ember-qunit/index.js | 10 ++++++---- .../{ => legacy-2-x}/module-for-component.js | 0 .../ember-qunit/{ => legacy-2-x}/module-for-model.js | 0 .../ember-qunit/{ => legacy-2-x}/module-for.js | 0 .../ember-qunit/{ => legacy-2-x}/qunit-module.js | 0 .../unit/{ => legacy-2-x}/module-for-component-test.js | 2 +- tests/unit/{ => legacy-2-x}/module-for-model-test.js | 2 +- tests/unit/{ => legacy-2-x}/module-for-test.js | 2 +- 8 files changed, 9 insertions(+), 7 deletions(-) rename addon-test-support/ember-qunit/{ => legacy-2-x}/module-for-component.js (100%) rename addon-test-support/ember-qunit/{ => legacy-2-x}/module-for-model.js (100%) rename addon-test-support/ember-qunit/{ => legacy-2-x}/module-for.js (100%) rename addon-test-support/ember-qunit/{ => legacy-2-x}/qunit-module.js (100%) rename tests/unit/{ => legacy-2-x}/module-for-component-test.js (97%) rename tests/unit/{ => legacy-2-x}/module-for-model-test.js (97%) rename tests/unit/{ => legacy-2-x}/module-for-test.js (98%) diff --git a/addon-test-support/ember-qunit/index.js b/addon-test-support/ember-qunit/index.js index a5feef1d..7612e205 100644 --- a/addon-test-support/ember-qunit/index.js +++ b/addon-test-support/ember-qunit/index.js @@ -1,6 +1,8 @@ -export { default as moduleFor } from './module-for'; -export { default as moduleForComponent } from './module-for-component'; -export { default as moduleForModel } from './module-for-model'; +export { default as moduleFor } from './legacy-2-x/module-for'; +export { + default as moduleForComponent, +} from './legacy-2-x/module-for-component'; +export { default as moduleForModel } from './legacy-2-x/module-for-model'; export { default as QUnitAdapter } from './adapter'; export { setResolver } from 'ember-test-helpers'; export { module, test, skip, only, todo } from 'qunit'; @@ -9,7 +11,7 @@ export { loadTests } from './test-loader'; import { loadTests } from './test-loader'; import Ember from 'ember'; import QUnit from 'qunit'; -import { QUnitAdapter } from 'ember-qunit'; +import QUnitAdapter from './adapter'; /** Uses current URL configuration to setup the test container. diff --git a/addon-test-support/ember-qunit/module-for-component.js b/addon-test-support/ember-qunit/legacy-2-x/module-for-component.js similarity index 100% rename from addon-test-support/ember-qunit/module-for-component.js rename to addon-test-support/ember-qunit/legacy-2-x/module-for-component.js diff --git a/addon-test-support/ember-qunit/module-for-model.js b/addon-test-support/ember-qunit/legacy-2-x/module-for-model.js similarity index 100% rename from addon-test-support/ember-qunit/module-for-model.js rename to addon-test-support/ember-qunit/legacy-2-x/module-for-model.js diff --git a/addon-test-support/ember-qunit/module-for.js b/addon-test-support/ember-qunit/legacy-2-x/module-for.js similarity index 100% rename from addon-test-support/ember-qunit/module-for.js rename to addon-test-support/ember-qunit/legacy-2-x/module-for.js diff --git a/addon-test-support/ember-qunit/qunit-module.js b/addon-test-support/ember-qunit/legacy-2-x/qunit-module.js similarity index 100% rename from addon-test-support/ember-qunit/qunit-module.js rename to addon-test-support/ember-qunit/legacy-2-x/qunit-module.js diff --git a/tests/unit/module-for-component-test.js b/tests/unit/legacy-2-x/module-for-component-test.js similarity index 97% rename from tests/unit/module-for-component-test.js rename to tests/unit/legacy-2-x/module-for-component-test.js index ce8615a4..ee29f4dd 100644 --- a/tests/unit/module-for-component-test.js +++ b/tests/unit/legacy-2-x/module-for-component-test.js @@ -1,7 +1,7 @@ import Ember from 'ember'; import $ from 'jquery'; import { moduleForComponent, test } from 'ember-qunit'; -import { setResolverRegistry } from '../helpers/resolver'; +import { setResolverRegistry } from '../../helpers/resolver'; import hbs from 'htmlbars-inline-precompile'; var PrettyColor = Ember.Component.extend({ diff --git a/tests/unit/module-for-model-test.js b/tests/unit/legacy-2-x/module-for-model-test.js similarity index 97% rename from tests/unit/module-for-model-test.js rename to tests/unit/legacy-2-x/module-for-model-test.js index 33f400ff..fb5eca53 100644 --- a/tests/unit/module-for-model-test.js +++ b/tests/unit/legacy-2-x/module-for-model-test.js @@ -1,6 +1,6 @@ import DS from 'ember-data'; import { moduleForModel, test } from 'ember-qunit'; -import { setResolverRegistry } from '../helpers/resolver'; +import { setResolverRegistry } from '../../helpers/resolver'; var Adapter = DS.JSONAPIAdapter || DS.FixutreAdapter; diff --git a/tests/unit/module-for-test.js b/tests/unit/legacy-2-x/module-for-test.js similarity index 98% rename from tests/unit/module-for-test.js rename to tests/unit/legacy-2-x/module-for-test.js index 874180b8..7f85e0b0 100644 --- a/tests/unit/module-for-test.js +++ b/tests/unit/legacy-2-x/module-for-test.js @@ -2,7 +2,7 @@ import Ember from 'ember'; import { module, moduleFor, test } from 'ember-qunit'; -import { setResolverRegistry } from '../helpers/resolver'; +import { setResolverRegistry } from '../../helpers/resolver'; function setupRegistry() { setResolverRegistry({ From 9cc8f47b2ac6a949b0a95c5e862cb2a7ceba2e48 Mon Sep 17 00:00:00 2001 From: Robert Jackson Date: Tue, 17 Oct 2017 14:20:13 -0400 Subject: [PATCH 3/8] Use a single centralized .eslintrc.js. --- .eslintrc.js | 28 +++++++++++++++++++++++++++- addon-test-support/.eslintrc | 8 -------- tests/.eslintrc.js | 9 --------- 3 files changed, 27 insertions(+), 18 deletions(-) delete mode 100644 addon-test-support/.eslintrc delete mode 100644 tests/.eslintrc.js diff --git a/.eslintrc.js b/.eslintrc.js index f9d5f9fb..96480ea1 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -4,8 +4,34 @@ module.exports = { plugins: ['prettier'], parserOptions: { ecmaVersion: 2017, + sourceType: 'module', + }, + env: { + browser: true, }, rules: { - 'prettier/prettier': ['error', { singleQuote: true, trailingComma: 'es5' }], + 'prettier/prettier': ['error', { + singleQuote: true, + trailingComma: 'es5', + printWidth: 100, + }], }, + overrides: [ + { + files: ['./index.js'], + parserOptions: { + sourceType: 'script', + }, + env: { + browser: false, + node: true, + } + }, + { + files: ['tests/**/*.js'], + env: { + qunit: true + } + }, + ] }; diff --git a/addon-test-support/.eslintrc b/addon-test-support/.eslintrc deleted file mode 100644 index d7284bd9..00000000 --- a/addon-test-support/.eslintrc +++ /dev/null @@ -1,8 +0,0 @@ -{ - "parserOptions": { - "sourceType": "module" - }, - "env": { - "browser": true - } -} diff --git a/tests/.eslintrc.js b/tests/.eslintrc.js deleted file mode 100644 index adcd8578..00000000 --- a/tests/.eslintrc.js +++ /dev/null @@ -1,9 +0,0 @@ -module.exports = { - parserOptions: { - sourceType: 'module' - }, - env: { - browser: true, - embertest: true - } -}; From 86ce3c0ae12daaa812cdc883c9e223ea290a1c84 Mon Sep 17 00:00:00 2001 From: Robert Jackson Date: Tue, 17 Oct 2017 14:20:38 -0400 Subject: [PATCH 4/8] Allow async/await in tests/ but disallow in addon-test-support. --- .eslintrc.js | 10 ++++++++++ package.json | 1 + tests/dummy/config/targets.js | 7 +------ yarn.lock | 10 ++++++++++ 4 files changed, 22 insertions(+), 6 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 96480ea1..7c6639b8 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -33,5 +33,15 @@ module.exports = { qunit: true } }, + { + files: ['./index.js', 'addon-test-support/**/*.js', 'config/**/*.js'], + plugins: [ + 'disable-features', + ], + rules: { + 'disable-features/disable-async-await': 'error', + 'disable-features/disable-generator-functions': 'error', + } + }, ] }; diff --git a/package.json b/package.json index 0d317111..af078050 100644 --- a/package.json +++ b/package.json @@ -48,6 +48,7 @@ "ember-resolver": "^4.0.0", "ember-source": "~2.15.0", "eslint-config-prettier": "^2.6.0", + "eslint-plugin-disable-features": "^0.1.2", "eslint-plugin-prettier": "^2.3.1", "loader.js": "^4.2.3", "prettier": "^1.7.4" diff --git a/tests/dummy/config/targets.js b/tests/dummy/config/targets.js index 1485eec1..88acac5a 100644 --- a/tests/dummy/config/targets.js +++ b/tests/dummy/config/targets.js @@ -1,9 +1,4 @@ /* eslint-env node */ module.exports = { - browsers: [ - 'ie 9', - 'last 1 Chrome versions', - 'last 1 Firefox versions', - 'last 1 Safari versions', - ], + browsers: ['last 1 Chrome versions', 'last 1 Firefox versions', 'last 1 Safari versions'], }; diff --git a/yarn.lock b/yarn.lock index ac82139f..b9552d77 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2288,6 +2288,12 @@ eslint-config-prettier@^2.6.0: dependencies: get-stdin "^5.0.1" +eslint-plugin-disable-features@^0.1.2: + version "0.1.2" + resolved "https://registry.yarnpkg.com/eslint-plugin-disable-features/-/eslint-plugin-disable-features-0.1.2.tgz#a5e53dd61e517d897938b8451bce13b24677597f" + dependencies: + requireindex "~1.1.0" + eslint-plugin-prettier@^2.3.1: version "2.3.1" resolved "https://registry.yarnpkg.com/eslint-plugin-prettier/-/eslint-plugin-prettier-2.3.1.tgz#e7a746c67e716f335274b88295a9ead9f544e44d" @@ -4568,6 +4574,10 @@ require-uncached@^1.0.3: caller-path "^0.1.0" resolve-from "^1.0.0" +requireindex@~1.1.0: + version "1.1.0" + resolved "https://registry.yarnpkg.com/requireindex/-/requireindex-1.1.0.tgz#e5404b81557ef75db6e49c5a72004893fe03e162" + requires-port@1.x.x: version "1.0.0" resolved "https://registry.yarnpkg.com/requires-port/-/requires-port-1.0.0.tgz#925d2601d39ac485e091cf0da5c6e694dc3dcaff" From 9ff51884e579a22fda601da7a274e1c3ece1a7ef Mon Sep 17 00:00:00 2001 From: Robert Jackson Date: Tue, 17 Oct 2017 14:23:33 -0400 Subject: [PATCH 5/8] Update files for updated prettier config for printWidth. --- addon-test-support/ember-qunit/adapter.js | 4 +--- addon-test-support/ember-qunit/index.js | 11 +++------- .../ember-qunit/legacy-2-x/qunit-module.js | 4 +--- tests/helpers/module-for-acceptance.js | 3 +-- tests/unit/adapter-test.js | 4 +--- .../unit/legacy-2-x/module-for-model-test.js | 12 +++-------- tests/unit/legacy-2-x/module-for-test.js | 21 +++---------------- 7 files changed, 13 insertions(+), 46 deletions(-) diff --git a/addon-test-support/ember-qunit/adapter.js b/addon-test-support/ember-qunit/adapter.js index 2932320c..fd1d919a 100644 --- a/addon-test-support/ember-qunit/adapter.js +++ b/addon-test-support/ember-qunit/adapter.js @@ -30,9 +30,7 @@ export default Ember.Test.Adapter.extend({ }, asyncStart() { - this.doneCallbacks.push( - QUnit.config.current ? QUnit.config.current.assert.async() : null - ); + this.doneCallbacks.push(QUnit.config.current ? QUnit.config.current.assert.async() : null); }, asyncEnd() { diff --git a/addon-test-support/ember-qunit/index.js b/addon-test-support/ember-qunit/index.js index 7612e205..db864167 100644 --- a/addon-test-support/ember-qunit/index.js +++ b/addon-test-support/ember-qunit/index.js @@ -1,7 +1,5 @@ export { default as moduleFor } from './legacy-2-x/module-for'; -export { - default as moduleForComponent, -} from './legacy-2-x/module-for-component'; +export { default as moduleForComponent } from './legacy-2-x/module-for-component'; export { default as moduleForModel } from './legacy-2-x/module-for-model'; export { default as QUnitAdapter } from './adapter'; export { setResolver } from 'ember-test-helpers'; @@ -32,8 +30,7 @@ export function setupTestContainer() { let params = QUnit.urlParams; let containerVisibility = params.nocontainer ? 'hidden' : 'visible'; - let containerPosition = - params.dockcontainer || params.devmode ? 'fixed' : 'relative'; + let containerPosition = params.dockcontainer || params.devmode ? 'fixed' : 'relative'; if (params.devmode) { testContainer.className = ' full-screen'; @@ -44,9 +41,7 @@ export function setupTestContainer() { let qunitContainer = document.getElementById('qunit'); if (params.dockcontainer) { - qunitContainer.style.marginBottom = window.getComputedStyle( - testContainer - ).height; + qunitContainer.style.marginBottom = window.getComputedStyle(testContainer).height; } } diff --git a/addon-test-support/ember-qunit/legacy-2-x/qunit-module.js b/addon-test-support/ember-qunit/legacy-2-x/qunit-module.js index c3c7229e..fd5d2d68 100644 --- a/addon-test-support/ember-qunit/legacy-2-x/qunit-module.js +++ b/addon-test-support/ember-qunit/legacy-2-x/qunit-module.js @@ -54,9 +54,7 @@ export function createModule(Constructor, name, description, callbacks) { afterEach() { let result = afterEach.apply(this, arguments); - return Ember.RSVP - .resolve(result) - .then(() => module.teardown(...arguments)); + return Ember.RSVP.resolve(result).then(() => module.teardown(...arguments)); }, after() { diff --git a/tests/helpers/module-for-acceptance.js b/tests/helpers/module-for-acceptance.js index cfc7c517..13532942 100644 --- a/tests/helpers/module-for-acceptance.js +++ b/tests/helpers/module-for-acceptance.js @@ -16,8 +16,7 @@ export default function(name, options = {}) { }, afterEach() { - let afterEach = - options.afterEach && options.afterEach.apply(this, arguments); + let afterEach = options.afterEach && options.afterEach.apply(this, arguments); return resolve(afterEach).then(() => destroyApp(this.application)); }, }); diff --git a/tests/unit/adapter-test.js b/tests/unit/adapter-test.js index 109424bd..70f0262f 100644 --- a/tests/unit/adapter-test.js +++ b/tests/unit/adapter-test.js @@ -15,9 +15,7 @@ test('asyncStart waits for asyncEnd to finish a test', function(assert) { }, 50); }); -test('asyncStart waits for equal numbers of asyncEnd to finish a test', function( - assert -) { +test('asyncStart waits for equal numbers of asyncEnd to finish a test', function(assert) { const adapter = QUnitAdapter.create(); adapter.asyncStart(); diff --git a/tests/unit/legacy-2-x/module-for-model-test.js b/tests/unit/legacy-2-x/module-for-model-test.js index fb5eca53..30c89896 100644 --- a/tests/unit/legacy-2-x/module-for-model-test.js +++ b/tests/unit/legacy-2-x/module-for-model-test.js @@ -66,9 +66,7 @@ test('WhazzitAdapter is registered for model', function(assert) { var model = this.subject(), store = this.store(); - assert.ok( - store.adapterFor(model.constructor.modelName) instanceof WhazzitAdapter - ); + assert.ok(store.adapterFor(model.constructor.modelName) instanceof WhazzitAdapter); }); /////////////////////////////////////////////////////////////////////////////// @@ -89,10 +87,6 @@ test('ApplicationAdapter is registered for model', function(assert) { var model = this.subject(), store = this.store(); - assert.ok( - store.adapterFor(model.constructor.modelName) instanceof ApplicationAdapter - ); - assert.notOk( - store.adapterFor(model.constructor.modelName) instanceof WhazzitAdapter - ); + assert.ok(store.adapterFor(model.constructor.modelName) instanceof ApplicationAdapter); + assert.notOk(store.adapterFor(model.constructor.modelName) instanceof WhazzitAdapter); }); diff --git a/tests/unit/legacy-2-x/module-for-test.js b/tests/unit/legacy-2-x/module-for-test.js index 7f85e0b0..b2c15686 100644 --- a/tests/unit/legacy-2-x/module-for-test.js +++ b/tests/unit/legacy-2-x/module-for-test.js @@ -10,11 +10,7 @@ function setupRegistry() { }); } -var callbackOrder, - setupContext, - teardownContext, - beforeSetupContext, - afterTeardownContext; +var callbackOrder, setupContext, teardownContext, beforeSetupContext, afterTeardownContext; moduleFor('component:x-foo', 'TestModule callbacks', { beforeSetup: function() { @@ -53,12 +49,7 @@ moduleFor('component:x-foo', 'TestModule callbacks', { afterTeardownContext = this; callbackOrder.push('afterTeardown'); - assert.deepEqual(callbackOrder, [ - 'beforeSetup', - 'setup', - 'teardown', - 'afterTeardown', - ]); + assert.deepEqual(callbackOrder, ['beforeSetup', 'setup', 'teardown', 'afterTeardown']); assert.equal(afterTeardownContext, beforeSetupContext); assert.ok(afterTeardownContext !== teardownContext); }, @@ -96,13 +87,7 @@ moduleFor('component:x-foo', 'beforeEach/afterEach callbacks', { after: function(assert) { callbackOrder.push('after'); - assert.deepEqual(callbackOrder, [ - 'before', - 'beforeSetup', - 'beforeEach', - 'afterEach', - 'after', - ]); + assert.deepEqual(callbackOrder, ['before', 'beforeSetup', 'beforeEach', 'afterEach', 'after']); }, }); From a19773719be0981b3095427402409970d317d74b Mon Sep 17 00:00:00 2001 From: Robert Jackson Date: Tue, 17 Oct 2017 15:00:35 -0400 Subject: [PATCH 6/8] Add basic implementation of new ember-qunit API. --- addon-test-support/ember-qunit/index.js | 30 +++++++- .../integration/setup-rendering-test-test.js | 48 +++++++++++++ tests/integration/setup-test-test.js | 71 +++++++++++++++++++ 3 files changed, 148 insertions(+), 1 deletion(-) create mode 100644 tests/integration/setup-rendering-test-test.js create mode 100644 tests/integration/setup-test-test.js diff --git a/addon-test-support/ember-qunit/index.js b/addon-test-support/ember-qunit/index.js index db864167..452610b4 100644 --- a/addon-test-support/ember-qunit/index.js +++ b/addon-test-support/ember-qunit/index.js @@ -2,7 +2,7 @@ export { default as moduleFor } from './legacy-2-x/module-for'; export { default as moduleForComponent } from './legacy-2-x/module-for-component'; export { default as moduleForModel } from './legacy-2-x/module-for-model'; export { default as QUnitAdapter } from './adapter'; -export { setResolver } from 'ember-test-helpers'; +export { setResolver, render, clearRender, settled } from 'ember-test-helpers'; export { module, test, skip, only, todo } from 'qunit'; export { loadTests } from './test-loader'; @@ -10,6 +10,34 @@ import { loadTests } from './test-loader'; import Ember from 'ember'; import QUnit from 'qunit'; import QUnitAdapter from './adapter'; +import { + setupContext, + teardownContext, + setupRenderingContext, + teardownRenderingContext, +} from 'ember-test-helpers'; + +export function setupTest(hooks, options) { + hooks.beforeEach(function() { + setupContext(this, options); + }); + + hooks.afterEach(function() { + teardownContext(this); + }); +} + +export function setupRenderingTest(hooks, options) { + setupTest(hooks, options); + + hooks.beforeEach(function() { + setupRenderingContext(this); + }); + + hooks.afterEach(function() { + teardownRenderingContext(this); + }); +} /** Uses current URL configuration to setup the test container. diff --git a/tests/integration/setup-rendering-test-test.js b/tests/integration/setup-rendering-test-test.js new file mode 100644 index 00000000..4c005cd5 --- /dev/null +++ b/tests/integration/setup-rendering-test-test.js @@ -0,0 +1,48 @@ +import { module, test } from 'qunit'; +import Component from '@ember/component'; +import { helper } from '@ember/component/helper'; +import hbs from 'htmlbars-inline-precompile'; +import { setupRenderingTest, render } from 'ember-qunit'; +import { setResolverRegistry } from '../helpers/resolver'; + +module('setupRenderingTest tests', function(hooks) { + hooks.beforeEach(function() { + setResolverRegistry({}); + }); + + setupRenderingTest(hooks); + + test('can render a simple template', async function(assert) { + await render(hbs`

Hello!

`); + + assert.equal(this.element.textContent, 'Hello!'); + }); + + test('can invoke template only components', async function(assert) { + this.owner.register('template:components/template-only', hbs`template-only component here`); + await render(hbs`{{template-only}}`); + + assert.equal(this.element.textContent, 'template-only component here'); + }); + + test('can invoke JS only components', async function(assert) { + this.owner.register( + 'component:js-only', + Component.extend({ + classNames: ['js-only'], + }) + ); + + await render(hbs`{{js-only}}`); + + assert.ok(this.element.querySelector('.js-only'), 'element found for js-only component'); + }); + + test('can invoke helper', async function(assert) { + this.owner.register('helper:jax', helper(([name]) => `${name}-jax`)); + + await render(hbs`{{jax "max"}}`); + + assert.equal(this.element.textContent, 'max-jax'); + }); +}); diff --git a/tests/integration/setup-test-test.js b/tests/integration/setup-test-test.js new file mode 100644 index 00000000..4cb7c353 --- /dev/null +++ b/tests/integration/setup-test-test.js @@ -0,0 +1,71 @@ +import { module, test } from 'qunit'; +import Service, { inject as injectService } from '@ember/service'; +import Component from '@ember/component'; +import { setupTest } from 'ember-qunit'; +import hasEmberVersion from 'ember-test-helpers/has-ember-version'; +import { setResolverRegistry } from '../helpers/resolver'; + +module('setupTest tests', function(hooks) { + hooks.beforeEach(function() { + setResolverRegistry({}); + }); + + setupTest(hooks); + + test('can be used for unit style testing', function(assert) { + this.owner.register( + 'service:foo', + Service.extend({ + someMethod() { + return 'hello thar!'; + }, + }) + ); + + let subject = this.owner.lookup('service:foo'); + + assert.equal(subject.someMethod(), 'hello thar!'); + }); + + test('can access a shared service instance', function(assert) { + this.owner.register('service:bar', Service.extend()); + this.owner.register( + 'service:foo', + Service.extend({ + bar: injectService(), + someMethod() { + this.set('bar.someProp', 'derp'); + }, + }) + ); + + let subject = this.owner.lookup('service:foo'); + let bar = this.owner.lookup('service:bar'); + + assert.notOk(bar.get('someProp'), 'precond - initially undefined'); + + subject.someMethod(); + + assert.equal(bar.get('someProp'), 'derp', 'property updated'); + }); + + test('can create a component instance for direct testing without a template', function(assert) { + this.owner.register( + 'component:foo-bar', + Component.extend({ + someMethod() { + return 'hello thar!'; + }, + }) + ); + + let subject; + if (hasEmberVersion(2, 12)) { + subject = this.owner.lookup('component:foo-bar'); + } else { + subject = this.owner._lookupFactory('component:foo-bar').create(); + } + + assert.equal(subject.someMethod(), 'hello thar!'); + }); +}); From b9db3fd6f811f69e9e9a62f0926abd05f2d670f1 Mon Sep 17 00:00:00 2001 From: Robert Jackson Date: Tue, 17 Oct 2017 15:37:39 -0400 Subject: [PATCH 7/8] Bump node version to 6 (required for eslint-plugin-disable-features). PR is submitted to fix the plugin, once merged and released we can drop this back down. --- .travis.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 3f082867..2749cbb4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,9 +1,7 @@ --- language: node_js node_js: - # we recommend testing addons with the same minimum supported node version as Ember CLI - # so that your addon works for all apps - - "4" + - "6" sudo: false dist: trusty From 0aa46893b807383a819beeb4fce1547f88055631 Mon Sep 17 00:00:00 2001 From: Robert Jackson Date: Tue, 17 Oct 2017 16:03:39 -0400 Subject: [PATCH 8/8] Ensure the new testing API does not run for Ember < 2.4. The new API relies on the the public API added for `Ember.getOwner` / `Ember.setOwner`. --- tests/integration/setup-rendering-test-test.js | 5 +++++ tests/integration/setup-test-test.js | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/tests/integration/setup-rendering-test-test.js b/tests/integration/setup-rendering-test-test.js index 4c005cd5..dc6c41f3 100644 --- a/tests/integration/setup-rendering-test-test.js +++ b/tests/integration/setup-rendering-test-test.js @@ -4,8 +4,13 @@ import { helper } from '@ember/component/helper'; import hbs from 'htmlbars-inline-precompile'; import { setupRenderingTest, render } from 'ember-qunit'; import { setResolverRegistry } from '../helpers/resolver'; +import hasEmberVersion from 'ember-test-helpers/has-ember-version'; module('setupRenderingTest tests', function(hooks) { + if (!hasEmberVersion(2, 4)) { + return; + } + hooks.beforeEach(function() { setResolverRegistry({}); }); diff --git a/tests/integration/setup-test-test.js b/tests/integration/setup-test-test.js index 4cb7c353..115399d1 100644 --- a/tests/integration/setup-test-test.js +++ b/tests/integration/setup-test-test.js @@ -6,6 +6,10 @@ import hasEmberVersion from 'ember-test-helpers/has-ember-version'; import { setResolverRegistry } from '../helpers/resolver'; module('setupTest tests', function(hooks) { + if (!hasEmberVersion(2, 4)) { + return; + } + hooks.beforeEach(function() { setResolverRegistry({}); });