File tree Expand file tree Collapse file tree 2 files changed +30
-4
lines changed Expand file tree Collapse file tree 2 files changed +30
-4
lines changed Original file line number Diff line number Diff line change @@ -153,13 +153,18 @@ function isDSModel(node, filePath) {
153
153
}
154
154
155
155
function isModuleByFilePath ( filePath , module ) {
156
- const fileNameJs = `${ module } .js` ;
157
- const fileNameTs = `${ module } .ts` ;
158
- const folderName = `${ module } s` ;
156
+ const expectedFileNameJs = `${ module } .js` ;
157
+ const expectedFileNameTs = `${ module } .ts` ;
158
+ const expectedFolderName = `${ module } s` ;
159
+
160
+ const actualFolders = path . dirname ( filePath ) . split ( path . sep ) ;
161
+ const actualFileName = path . basename ( filePath ) ;
159
162
160
163
/* Check both folder and filename to support both classic and POD's structure */
161
164
return (
162
- filePath . includes ( fileNameJs ) || filePath . includes ( fileNameTs ) || filePath . includes ( folderName )
165
+ actualFileName === expectedFileNameJs ||
166
+ actualFileName === expectedFileNameTs ||
167
+ actualFolders . includes ( expectedFolderName )
163
168
) ;
164
169
}
165
170
Original file line number Diff line number Diff line change @@ -86,6 +86,27 @@ describe('isModuleByFilePath', () => {
86
86
const filePath = 'example-app/components/path/to/some-component.ts' ;
87
87
expect ( emberUtils . isModuleByFilePath ( filePath , 'component' ) ) . toBeTruthy ( ) ;
88
88
} ) ;
89
+
90
+ // Avoid false positives:
91
+ it ( 'should not detect a component in a folder named `fake-components`' , ( ) => {
92
+ const filePath = 'example-app/fake-components/path/to/file.js' ;
93
+ expect ( emberUtils . isModuleByFilePath ( filePath , 'component' ) ) . toBeFalsy ( ) ;
94
+ } ) ;
95
+
96
+ it ( 'should not detect a component with a file named `components`' , ( ) => {
97
+ const filePath = 'example-app/some-folder/path/to/components' ;
98
+ expect ( emberUtils . isModuleByFilePath ( filePath , 'component' ) ) . toBeFalsy ( ) ;
99
+ } ) ;
100
+
101
+ it ( 'should not detect a component with a directory named `component.js`' , ( ) => {
102
+ const filePath = 'example-app/component.js/path/to/file.js' ;
103
+ expect ( emberUtils . isModuleByFilePath ( filePath , 'component' ) ) . toBeFalsy ( ) ;
104
+ } ) ;
105
+
106
+ it ( 'should not detect a component with a directory named `component.ts`' , ( ) => {
107
+ const filePath = 'example-app/component.ts/path/to/file.js' ;
108
+ expect ( emberUtils . isModuleByFilePath ( filePath , 'component' ) ) . toBeFalsy ( ) ;
109
+ } ) ;
89
110
} ) ;
90
111
91
112
describe ( 'isMirageDirectory' , ( ) => {
You can’t perform that action at this time.
0 commit comments