Skip to content

Commit

Permalink
refactor: file filter allow complete filename as well
Browse files Browse the repository at this point in the history
  • Loading branch information
thetutlage committed Jun 29, 2023
1 parent 6a8a18a commit 8962d42
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/files_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,16 @@ export class FilesManager {
*/
grep(files: URL[], filters: string[]): URL[] {
return files.filter((file) => {
const filename = file.pathname
const filenameWithoutTestSuffix = filename.replace(FILE_SUFFIX_EXPRESSION, '')

return !!filters.find((filter) => {
if (filename.endsWith(filter)) {
return true
}

const filterSegments = filter.split('/').reverse()
const fileSegments = file.pathname.replace(FILE_SUFFIX_EXPRESSION, '').split(sep).reverse()
const fileSegments = filenameWithoutTestSuffix.split(sep).reverse()

return filterSegments.every((segment, index) => {
return fileSegments[index] && (segment === '*' || fileSegments[index].endsWith(segment))
Expand Down
11 changes: 11 additions & 0 deletions tests/files_manager.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,17 @@ const FILTERING_DATASET: { files: URL[]; filters: string[]; output: URL[] }[] =
pathToFileURL('tests/unit/users/delete.spec.js'),
],
},
{
files: [
pathToFileURL('tests/unit/users/create.spec.js'),
pathToFileURL('tests/unit/users/edit.spec.js'),
pathToFileURL('tests/unit/users/delete.spec.js'),
pathToFileURL('tests/functional/users.spec.js'),
pathToFileURL('tests/functional/register_user.spec.js'),
],
filters: ['users/create.spec.js'],
output: [pathToFileURL('tests/unit/users/create.spec.js')],
},
]

test.describe('Files manager | grep', () => {
Expand Down

0 comments on commit 8962d42

Please sign in to comment.