Skip to content
This repository has been archived by the owner on Dec 8, 2024. It is now read-only.

Allowing you to test templates from MU co-located tests #33

Closed
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
10 changes: 8 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,14 @@ module.exports = function(babel) {
meta: {}
}

if (state.file.opts.filename.includes('-components')) {
options.meta.moduleName = parseModuleName(state.file.opts.filename);
let filename = state.file.opts.filename;
let filenameParts = filename.split('/');
filenameParts.splice(0, 1);

if (filename.includes('-components')) {
options.meta.moduleName = parseModuleName(filename);
} else if (filenameParts[2] === 'components' && filenameParts.length > 5) {
options.meta.moduleName = parseModuleName(filename);
Copy link

Choose a reason for hiding this comment

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

I wonder if it would be better if parseModuleName does the filename checking and returns null if the filename is irrelevant. So this could be

let filename = state.file.opts.filename;
let moduleName = parseModuleName(filename);
if (moduleName) {
  options.meta.moduleName = moduleName;
}

}

let compiledTemplateString = `Ember.HTMLBars.template(${state.opts.precompile(template, options)})`;
Expand Down
8 changes: 7 additions & 1 deletion lib/parse-module-name.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@ module.exports = function (filename) {

const componentsIndex = parts.indexOf('-components');

parts.splice(componentsIndex);
if (componentsIndex > 0) {
parts.splice(componentsIndex);
} else {
parts.splice(parts.length - 2);
}

parts.push('template');

return parts.join('/') + '.hbs';
}
6 changes: 5 additions & 1 deletion tests/parse-module-name.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@

const parseModuleName = require('../lib/parse-module-name');

describe.only('parse-module-name helper', function() {
describe('parse-module-name helper', function() {
it('should return applicaiton template when using a route local -component', function() {
Copy link

Choose a reason for hiding this comment

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

typo here, should read application
Also can you add a few more test for the null case?

it('should return null for public components', function() {
  expect(parseModuleName('emberconf/src/ui/components/foo-bar/component-test.js').toEqual(null);
}
it('should return null for public components in test folder', function() {
  expect(parseModuleName('emberconf/tests/integration/components/foo-bar/component-test.js').toEqual(null);
}

expect(parseModuleName('emberconf/src/ui/routes/application/-components/footer-prompt/component-test.js')).toEqual('src/ui/routes/application.hbs');
})

it('should return the parent component when using a component local component', function() {
expect(parseModuleName('emberconf/src/ui/components/icon-emberconf/facey-face/component-test.js')).toEqual('src/ui/components/icon-emberconf/template.hbs');
})
})