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

[BUGFIX beta] Add blueprints for "ember-cli-mocha >= 0.12.0" #4691

Merged
merged 1 commit into from
Dec 2, 2016
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,16 @@
import { expect } from 'chai';
import { describe, it } from 'mocha';
import { setupTest } from 'ember-mocha';

describe('<%= friendlyTestDescription %>', function() {
setupTest('adapter:<%= dasherizedModuleName %>', {
// Specify the other units that are required for this test.
// needs: ['serializer:foo']
});

// Replace this with your real tests.
it('exists', function() {
let adapter = this.subject();
expect(adapter).to.be.ok;
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { expect } from 'chai';
import { describe, it } from 'mocha';
import { setupModelTest } from 'ember-mocha';

describe('<%= friendlyDescription %>', function() {
setupModelTest('<%= dasherizedModuleName %>', {
// Specify the other units that are required for this test.
<%= typeof needs !== 'undefined' ? needs : '' %>
});

// Replace this with your real tests.
it('exists', function() {
let model = this.subject();
// var store = this.store();
expect(model).to.be.ok;
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { expect } from 'chai';
import { describe, it } from 'mocha';
import { setupModelTest } from 'ember-mocha';

describe('<%= friendlyTestDescription %>', function() {
setupModelTest('<%= dasherizedModuleName %>', {
// Specify the other units that are required for this test.
needs: ['serializer:<%= dasherizedModuleName %>']
});

// Replace this with your real tests.
it('serializes records', function() {
let record = this.subject();

let serializedRecord = record.serialize();

expect(serializedRecord).to.be.ok;
});
});
9 changes: 8 additions & 1 deletion blueprints/test-framework-detector.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
var fs = require('fs');
var path = require('path');
var VersionChecker = require('ember-cli-version-checker');

module.exports = function(blueprint) {
blueprint.supportsAddon = function() {
Expand All @@ -12,7 +14,12 @@ module.exports = function(blueprint) {
if ('ember-cli-qunit' in dependencies) {
type = 'qunit';
} else if ('ember-cli-mocha' in dependencies) {
type = 'mocha';
var checker = new VersionChecker({ project: this.project });
if (fs.existsSync(this.path + '/mocha-0.12-files') && checker.for('ember-cli-mocha', 'npm').satisfies('>=0.12.0')) {
Copy link
Member

Choose a reason for hiding this comment

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

Why is the check for /mocha-0.12-files necessary`? Shouldn't this be the case when the addon of this version is installed?

Copy link
Member Author

Choose a reason for hiding this comment

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

@pangratz that check allows us to have some blueprints that care about the Mocha version and others that don't. This is not technically needed in this case, but I've reused the code from emberjs/ember.js#14670 to reduce differences.

type = 'mocha-0.12';
} else {
type = 'mocha';
}
} else {
this.ui.writeLine('Couldn\'t determine test style - using QUnit');
type = 'qunit';
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { expect } from 'chai';
import { describe, it } from 'mocha';
import { setupTest } from 'ember-mocha';

describe('<%= friendlyTestDescription %>', function() {
setupTest('transform:<%= dasherizedModuleName %>', {
// Specify the other units that are required for this test.
// needs: ['transform:foo']
});

// Replace this with your real tests.
it('exists', function() {
let transform = this.subject();
expect(transform).to.be.ok;
});
});
22 changes: 22 additions & 0 deletions node-tests/blueprints/adapter-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ var expect = chai.expect;

var SilentError = require('silent-error');

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

describe('Acceptance: generate and destroy adapter blueprints', function() {
setupTestHooks(this);

Expand Down Expand Up @@ -96,11 +98,31 @@ describe('Acceptance: generate and destroy adapter blueprints', function() {
{name: 'ember-cli-qunit', delete: true},
{name: 'ember-cli-mocha', dev: true}
]))
.then(() => generateFakePackageManifest('ember-cli-mocha', '0.11.0'))
.then(() => emberGenerateDestroy(args, _file => {
expect(_file('tests/unit/adapters/foo-test.js'))
.to.contain('import { describeModule, it } from \'ember-mocha\';')
.to.contain('describeModule(\n \'adapter:foo\',')
.to.contain('expect(adapter).to.be.ok;');
}));
});

it('adapter-test for mocha v0.12+', function() {
var args = ['adapter-test', 'foo'];

return emberNew()
.then(() => modifyPackages([
{name: 'ember-cli-qunit', delete: true},
{name: 'ember-cli-mocha', dev: true}
]))
.then(() => generateFakePackageManifest('ember-cli-mocha', '0.12.0'))
.then(() => emberGenerateDestroy(args, _file => {
expect(_file('tests/unit/adapters/foo-test.js'))
.to.contain('import { describe, it } from \'mocha\';')
.to.contain('import { setupTest } from \'ember-mocha\';')
.to.contain('describe(\'Unit | Adapter | foo\', function() {')
.to.contain('setupTest(\'adapter:foo\',')
.to.contain('expect(adapter).to.be.ok;');
}));
});
});
22 changes: 22 additions & 0 deletions node-tests/blueprints/model-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ var modifyPackages = blueprintHelpers.modifyPackages;
var chai = require('ember-cli-blueprint-test-helpers/chai');
var expect = chai.expect;

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

describe('Acceptance: generate and destroy model blueprints', function() {
setupTestHooks(this);

Expand Down Expand Up @@ -109,11 +111,31 @@ describe('Acceptance: generate and destroy model blueprints', function() {
{name: 'ember-cli-qunit', delete: true},
{name: 'ember-cli-mocha', dev: true}
]))
.then(() => generateFakePackageManifest('ember-cli-mocha', '0.11.0'))
.then(() => emberGenerateDestroy(args, _file => {
expect(_file('tests/unit/models/foo-test.js'))
.to.contain('import { describeModel, it } from \'ember-mocha\';')
.to.contain('describeModel(\n \'foo\',')
.to.contain('expect(model).to.be.ok;');
}));
});

it('model-test for mocha v0.12+', function() {
var args = ['model-test', 'foo'];

return emberNew()
.then(() => modifyPackages([
{name: 'ember-cli-qunit', delete: true},
{name: 'ember-cli-mocha', dev: true}
]))
.then(() => generateFakePackageManifest('ember-cli-mocha', '0.12.0'))
.then(() => emberGenerateDestroy(args, _file => {
expect(_file('tests/unit/models/foo-test.js'))
.to.contain('import { describe, it } from \'mocha\';')
.to.contain('import { setupModelTest } from \'ember-mocha\';')
.to.contain('describe(\'Unit | Model | foo\', function() {')
.to.contain('setupModelTest(\'foo\',')
.to.contain('expect(model).to.be.ok;');
}));
});
});
23 changes: 23 additions & 0 deletions node-tests/blueprints/serializer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ var expect = chai.expect;

var SilentError = require('silent-error');

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

describe('Acceptance: generate and destroy serializer blueprints', function() {
setupTestHooks(this);

Expand Down Expand Up @@ -96,6 +98,7 @@ describe('Acceptance: generate and destroy serializer blueprints', function() {
{name: 'ember-cli-qunit', delete: true},
{name: 'ember-cli-mocha', dev: true}
]))
.then(() => generateFakePackageManifest('ember-cli-mocha', '0.11.0'))
.then(() => emberGenerateDestroy(args, _file => {
expect(_file('tests/unit/serializers/foo-test.js'))
.to.contain('import { describeModel, it } from \'ember-mocha\';')
Expand All @@ -105,4 +108,24 @@ describe('Acceptance: generate and destroy serializer blueprints', function() {
.to.contain('expect(serializedRecord).to.be.ok;');
}));
});

it('serializer-test for mocha v0.12+', function() {
var args = ['serializer-test', 'foo'];

return emberNew()
.then(() => modifyPackages([
{name: 'ember-cli-qunit', delete: true},
{name: 'ember-cli-mocha', dev: true}
]))
.then(() => generateFakePackageManifest('ember-cli-mocha', '0.12.0'))
.then(() => emberGenerateDestroy(args, _file => {
expect(_file('tests/unit/serializers/foo-test.js'))
.to.contain('import { describe, it } from \'mocha\';')
.to.contain('import { setupModelTest } from \'ember-mocha\';')
.to.contain('describe(\'Unit | Serializer | foo\', function() {')
.to.contain('setupModelTest(\'foo\', {')
.to.contain('needs: [\'serializer:foo\']')
.to.contain('expect(serializedRecord).to.be.ok;');
}));
});
});
22 changes: 22 additions & 0 deletions node-tests/blueprints/transform-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ var modifyPackages = blueprintHelpers.modifyPackages;
var chai = require('ember-cli-blueprint-test-helpers/chai');
var expect = chai.expect;

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

describe('Acceptance: generate and destroy transform blueprints', function() {
setupTestHooks(this);

Expand Down Expand Up @@ -44,11 +46,31 @@ describe('Acceptance: generate and destroy transform blueprints', function() {
{name: 'ember-cli-qunit', delete: true},
{name: 'ember-cli-mocha', dev: true}
]))
.then(() => generateFakePackageManifest('ember-cli-mocha', '0.11.0'))
.then(() => emberGenerateDestroy(args, _file => {
expect(_file('tests/unit/transforms/foo-test.js'))
.to.contain('import { describeModule, it } from \'ember-mocha\';')
.to.contain('describeModule(\n \'transform:foo\',')
.to.contain('expect(transform).to.be.ok;');
}));
});

it('transform-test for mocha v0.12+', function() {
var args = ['transform-test', 'foo'];

return emberNew()
.then(() => modifyPackages([
{name: 'ember-cli-qunit', delete: true},
{name: 'ember-cli-mocha', dev: true}
]))
.then(() => generateFakePackageManifest('ember-cli-mocha', '0.12.0'))
.then(() => emberGenerateDestroy(args, _file => {
expect(_file('tests/unit/transforms/foo-test.js'))
.to.contain('import { describe, it } from \'mocha\';')
.to.contain('import { setupTest } from \'ember-mocha\';')
.to.contain('describe(\'Unit | Transform | foo\', function() {')
.to.contain('setupTest(\'transform:foo\',')
.to.contain('expect(transform).to.be.ok;');
}));
});
});
13 changes: 13 additions & 0 deletions node-tests/helpers/generate-fake-package-manifest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
var fs = require('fs');

module.exports = function generateFakePackageManifest(name, version) {
if (!fs.existsSync('node_modules')) {
fs.mkdirSync('node_modules');
}
if (!fs.existsSync('node_modules/' + name)) {
fs.mkdirSync('node_modules/' + name);
}
fs.writeFileSync('node_modules/' + name + '/package.json', JSON.stringify({
version: version,
}));
};