From 81568674fdbfdf26221708b94c08340f97279c9a Mon Sep 17 00:00:00 2001 From: snewcomer24 Date: Fri, 8 Dec 2017 08:50:23 -0800 Subject: [PATCH 1/2] blueprints/instance-initializer-test: Add RFC232 variants --- .../instance-initializers/__name__-test.js | 29 +++++++++++++++++++ .../instance-initializer-test-test.js | 14 +++++++++ .../instance-initializer-test/rfc232.js | 29 +++++++++++++++++++ 3 files changed, 72 insertions(+) create mode 100644 blueprints/instance-initializer-test/qunit-rfc-232-files/tests/unit/instance-initializers/__name__-test.js create mode 100644 node-tests/fixtures/instance-initializer-test/rfc232.js diff --git a/blueprints/instance-initializer-test/qunit-rfc-232-files/tests/unit/instance-initializers/__name__-test.js b/blueprints/instance-initializer-test/qunit-rfc-232-files/tests/unit/instance-initializers/__name__-test.js new file mode 100644 index 00000000000..0a8c159b505 --- /dev/null +++ b/blueprints/instance-initializer-test/qunit-rfc-232-files/tests/unit/instance-initializers/__name__-test.js @@ -0,0 +1,29 @@ +import Application from '@ember/application'; +import { run } from '@ember/runloop'; + +import { initialize } from '<%= dasherizedModulePrefix %>/initializers/<%= dasherizedModuleName %>'; +import { module, test } from 'qunit'; +import { setupTest } from 'ember-qunit'; +import destroyApp from '../../helpers/destroy-app'; + +module('<%= friendlyTestName %>', function(hooks) { + setupTest(hooks); + + hooks.beforeEach(function() { + run(() => { + this.application = Application.create(); + this.application.deferReadiness(); + }); + }); + hooks.afterEach(function() { + destroyApp(this.application); + }); + + // Replace this with your real tests. + test('it works', function(assert) { + initialize(this.application); + + // you would normally confirm the results of the initializer here + assert.ok(true); + }); +}); diff --git a/node-tests/blueprints/instance-initializer-test-test.js b/node-tests/blueprints/instance-initializer-test-test.js index a98d25aa492..deef587b9d6 100644 --- a/node-tests/blueprints/instance-initializer-test-test.js +++ b/node-tests/blueprints/instance-initializer-test-test.js @@ -9,6 +9,7 @@ const modifyPackages = blueprintHelpers.modifyPackages; const chai = require('ember-cli-blueprint-test-helpers/chai'); const expect = chai.expect; +const generateFakePackageManifest = require('../helpers/generate-fake-package-manifest'); const fixture = require('../helpers/fixture'); describe('Blueprint: instance-initializer-test', function() { @@ -26,6 +27,19 @@ describe('Blueprint: instance-initializer-test', function() { }); }); + describe('with ember-cli-qunit@4.1.1', function() { + beforeEach(function() { + generateFakePackageManifest('ember-cli-qunit', '4.1.1'); + }); + + it('instance-initializer-test foo', function() { + return emberGenerateDestroy(['instance-initializer-test', 'foo'], _file => { + expect(_file('tests/unit/instance-initializers/foo-test.js')) + .to.equal(fixture('instance-initializer-test/rfc232.js')); + }); + }); + }); + describe('with ember-cli-mocha', function() { beforeEach(function() { modifyPackages([ diff --git a/node-tests/fixtures/instance-initializer-test/rfc232.js b/node-tests/fixtures/instance-initializer-test/rfc232.js new file mode 100644 index 00000000000..7d338ef7316 --- /dev/null +++ b/node-tests/fixtures/instance-initializer-test/rfc232.js @@ -0,0 +1,29 @@ +import Application from '@ember/application'; +import { run } from '@ember/runloop'; + +import { initialize } from 'my-app/initializers/foo'; +import { module, test } from 'qunit'; +import { setupTest } from 'ember-qunit'; +import destroyApp from '../../helpers/destroy-app'; + +module('Unit | Instance Initializer | foo', function(hooks) { + setupTest(hooks); + + hooks.beforeEach(function() { + run(() => { + this.application = Application.create(); + this.application.deferReadiness(); + }); + }); + hooks.afterEach(function() { + destroyApp(this.application); + }); + + // Replace this with your real tests. + test('it works', function(assert) { + initialize(this.application); + + // you would normally confirm the results of the initializer here + assert.ok(true); + }); +}); From 4879d49d675c487ad4de8eebce777de7ec6b6492 Mon Sep 17 00:00:00 2001 From: snewcomer24 Date: Sat, 9 Dec 2017 18:31:45 -0800 Subject: [PATCH 2/2] fixup based on comments --- .../instance-initializers/__name__-test.js | 18 ++++++++++-------- .../instance-initializer-test/rfc232.js | 18 ++++++++++-------- 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/blueprints/instance-initializer-test/qunit-rfc-232-files/tests/unit/instance-initializers/__name__-test.js b/blueprints/instance-initializer-test/qunit-rfc-232-files/tests/unit/instance-initializers/__name__-test.js index 0a8c159b505..9782808f480 100644 --- a/blueprints/instance-initializer-test/qunit-rfc-232-files/tests/unit/instance-initializers/__name__-test.js +++ b/blueprints/instance-initializer-test/qunit-rfc-232-files/tests/unit/instance-initializers/__name__-test.js @@ -1,7 +1,6 @@ import Application from '@ember/application'; -import { run } from '@ember/runloop'; -import { initialize } from '<%= dasherizedModulePrefix %>/initializers/<%= dasherizedModuleName %>'; +import { initialize } from '<%= dasherizedModulePrefix %>/instance-initializers/<%= dasherizedModuleName %>'; import { module, test } from 'qunit'; import { setupTest } from 'ember-qunit'; import destroyApp from '../../helpers/destroy-app'; @@ -10,20 +9,23 @@ module('<%= friendlyTestName %>', function(hooks) { setupTest(hooks); hooks.beforeEach(function() { - run(() => { - this.application = Application.create(); - this.application.deferReadiness(); + this.TestApplication = Application.extend(); + this.TestApplication.instanceInitializer({ + name: 'initializer under test', + initialize }); + this.application = this.TestApplication.create({ autoboot: false }); + this.instance = this.application.buildInstance(); }); hooks.afterEach(function() { destroyApp(this.application); + destroyApp(this.instance); }); // Replace this with your real tests. - test('it works', function(assert) { - initialize(this.application); + test('it works', async function(assert) { + await this.instance.boot(); - // you would normally confirm the results of the initializer here assert.ok(true); }); }); diff --git a/node-tests/fixtures/instance-initializer-test/rfc232.js b/node-tests/fixtures/instance-initializer-test/rfc232.js index 7d338ef7316..d3378f08aef 100644 --- a/node-tests/fixtures/instance-initializer-test/rfc232.js +++ b/node-tests/fixtures/instance-initializer-test/rfc232.js @@ -1,7 +1,6 @@ import Application from '@ember/application'; -import { run } from '@ember/runloop'; -import { initialize } from 'my-app/initializers/foo'; +import { initialize } from 'my-app/instance-initializers/foo'; import { module, test } from 'qunit'; import { setupTest } from 'ember-qunit'; import destroyApp from '../../helpers/destroy-app'; @@ -10,20 +9,23 @@ module('Unit | Instance Initializer | foo', function(hooks) { setupTest(hooks); hooks.beforeEach(function() { - run(() => { - this.application = Application.create(); - this.application.deferReadiness(); + this.TestApplication = Application.extend(); + this.TestApplication.instanceInitializer({ + name: 'initializer under test', + initialize }); + this.application = this.TestApplication.create({ autoboot: false }); + this.instance = this.application.buildInstance(); }); hooks.afterEach(function() { destroyApp(this.application); + destroyApp(this.instance); }); // Replace this with your real tests. - test('it works', function(assert) { - initialize(this.application); + test('it works', async function(assert) { + await this.instance.boot(); - // you would normally confirm the results of the initializer here assert.ok(true); }); });