From 486aff750bb66b90728029620d6e9e8bdb45c3f7 Mon Sep 17 00:00:00 2001 From: Tobias Bieniek Date: Fri, 2 Dec 2016 13:52:45 +0100 Subject: [PATCH] [BUGFIX beta] Add blueprints for "ember-cli-mocha >= 0.12.0" --- .../tests/unit/__path__/__test__.js | 16 +++++++++++++ .../tests/unit/__path__/__test__.js | 17 ++++++++++++++ .../tests/unit/__path__/__test__.js | 19 +++++++++++++++ blueprints/test-framework-detector.js | 9 +++++++- .../tests/unit/__path__/__test__.js | 16 +++++++++++++ node-tests/blueprints/adapter-test.js | 22 ++++++++++++++++++ node-tests/blueprints/model-test.js | 22 ++++++++++++++++++ node-tests/blueprints/serializer-test.js | 23 +++++++++++++++++++ node-tests/blueprints/transform-test.js | 22 ++++++++++++++++++ .../helpers/generate-fake-package-manifest.js | 13 +++++++++++ 10 files changed, 178 insertions(+), 1 deletion(-) create mode 100644 blueprints/adapter-test/mocha-0.12-files/tests/unit/__path__/__test__.js create mode 100644 blueprints/model-test/mocha-0.12-files/tests/unit/__path__/__test__.js create mode 100644 blueprints/serializer-test/mocha-0.12-files/tests/unit/__path__/__test__.js create mode 100644 blueprints/transform-test/mocha-0.12-files/tests/unit/__path__/__test__.js create mode 100644 node-tests/helpers/generate-fake-package-manifest.js diff --git a/blueprints/adapter-test/mocha-0.12-files/tests/unit/__path__/__test__.js b/blueprints/adapter-test/mocha-0.12-files/tests/unit/__path__/__test__.js new file mode 100644 index 00000000000..1eb97b0b43a --- /dev/null +++ b/blueprints/adapter-test/mocha-0.12-files/tests/unit/__path__/__test__.js @@ -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; + }); +}); diff --git a/blueprints/model-test/mocha-0.12-files/tests/unit/__path__/__test__.js b/blueprints/model-test/mocha-0.12-files/tests/unit/__path__/__test__.js new file mode 100644 index 00000000000..6850a578f78 --- /dev/null +++ b/blueprints/model-test/mocha-0.12-files/tests/unit/__path__/__test__.js @@ -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; + }); +}); diff --git a/blueprints/serializer-test/mocha-0.12-files/tests/unit/__path__/__test__.js b/blueprints/serializer-test/mocha-0.12-files/tests/unit/__path__/__test__.js new file mode 100644 index 00000000000..fd852a5e0d9 --- /dev/null +++ b/blueprints/serializer-test/mocha-0.12-files/tests/unit/__path__/__test__.js @@ -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; + }); +}); diff --git a/blueprints/test-framework-detector.js b/blueprints/test-framework-detector.js index 8f04dca3a60..2f8a2d988f8 100644 --- a/blueprints/test-framework-detector.js +++ b/blueprints/test-framework-detector.js @@ -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() { @@ -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')) { + type = 'mocha-0.12'; + } else { + type = 'mocha'; + } } else { this.ui.writeLine('Couldn\'t determine test style - using QUnit'); type = 'qunit'; diff --git a/blueprints/transform-test/mocha-0.12-files/tests/unit/__path__/__test__.js b/blueprints/transform-test/mocha-0.12-files/tests/unit/__path__/__test__.js new file mode 100644 index 00000000000..fcbe57e5eed --- /dev/null +++ b/blueprints/transform-test/mocha-0.12-files/tests/unit/__path__/__test__.js @@ -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; + }); +}); diff --git a/node-tests/blueprints/adapter-test.js b/node-tests/blueprints/adapter-test.js index 699abfa1454..d312cbfe341 100644 --- a/node-tests/blueprints/adapter-test.js +++ b/node-tests/blueprints/adapter-test.js @@ -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); @@ -96,6 +98,7 @@ 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\';') @@ -103,4 +106,23 @@ describe('Acceptance: generate and destroy adapter blueprints', function() { .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;'); + })); + }); }); diff --git a/node-tests/blueprints/model-test.js b/node-tests/blueprints/model-test.js index 70e046f9517..6b57bf5a1fb 100644 --- a/node-tests/blueprints/model-test.js +++ b/node-tests/blueprints/model-test.js @@ -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); @@ -109,6 +111,7 @@ 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\';') @@ -116,4 +119,23 @@ describe('Acceptance: generate and destroy model blueprints', function() { .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;'); + })); + }); }); diff --git a/node-tests/blueprints/serializer-test.js b/node-tests/blueprints/serializer-test.js index b7eb757e527..016e94eae0f 100644 --- a/node-tests/blueprints/serializer-test.js +++ b/node-tests/blueprints/serializer-test.js @@ -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); @@ -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\';') @@ -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;'); + })); + }); }); diff --git a/node-tests/blueprints/transform-test.js b/node-tests/blueprints/transform-test.js index cebe88093b6..8d934d7218e 100644 --- a/node-tests/blueprints/transform-test.js +++ b/node-tests/blueprints/transform-test.js @@ -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); @@ -44,6 +46,7 @@ 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\';') @@ -51,4 +54,23 @@ describe('Acceptance: generate and destroy transform blueprints', function() { .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;'); + })); + }); }); diff --git a/node-tests/helpers/generate-fake-package-manifest.js b/node-tests/helpers/generate-fake-package-manifest.js new file mode 100644 index 00000000000..d6f92f1f5a9 --- /dev/null +++ b/node-tests/helpers/generate-fake-package-manifest.js @@ -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, + })); +};