This repository was archived by the owner on Dec 8, 2024. It is now read-only.
Repository navigation
Allowing you to test templates from MU co-located tests #33
Closed
mansona
wants to merge
6
commits into
ember-cli:master
from
stonecircle:feature/test-private-components
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
2f57fd0
make it work for components inside `-components` folders
mansona ad4229d
implementing the nested components version
mansona 7fcb9ce
simplifying the implementation
mansona c8aa333
Add tests for several complex module name cases
mixonic 4d24a0d
Merge pull request #1 from mixonic/feature/test-private-components
mansona ebbeed4
allowing this to work with windows
mansona File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| 'use strict'; | ||
|
|
||
| module.exports = function (filename) { | ||
| let parts = filename.split(/[/\\]/); | ||
|
|
||
| // Drop the application name from the parts | ||
| parts.shift(); | ||
|
|
||
| let lastPrivateCollectionIndex = parts.lastIndexOf('-components'); | ||
|
|
||
| if (lastPrivateCollectionIndex !== -1) { | ||
| // TODO: We likely do not need new array allocations for the prefix and | ||
| // collection parts | ||
|
|
||
| // Take the prefix string | ||
| let prefixString = parts.slice(0,lastPrivateCollectionIndex).join('/'); | ||
|
|
||
| // Take the rest of the string starting at -collectionName (including the -) | ||
| let collectionParts = parts.slice(lastPrivateCollectionIndex); | ||
|
|
||
| // In other cases we're not sure about the semantics in your templates. | ||
| if (collectionParts.length >= 3) { | ||
| if (collectionParts.length > 3) { | ||
| collectionParts.splice(-2); | ||
| return `${prefixString}/${collectionParts.join('/')}/template.hbs`; | ||
| } | ||
| return `${prefixString}/template.hbs`; | ||
| } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if (collectionParts.length > 3) {
collectionParts.splice(-2);
return `${prefixString}/${collectionParts.join('/')}/template.hbs`;
} else if (collectionParts.length === 3) {
return `${prefixString}/template.hbs`;
}
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. also it seems that the route with |
||
| } else { | ||
| let componentsIndex = parts.indexOf('components'); | ||
|
|
||
| // We don't process anything except components | ||
| if (componentsIndex !== -1) { | ||
| // If we don't have 3 segments left, then there is no change to perform. | ||
| if (parts.length - componentsIndex > 3) { | ||
| parts.splice(-2); | ||
| return `${parts.join('/')}/template.hbs`; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return null; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| 'use strict'; | ||
|
|
||
| const parseModuleName = require('../lib/parse-module-name'); | ||
|
|
||
| describe('parse-module-name helper', function() { | ||
| it('should return application template when using a route local -component', function() { | ||
| expect( | ||
| parseModuleName('emberconf/src/ui/routes/application/-components/footer-prompt/component-test.js') | ||
| ).toEqual('src/ui/routes/application/template.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'); | ||
| }); | ||
|
|
||
| it('should return the parent component when using a component local component in private collection', function() { | ||
| expect( | ||
| parseModuleName('emberconf/src/ui/routes/application/foo/-components/footer-prompt/component-test.js') | ||
| ).toEqual('src/ui/routes/application/foo/template.hbs'); | ||
| }); | ||
|
|
||
| it('should return when using a route local -component with nested naming', function() { | ||
| expect( | ||
| parseModuleName('emberconf/src/ui/routes/application/-components/footer-prompt/foo/component-test.js') | ||
| ).toEqual('src/ui/routes/application/-components/footer-prompt/template.hbs'); | ||
| }); | ||
|
|
||
| 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); | ||
| }); | ||
| }); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this still WIP? otherwise this comment should be removed