Skip to content
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
59 changes: 49 additions & 10 deletions blueprints/component-test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const isPackageMissing = require('ember-cli-is-package-missing');
const getPathOption = require('ember-cli-get-component-path-option');

const useTestFrameworkDetector = require('../test-framework-detector');
const { isModuleUnificationProject } = require('../module-unification');

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This will break on node@4

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Thanks @ro0gr, I'll update now

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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


module.exports = useTestFrameworkDetector({
description: 'Generates a component integration or unit test.',
Expand All @@ -25,18 +26,49 @@ module.exports = useTestFrameworkDetector({
],

fileMapTokens: function() {
return {
__testType__: function(options) {
return options.locals.testType || 'integration';
},
__path__: function(options) {
if (options.pod) {
return path.join(options.podPath, options.locals.path, options.dasherizedModuleName);
if (isModuleUnificationProject(this.project)) {
return {
__test__() {
return 'component-test';
},
__root__(options) {
if (options.inRepoAddon) {
return path.join('packages', options.inRepoAddon, 'src');
}
return 'src';
},
__testType__(options) {
if (options.locals.testType === 'unit') {
throw 'The --unit flag isn\'t supported within a module unification app';
}

return '';
},
__path__(options) {
if (options.pod) {
throw 'Pods aren\'t supported within a module unification app';
}
return path.join('ui', 'components', options.dasherizedModuleName);
}
return 'components';
}
};
};
} else {
return {
__root__() {
return 'tests';
},
__testType__(options) {
return options.locals.testType || 'integration';
},
__path__(options) {
if (options.pod) {
return path.join(options.podPath, options.locals.path, options.dasherizedModuleName);
}
return 'components';
}
};
}
},

locals: function(options) {
let dasherizedModuleName = stringUtil.dasherize(options.entity.name);
let componentPathName = dasherizedModuleName;
Expand All @@ -50,6 +82,12 @@ module.exports = useTestFrameworkDetector({

if (options.pod && options.path !== 'components' && options.path !== '') {
componentPathName = [options.path, dasherizedModuleName].filter(Boolean).join('/');
} else if (isModuleUnificationProject(this.project)) {
if (options.inRepoAddon) {
componentPathName = `${options.inRepoAddon}::${dasherizedModuleName}`;
} else if (this.project.isEmberCLIAddon()) {
componentPathName = `${this.project.pkg.name}::${dasherizedModuleName}`;
}
}

return {
Expand All @@ -59,6 +97,7 @@ module.exports = useTestFrameworkDetector({
friendlyTestDescription: friendlyTestDescription
};
},

afterInstall: function(options) {
if (!options.dryRun && options.testType === 'integration' && isPackageMissing(this, 'ember-cli-htmlbars-inline-precompile')) {
return this.addPackagesToProject([
Expand Down
69 changes: 50 additions & 19 deletions blueprints/component/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const pathUtil = require('ember-cli-path-utils');
const validComponentName = require('ember-cli-valid-component-name');
const getPathOption = require('ember-cli-get-component-path-option');
const normalizeEntityName = require('ember-cli-normalize-entity-name');
const { isModuleUnificationProject } = require('../module-unification');

module.exports = {
description: 'Generates a component. Name must contain a hyphen.',
Expand All @@ -21,27 +22,55 @@ module.exports = {
}
],

filesPath: function() {
let filesDirectory = 'files';

if (isModuleUnificationProject(this.project)) {
filesDirectory = 'module-unification-files';
}

return path.join(this.path, filesDirectory);
},

fileMapTokens: function() {
return {
__path__: function(options) {
if (options.pod) {
return path.join(options.podPath, options.locals.path, options.dasherizedModuleName);
}
return 'components';
},
__templatepath__: function(options) {
if (options.pod) {
return path.join(options.podPath, options.locals.path, options.dasherizedModuleName);
if (isModuleUnificationProject(this.project)) {
return {
__root__(options) {
if (options.inRepoAddon) {
return path.join('packages', options.inRepoAddon, 'src');
}
if (options.inDummy) {
return path.join('tests', 'dummy', 'src');
}
return 'src';
},
__path__(options) {
return path.join('ui', 'components', options.dasherizedModuleName);
},
};
} else {
return {
__path__: function(options) {
if (options.pod) {
return path.join(options.podPath, options.locals.path, options.dasherizedModuleName);
} else {
return 'components';
}
},
__templatepath__: function(options) {
if (options.pod) {
return path.join(options.podPath, options.locals.path, options.dasherizedModuleName);
}
return 'templates/components';
},
__templatename__: function(options) {
if (options.pod) {
return 'template';
}
return options.dasherizedModuleName;
}
return 'templates/components';
},
__templatename__: function(options) {
if (options.pod) {
return 'template';
}
return options.dasherizedModuleName;
}
};
};
}
},

normalizeEntityName: function(entityName) {
Expand All @@ -54,13 +83,15 @@ module.exports = {
let templatePath = '';
let importTemplate = '';
let contents = '';

// if we're in an addon, build import statement
if (options.project.isEmberCLIAddon() || options.inRepoAddon && !options.inDummy) {
if (options.pod) {
templatePath = './template';
} else {
templatePath = pathUtil.getRelativeParentPath(options.entity.name) +
'templates/components/' + stringUtil.dasherize(options.entity.name);

}
importTemplate = 'import layout from \'' + templatePath + '\';\n';
contents = '\n layout';
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import Component from '@ember/component';

export default Component.extend({

});
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{yield}}
7 changes: 7 additions & 0 deletions blueprints/module-unification.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
'use strict';

module.exports = {
isModuleUnificationProject(project) {
return project.isModuleUnification && project.isModuleUnification();
}
};
116 changes: 115 additions & 1 deletion node-tests/blueprints/component-test-test.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
'use strict';

const fs = require('fs');
const fs = require('fs-extra');

const blueprintHelpers = require('ember-cli-blueprint-test-helpers/helpers');
const setupTestHooks = blueprintHelpers.setupTestHooks;
const emberNew = blueprintHelpers.emberNew;
const emberGenerate = blueprintHelpers.emberGenerate;
const emberGenerateDestroy = blueprintHelpers.emberGenerateDestroy;
const modifyPackages = blueprintHelpers.modifyPackages;

Expand All @@ -14,6 +15,14 @@ const expect = chai.expect;
const generateFakePackageManifest = require('../helpers/generate-fake-package-manifest');
const fixture = require('../helpers/fixture');

function expectError(promise, expectedErrorText) {
return promise.then(() => {
throw 'the command should raise an exception';
}).catch(error => {
expect(error).to.equal(expectedErrorText);
});
}

describe('Blueprint: component-test', function() {
setupTestHooks(this);

Expand Down Expand Up @@ -121,6 +130,111 @@ describe('Blueprint: component-test', function() {
});
});

describe('in app - module unification', function() {
beforeEach(function() {
return emberNew().then(() => fs.ensureDirSync('src'));
});

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/default.js'));
});
});

it('component-test x-foo --unit', function() {
return emberGenerate(['component-test', 'x-foo', '--unit']).then(() => {
throw 'the command should raise an exception';
}).catch(error => {
expect(error).to.equal('The --unit flag isn\'t supported within a module unification app');
});
});

describe('with usePods=true', function() {
beforeEach(function() {
fs.writeFileSync('.ember-cli', `{
"disableAnalytics": false,
"usePods": true
}`);
});

it('component-test x-foo', function() {
return expectError(
emberGenerate(['component-test', 'x-foo']),
'Pods aren\'t supported within a module unification app'
);
});
});

describe('with [email protected]', function() {
beforeEach(function() {
generateFakePackageManifest('ember-cli-qunit', '4.2.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/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('with [email protected]', function() {
beforeEach(function() {
modifyPackages([
{ name: 'ember-cli-qunit', delete: true },
{ name: 'ember-cli-mocha', dev: true }
]);
generateFakePackageManifest('ember-cli-mocha', '0.11.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.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('with [email protected]', function() {
beforeEach(function() {
modifyPackages([
{ name: 'ember-cli-qunit', delete: true },
{ name: 'ember-cli-mocha', dev: true }
]);
generateFakePackageManifest('ember-cli-mocha', '0.12.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-0.12.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() {
beforeEach(function() {
return emberNew({ target: 'addon' });
Expand Down
Loading