-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Start adding a new rerun order #2067
Open
aslakhellesoy
wants to merge
6
commits into
main
Choose a base branch
from
add-rerun-order
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
abc19b3
Start adding a new rerun order
aslakhellesoy 35db65e
implement the rerun ordering
IMalaniak ea766bc
move PickleWithDocuments out of public types
IMalaniak 82dc722
mark unexpandedFeaturePaths as optional
IMalaniak 25513d1
implement check for correct rerun file
IMalaniak cb69d4f
Merge branch 'main' into add-rerun-order
aslakhellesoy 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 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 |
---|---|---|
|
@@ -7,7 +7,12 @@ import { OptionSplitter } from '../configuration' | |
import { Readable } from 'stream' | ||
import os from 'os' | ||
import * as messages from '@cucumber/messages' | ||
import { IdGenerator } from '@cucumber/messages' | ||
import { | ||
GherkinDocument, | ||
IdGenerator, | ||
Location, | ||
Pickle, | ||
} from '@cucumber/messages' | ||
import detectCiEnvironment from '@cucumber/ci-environment' | ||
import { ISupportCodeLibrary } from '../support_code_library_builder/types' | ||
import TestCaseHookDefinition from '../models/test_case_hook_definition' | ||
|
@@ -16,12 +21,19 @@ import { PickleOrder } from '../models/pickle_order' | |
import { builtinParameterTypes } from '../support_code_library_builder' | ||
import { version } from '../version' | ||
|
||
export interface PickleWithDocument { | ||
gherkinDocument: GherkinDocument | ||
location: Location | ||
pickle: Pickle | ||
} | ||
|
||
interface IParseGherkinMessageStreamRequest { | ||
cwd?: string | ||
eventBroadcaster: EventEmitter | ||
eventDataCollector: EventDataCollector | ||
gherkinMessageStream: Readable | ||
order: string | ||
unexpandedFeaturePaths?: string[] | ||
pickleFilter: PickleFilter | ||
} | ||
|
||
|
@@ -34,13 +46,15 @@ interface IParseGherkinMessageStreamRequest { | |
* @param eventDataCollector | ||
* @param gherkinMessageStream | ||
* @param order | ||
* @param unexpandedFeaturePaths | ||
* @param pickleFilter | ||
*/ | ||
export async function parseGherkinMessageStream({ | ||
eventBroadcaster, | ||
eventDataCollector, | ||
gherkinMessageStream, | ||
order, | ||
unexpandedFeaturePaths, | ||
pickleFilter, | ||
}: IParseGherkinMessageStreamRequest): Promise<string[]> { | ||
return await new Promise<string[]>((resolve, reject) => { | ||
|
@@ -59,7 +73,7 @@ export async function parseGherkinMessageStream({ | |
} | ||
}) | ||
gherkinMessageStream.on('end', () => { | ||
orderPickles(result, order, console) | ||
orderPickles(result, order, unexpandedFeaturePaths, console) | ||
resolve(result) | ||
}) | ||
gherkinMessageStream.on('error', reject) | ||
|
@@ -70,6 +84,7 @@ export async function parseGherkinMessageStream({ | |
export function orderPickles<T = string>( | ||
pickleIds: T[], | ||
order: PickleOrder, | ||
unexpandedFeaturePaths: string[] | undefined, | ||
logger: Console | ||
): void { | ||
const [type, seed] = OptionSplitter.split(order) | ||
|
@@ -85,6 +100,36 @@ export function orderPickles<T = string>( | |
shuffle(pickleIds, seed) | ||
} | ||
break | ||
case 'rerun': | ||
{ | ||
if (unexpandedFeaturePaths === undefined) { | ||
throw new Error( | ||
'Cannot order by rerun because no unexpandedFeaturePaths were provided' | ||
) | ||
} | ||
|
||
const picklesWithDocument = | ||
pickleIds as unknown[] as PickleWithDocument[] | ||
|
||
picklesWithDocument.sort((a, b) => { | ||
const pathA = `${a.pickle.uri}:${a.location.line}` | ||
const pathB = `${b.pickle.uri}:${b.location.line}` | ||
const indexA = unexpandedFeaturePaths.indexOf(pathA) | ||
const indexB = unexpandedFeaturePaths.indexOf(pathB) | ||
if (indexA === -1) { | ||
throw new Error( | ||
`Cannot use rerun order because ${pathA} was not in the rerun order. Did you forget to specify @rerun.txt?` | ||
) | ||
} | ||
if (indexB === -1) { | ||
throw new Error( | ||
`Cannot use rerun order because ${pathB} was not in the rerun order. Did you forget to specify @rerun.txt?` | ||
) | ||
} | ||
return indexA - indexB | ||
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. Note I think this could be something like const ordered = new Array(unexpandedFeaturePaths.length);
picklesWithDocument.forEach(item => {
// get index in unexpandedFeaturePaths, throw if not found
ordered[index] = item
})
// remove empty indexes (only occurs if have duplicates in list and we just use the first) That should be O(n) instead O(nlogn) |
||
}) | ||
} | ||
break | ||
default: | ||
throw new Error( | ||
'Unrecgonized order type. Should be `defined` or `random`' | ||
|
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 +1 @@ | ||
export type PickleOrder = 'defined' | 'random' | string | ||
export type PickleOrder = 'defined' | 'random' | 'rerun' | string |
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.
This function is deprecated and will be removed in a future major release, however in the meantime it'd be better to avoid making a breaking change to it. Could we make the new field optional?
(It's fine to change
orderPickles
, that's an internal one.)