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

blueprints/instance-initializers-test: Add RFC232 variants #15945

Merged
merged 2 commits into from
Dec 10, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
@@ -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(() => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We shouldn’t need to Ember.run here, why is this required? Is there an error or something without it?

Copy link
Contributor Author

@snewcomer snewcomer Dec 9, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah the error I get is the You have turned on testing mode... error...specifically related to the Application.create() expression.

this.application = Application.create();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you swap this to Application.create({ autoboot: false }) here?

this.application.deferReadiness();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This shouldn’t be needed with my suggested changes

});
});
hooks.afterEach(function() {
destroyApp(this.application);
});

// Replace this with your real tests.
test('it works', function(assert) {
initialize(this.application);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instance initializers expect to receive an Ember.ApplicationInstance instance, but this is an Ember.Application instance.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To fix that, you would do something like:

module(‘asdf’, function(hooks) {

  hooks.beforeEach(function() {
    this.Application = Ember.Application.extend();
    this.application = this.Application.create({ autoboot: true });
    this.application.instanceInitializer({
      name: ‘initializer under test’,
      initialize
    });
  });

  hooks.afterEach(function() {
    runDestroy(this.instance);
    runDestroy(this.application);
  });

  test(‘it works’, async function(assert) {
    this.instance = this.application.buildInstance();
    await this.instance.boot();
    assert.ok(didTheInitializerWork);
  });
});

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rwjblue Ah yeah overall my bad. So with this test, await this.instance.boot(); results in Assertion Failed: You cannot use the same root element (BODY) multiple times in an Ember.Application. Failing on this line -

assert(`You cannot use the same root element (${rootElement.selector || rootElement[0].tagName}) multiple times in an Ember.Application`, !rootElement.is(ROOT_ELEMENT_SELECTOR));

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tested on a 2.17 application.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you mind pushing up your demo app so I can tinker with it to find the right combo?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, I made a really bad mistake in my comment above, it should be { autoboot: false } (and I had true in the comment)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, just tested locally, and I think that it will work once updating to { autoboot: false } (sorry about that).


// you would normally confirm the results of the initializer here
assert.ok(true);
});
});
14 changes: 14 additions & 0 deletions node-tests/blueprints/instance-initializer-test-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -26,6 +27,19 @@ describe('Blueprint: instance-initializer-test', function() {
});
});

describe('with [email protected]', 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([
Expand Down
29 changes: 29 additions & 0 deletions node-tests/fixtures/instance-initializer-test/rfc232.js
Original file line number Diff line number Diff line change
@@ -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);
});
});