-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cli): Support specifying a line number when filtering tests (#6411)
Co-authored-by: Vladimir <[email protected]>
- Loading branch information
1 parent
bf7b36a
commit 4d94b95
Showing
30 changed files
with
584 additions
and
76 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 |
---|---|---|
@@ -1,5 +1,6 @@ | ||
export type { | ||
CancelReason, | ||
FileSpec, | ||
VitestRunner, | ||
VitestRunnerConfig, | ||
VitestRunnerConstructor, | ||
|
This file contains 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 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 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 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,49 @@ | ||
import { groupBy } from '../../utils/base' | ||
import { RangeLocationFilterProvidedError } from '../errors' | ||
|
||
export function parseFilter(filter: string): Filter { | ||
const colonIndex = filter.lastIndexOf(':') | ||
if (colonIndex === -1) { | ||
return { filename: filter } | ||
} | ||
|
||
const [parsedFilename, lineNumber] = [ | ||
filter.substring(0, colonIndex), | ||
filter.substring(colonIndex + 1), | ||
] | ||
|
||
if (lineNumber.match(/^\d+$/)) { | ||
return { | ||
filename: parsedFilename, | ||
lineNumber: Number.parseInt(lineNumber), | ||
} | ||
} | ||
else if (lineNumber.match(/^\d+-\d+$/)) { | ||
throw new RangeLocationFilterProvidedError(filter) | ||
} | ||
else { | ||
return { filename: filter } | ||
} | ||
} | ||
|
||
interface Filter { | ||
filename: string | ||
lineNumber?: undefined | number | ||
} | ||
|
||
export function groupFilters(filters: Filter[]) { | ||
const groupedFilters_ = groupBy(filters, f => f.filename) | ||
const groupedFilters = Object.fromEntries(Object.entries(groupedFilters_) | ||
.map((entry) => { | ||
const [filename, filters] = entry | ||
const testLocations = filters.map(f => f.lineNumber) | ||
|
||
return [ | ||
filename, | ||
testLocations.filter(l => l !== undefined) as number[], | ||
] | ||
}), | ||
) | ||
|
||
return groupedFilters | ||
} |
This file contains 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
Oops, something went wrong.