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/component-test: Add RFC232 variants #15934

Merged
merged 3 commits into from
Dec 6, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
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,36 @@
<% if (testType === 'integration') { %>import { module, test } from 'qunit';
import { setupRenderingTest } from 'ember-qunit';
import { render } from '@ember/test-helpers';
import hbs from 'htmlbars-inline-precompile';

module('<%= friendlyTestDescription %>', function(hooks) {
setupRenderingTest(hooks);

test('it renders', async function(assert) {
// Set any properties with this.set('myProperty', 'value');
// Handle any actions with this.set('myAction', function(val) { ... });
Copy link
Contributor

Choose a reason for hiding this comment

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

// Handle any actions with this.set('myAction', function(val) { ... });

should this be this.on ?

Copy link
Member Author

Choose a reason for hiding this comment

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

no, because with the new system this.on does not exist anymore

@rwjblue correct me if I'm wrong

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

yeah, and it's only needed for old-style actions, with closure actions the thing I put in there is all that's needed

Copy link
Contributor

Choose a reason for hiding this comment

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

got it.. 👌


await render(hbs`{{<%= componentPathName %>}}`);

assert.equal(this.element.textContent.trim(), '');

// Template block usage:
await render(hbs`
{{#<%= componentPathName %>}}
template block text
{{/<%= componentPathName %>}}
`);

assert.equal(this.element.textContent.trim(), 'template block text');
});
});<% } else if (testType === 'unit') { %>import { module, test } from 'qunit';
import { setupTest } from 'ember-qunit';

module('<%= friendlyTestDescription %>', function(hooks) {
setupTest(hooks);

test('it exists', function(assert) {
let component = this.owner.factoryFor('component:<%= componentPathName %>').create();
assert.ok(component);
});
});<% } %>
14 changes: 11 additions & 3 deletions blueprints/test-framework-detector.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,22 @@ module.exports = function(blueprint) {
var type;

var dependencies = this.project.dependencies();
if ('ember-qunit' in dependencies || 'ember-cli-qunit' in dependencies) {
type = 'qunit';
if ('ember-qunit' in dependencies) {
type = 'qunit-rfc-232';

} else if ('ember-cli-qunit' in dependencies) {
let checker = new VersionChecker(this.project);
if (fs.existsSync(this.path + '/qunit-rfc-232-files') && checker.for('ember-cli-qunit', 'npm').gte('4.1.1')) {
type = 'qunit-rfc-232';
} else {
type = 'qunit';
}

} else if ('ember-mocha' in dependencies) {
type = 'mocha-0.12';

} else if ('ember-cli-mocha' in dependencies) {
var checker = new VersionChecker({ root: this.project.root });
let checker = new VersionChecker(this.project);
if (fs.existsSync(this.path + '/mocha-0.12-files') && checker.for('ember-cli-mocha', 'npm').satisfies('>=0.12.0')) {
type = 'mocha-0.12';
} else {
Expand Down
60 changes: 29 additions & 31 deletions node-tests/blueprints/component-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ var chai = require('ember-cli-blueprint-test-helpers/chai');
var expect = chai.expect;

var generateFakePackageManifest = require('../helpers/generate-fake-package-manifest');
var fixture = require('../helpers/file');

describe('Acceptance: ember generate component', function() {
setupTestHooks(this);
Expand Down Expand Up @@ -719,12 +720,7 @@ describe('Acceptance: ember generate component', function() {
return emberNew()
.then(() => emberGenerateDestroy(args, _file => {
expect(_file('tests/integration/components/x-foo-test.js'))
.to.contain("import { moduleForComponent, test } from 'ember-qunit';")
.to.contain("import hbs from 'htmlbars-inline-precompile';")
.to.contain("moduleForComponent('x-foo'")
.to.contain("integration: true")
.to.contain("{{x-foo}}")
.to.contain("{{#x-foo}}");
.to.equal(fixture('component-test/default.js'));
}));
});

Expand Down Expand Up @@ -757,9 +753,7 @@ describe('Acceptance: ember generate component', function() {
return emberNew()
.then(() => emberGenerateDestroy(args, _file => {
expect(_file('tests/unit/components/x-foo-test.js'))
.to.contain("import { moduleForComponent, test } from 'ember-qunit';")
.to.contain("moduleForComponent('x-foo'")
.to.contain("unit: true");
.to.equal(fixture('component-test/unit.js'));
}));
});

Expand Down Expand Up @@ -811,6 +805,28 @@ describe('Acceptance: ember generate component', function() {
}));
});

it('component-test x-foo for RFC232', function() {
var args = ['component-test', 'x-foo'];

return emberNew()
.then(() => generateFakePackageManifest('ember-cli-qunit', '4.1.1'))
.then(() => emberGenerateDestroy(args, _file => {
expect(_file('tests/integration/components/x-foo-test.js'))
.to.equal(fixture('component-test/rfc232.js'));
}));
});

it('component-test x-foo --unit for RFC232', function() {
var args = ['component-test', 'x-foo', '--unit'];

return emberNew()
.then(() => generateFakePackageManifest('ember-cli-qunit', '4.1.1'))
.then(() => emberGenerateDestroy(args, _file => {
expect(_file('tests/unit/components/x-foo-test.js'))
.to.equal(fixture('component-test/rfc232-unit.js'));
}));
});

it('component-test x-foo for mocha', function() {
var args = ['component-test', 'x-foo'];

Expand All @@ -822,12 +838,7 @@ describe('Acceptance: ember generate component', function() {
.then(() => generateFakePackageManifest('ember-cli-mocha', '0.11.0'))
.then(() => emberGenerateDestroy(args, _file => {
expect(_file('tests/integration/components/x-foo-test.js'))
.to.contain("import { describeComponent, it } from 'ember-mocha';")
.to.contain("import hbs from 'htmlbars-inline-precompile';")
.to.contain("describeComponent('x-foo', 'Integration | Component | x foo'")
.to.contain("integration: true")
.to.contain("{{x-foo}}")
.to.contain("{{#x-foo}}");
.to.equal(fixture('component-test/mocha.js'));
}));
});

Expand All @@ -842,9 +853,7 @@ describe('Acceptance: ember generate component', function() {
.then(() => generateFakePackageManifest('ember-cli-mocha', '0.11.0'))
.then(() => emberGenerateDestroy(args, _file => {
expect(_file('tests/unit/components/x-foo-test.js'))
.to.contain("import { describeComponent, it } from 'ember-mocha';")
.to.contain("describeComponent('x-foo', 'Unit | Component | x foo")
.to.contain("unit: true");
.to.equal(fixture('component-test/mocha-unit.js'));
}));
});

Expand All @@ -859,14 +868,7 @@ describe('Acceptance: ember generate component', function() {
.then(() => generateFakePackageManifest('ember-cli-mocha', '0.12.0'))
.then(() => emberGenerateDestroy(args, _file => {
expect(_file('tests/integration/components/x-foo-test.js'))
.to.contain("import { describe, it } from 'mocha';")
.to.contain("import { setupComponentTest } from 'ember-mocha';")
.to.contain("import hbs from 'htmlbars-inline-precompile';")
.to.contain("describe('Integration | Component | x foo'")
.to.contain("setupComponentTest('x-foo',")
.to.contain("integration: true")
.to.contain("{{x-foo}}")
.to.contain("{{#x-foo}}");
.to.equal(fixture('component-test/mocha-0.12.js'));
}));
});

Expand All @@ -881,11 +883,7 @@ describe('Acceptance: ember generate component', function() {
.then(() => generateFakePackageManifest('ember-cli-mocha', '0.12.0'))
.then(() => emberGenerateDestroy(args, _file => {
expect(_file('tests/unit/components/x-foo-test.js'))
.to.contain("import { describe, it } from 'mocha';")
.to.contain("import { setupComponentTest } from 'ember-mocha';")
.to.contain("describe('Unit | Component | x foo'")
.to.contain("setupComponentTest('x-foo',")
.to.contain("unit: true");
.to.equal(fixture('component-test/mocha-0.12-unit.js'));
}));
});
});
24 changes: 24 additions & 0 deletions node-tests/fixtures/component-test/default.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { moduleForComponent, test } from 'ember-qunit';
import hbs from 'htmlbars-inline-precompile';

moduleForComponent('x-foo', 'Integration | Component | x foo', {
integration: true
});

test('it renders', function(assert) {
// Set any properties with this.set('myProperty', 'value');
// Handle any actions with this.on('myAction', function(val) { ... });

this.render(hbs`{{x-foo}}`);

assert.equal(this.$().text().trim(), '');

// Template block usage:
this.render(hbs`
{{#x-foo}}
template block text
{{/x-foo}}
`);

assert.equal(this.$().text().trim(), 'template block text');
});
20 changes: 20 additions & 0 deletions node-tests/fixtures/component-test/mocha-0.12-unit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { expect } from 'chai';
import { describe, it } from 'mocha';
import { setupComponentTest } from 'ember-mocha';

describe('Unit | Component | x foo', function() {
setupComponentTest('x-foo', {
// Specify the other units that are required for this test
// needs: ['component:foo', 'helper:bar'],
unit: true
});

it('renders', function() {
// creates the component instance
let component = this.subject();
// renders the component on the page
this.render();
expect(component).to.be.ok;
expect(this.$()).to.have.length(1);
});
});
24 changes: 24 additions & 0 deletions node-tests/fixtures/component-test/mocha-0.12.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { expect } from 'chai';
import { describe, it } from 'mocha';
import { setupComponentTest } from 'ember-mocha';
import hbs from 'htmlbars-inline-precompile';

describe('Integration | Component | x foo', function() {
setupComponentTest('x-foo', {
integration: true
});

it('renders', function() {
// Set any properties with this.set('myProperty', 'value');
// Handle any actions with this.on('myAction', function(val) { ... });
// Template block usage:
// this.render(hbs`
// {{#x-foo}}
// template content
// {{/x-foo}}
// `);

this.render(hbs`{{x-foo}}`);
expect(this.$()).to.have.length(1);
});
});
20 changes: 20 additions & 0 deletions node-tests/fixtures/component-test/mocha-unit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { expect } from 'chai';
import { describeComponent, it } from 'ember-mocha';

describeComponent('x-foo', 'Unit | Component | x foo',
{
// Specify the other units that are required for this test
// needs: ['component:foo', 'helper:bar'],
unit: true
},
function() {
it('renders', function() {
// creates the component instance
let component = this.subject();
// renders the component on the page
this.render();
expect(component).to.be.ok;
expect(this.$()).to.have.length(1);
});
}
);
24 changes: 24 additions & 0 deletions node-tests/fixtures/component-test/mocha.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { expect } from 'chai';
import { describeComponent, it } from 'ember-mocha';
import hbs from 'htmlbars-inline-precompile';

describeComponent('x-foo', 'Integration | Component | x foo',
{
integration: true
},
function() {
it('renders', function() {
// Set any properties with this.set('myProperty', 'value');
// Handle any actions with this.on('myAction', function(val) { ... });
// Template block usage:
// this.render(hbs`
// {{#x-foo}}
// template content
// {{/x-foo}}
// `);

this.render(hbs`{{x-foo}}`);
expect(this.$()).to.have.length(1);
});
}
);
11 changes: 11 additions & 0 deletions node-tests/fixtures/component-test/rfc232-unit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { module, test } from 'qunit';
import { setupTest } from 'ember-qunit';

module('Unit | Component | x foo', function(hooks) {
setupTest(hooks);

test('it exists', function(assert) {
let component = this.owner.factoryFor('component:x-foo').create();
assert.ok(component);
});
});
26 changes: 26 additions & 0 deletions node-tests/fixtures/component-test/rfc232.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { module, test } from 'qunit';
import { setupRenderingTest } from 'ember-qunit';
import { render } from '@ember/test-helpers';
import hbs from 'htmlbars-inline-precompile';

module('Integration | Component | x foo', function(hooks) {
setupRenderingTest(hooks);

test('it renders', async function(assert) {
// Set any properties with this.set('myProperty', 'value');
// Handle any actions with this.set('myAction', function(val) { ... });
Copy link
Contributor

Choose a reason for hiding this comment

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

this.on


await render(hbs`{{x-foo}}`);

assert.equal(this.element.textContent.trim(), '');

// Template block usage:
await render(hbs`
{{#x-foo}}
template block text
{{/x-foo}}
`);

assert.equal(this.element.textContent.trim(), 'template block text');
});
});
16 changes: 16 additions & 0 deletions node-tests/fixtures/component-test/unit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { moduleForComponent, test } from 'ember-qunit';

moduleForComponent('x-foo', 'Unit | Component | x foo', {
// Specify the other units that are required for this test
// needs: ['component:foo', 'helper:bar'],
unit: true
});

test('it renders', function(assert) {

// Creates the component instance
/*let component =*/ this.subject();
// Renders the component to the page
this.render();
assert.equal(this.$().text().trim(), '');
});