Skip to content

Commit

Permalink
Add RFC 232 variant detector for mocha & component tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Dhaulagiri committed Aug 5, 2018
1 parent 9ea80e1 commit 97cf5d4
Show file tree
Hide file tree
Showing 5 changed files with 137 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<% if (testType === 'integration') { %>import { expect } from 'chai';
import { describe, it } from 'mocha';
import { setupRenderingTest } from 'ember-mocha';
import { render } from '@ember/test-helpers';
import hbs from 'htmlbars-inline-precompile';

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

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

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

expect(this.element.textContent.trim()).to.equal('');

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

expect(this.element.textContent.trim()).to.equal('template block text');
});
});<% } else if (testType === 'unit') { %>import { expect } from 'chai';
import { describe, it } from 'mocha';
import { setupTest } from 'ember-mocha';

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

it('exists', function() {
let component = this.owner.factoryFor('component:<%= componentPathName %>').create();
expect(component).to.be.ok;
});
});<% } %>
10 changes: 9 additions & 1 deletion blueprints/test-framework-detector.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,15 @@ module.exports = function(blueprint) {
type = 'qunit';
}
} else if ('ember-mocha' in dependencies) {
type = 'mocha-0.12';
let checker = new VersionChecker(this.project);
if (
fs.existsSync(this.path + '/mocha-rfc-232-files') &&
checker.for('ember-mocha', 'npm').gte('0.14.0')
) {
type = 'mocha-rfc-232';
} else {
type = 'mocha-0.12';
}
} else if ('ember-cli-mocha' in dependencies) {
let checker = new VersionChecker(this.project);
if (
Expand Down
51 changes: 51 additions & 0 deletions node-tests/blueprints/component-test-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,32 @@ describe('Blueprint: component-test', function() {
});
});
});

describe('with ember-mocha@0.14.0', function() {
beforeEach(function() {
modifyPackages([
{ name: 'ember-cli-qunit', delete: true },
{ name: 'ember-mocha', dev: true },
]);
generateFakePackageManifest('ember-mocha', '0.14.0');
});

it('component-test x-foo', function() {
return emberGenerateDestroy(['component-test', 'x-foo'], _file => {
expect(_file('tests/integration/components/x-foo-test.js')).to.equal(
fixture('component-test/mocha-rfc232.js')
);
});
});

it('component-test x-foo --unit', function() {
return emberGenerateDestroy(['component-test', 'x-foo', '--unit'], _file => {
expect(_file('tests/unit/components/x-foo-test.js')).to.equal(
fixture('component-test/mocha-rfc232-unit.js')
);
});
});
});
});

describe('in app - module unification', function() {
Expand Down Expand Up @@ -247,6 +273,31 @@ describe('Blueprint: component-test', function() {
);
});
});

describe('with ember-mocha@0.14.0', function() {
beforeEach(function() {
modifyPackages([
{ name: 'ember-cli-qunit', delete: true },
{ name: 'ember-mocha', dev: true },
]);
generateFakePackageManifest('ember-mocha', '0.14.0');
});

it('component-test x-foo', function() {
return emberGenerateDestroy(['component-test', 'x-foo'], _file => {
expect(_file('src/ui/components/x-foo/component-test.js')).to.equal(
fixture('component-test/mocha-rfc232.js')
);
});
});

it('component-test x-foo --unit', function() {
return expectError(
emberGenerate(['component-test', 'x-foo', '--unit']),
"The --unit flag isn't supported within a module unification app"
);
});
});
});

describe('in addon', function() {
Expand Down
12 changes: 12 additions & 0 deletions node-tests/fixtures/component-test/mocha-rfc232-unit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { expect } from 'chai';
import { describe, it } from 'mocha';
import { setupTest } from 'ember-mocha';

describe('Unit | Component | x-foo', function() {
setupTest();

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

describe('Integration | Component | x-foo', function() {
setupRenderingTest();

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

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

expect(this.element.textContent.trim()).to.equal('');

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

expect(this.element.textContent.trim()).to.equal('template block text');
});
});

0 comments on commit 97cf5d4

Please sign in to comment.