-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
format: report total steps correctly in progress bar (#1669)
* make cck fail: remove reordering of testCase messages * add new function to deal with testCase * dont emit testCase from PickleRunner * include in result * fix up some tests * move tests to right places * emit test cases from serial runtime * scrappy impl to get serial working * remove unused field * refactor structures, fix tests * make coordinator api more promisey * start to hook up parallel * assemble test cases without ITestStep * remove unused function * TestCase is source of truth * TestCaseRunner is more accurate than PickleRunner? * make parallel runtime work with this * add explanatory comment * fix progress bar formatter counts * changelog * remove temp tag Co-authored-by: Aurélien Reeves <[email protected]> * clarify changelog entry audience * cleanup Co-authored-by: Aurélien Reeves <[email protected]>
- Loading branch information
1 parent
ee90922
commit 226f0fb
Showing
16 changed files
with
732 additions
and
437 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
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,135 @@ | ||
import { EventEmitter } from 'events' | ||
import * as messages from '@cucumber/messages' | ||
import { IdGenerator } from '@cucumber/messages' | ||
import { ISupportCodeLibrary } from '../support_code_library_builder/types' | ||
import { Group } from '@cucumber/cucumber-expressions' | ||
import { doesHaveValue } from '../value_checker' | ||
import { clone } from 'lodash' | ||
|
||
export declare type IAssembledTestCases = Record<string, messages.TestCase> | ||
|
||
export interface IAssembleTestCasesOptions { | ||
eventBroadcaster: EventEmitter | ||
newId: IdGenerator.NewId | ||
pickles: messages.Pickle[] | ||
supportCodeLibrary: ISupportCodeLibrary | ||
} | ||
|
||
export async function assembleTestCases({ | ||
eventBroadcaster, | ||
newId, | ||
pickles, | ||
supportCodeLibrary, | ||
}: IAssembleTestCasesOptions): Promise<IAssembledTestCases> { | ||
const result: IAssembledTestCases = {} | ||
for (const pickle of pickles) { | ||
const { id: pickleId } = pickle | ||
const testCaseId = newId() | ||
const fromBeforeHooks: messages.TestStep[] = makeBeforeHookSteps({ | ||
supportCodeLibrary, | ||
pickle, | ||
newId, | ||
}) | ||
const fromStepDefinitions: messages.TestStep[] = makeSteps({ | ||
pickle, | ||
supportCodeLibrary, | ||
newId, | ||
}) | ||
const fromAfterHooks: messages.TestStep[] = makeAfterHookSteps({ | ||
supportCodeLibrary, | ||
pickle, | ||
newId, | ||
}) | ||
const testCase: messages.TestCase = { | ||
pickleId, | ||
id: testCaseId, | ||
testSteps: [ | ||
...fromBeforeHooks, | ||
...fromStepDefinitions, | ||
...fromAfterHooks, | ||
], | ||
} | ||
eventBroadcaster.emit('envelope', { testCase }) | ||
result[pickleId] = testCase | ||
} | ||
return result | ||
} | ||
|
||
function makeAfterHookSteps({ | ||
supportCodeLibrary, | ||
pickle, | ||
newId, | ||
}: { | ||
supportCodeLibrary: ISupportCodeLibrary | ||
pickle: messages.Pickle | ||
newId: IdGenerator.NewId | ||
}): messages.TestStep[] { | ||
return clone(supportCodeLibrary.afterTestCaseHookDefinitions) | ||
.reverse() | ||
.filter((hookDefinition) => hookDefinition.appliesToTestCase(pickle)) | ||
.map((hookDefinition) => ({ | ||
id: newId(), | ||
hookId: hookDefinition.id, | ||
})) | ||
} | ||
|
||
function makeBeforeHookSteps({ | ||
supportCodeLibrary, | ||
pickle, | ||
newId, | ||
}: { | ||
supportCodeLibrary: ISupportCodeLibrary | ||
pickle: messages.Pickle | ||
newId: IdGenerator.NewId | ||
}): messages.TestStep[] { | ||
return supportCodeLibrary.beforeTestCaseHookDefinitions | ||
.filter((hookDefinition) => hookDefinition.appliesToTestCase(pickle)) | ||
.map((hookDefinition) => ({ | ||
id: newId(), | ||
hookId: hookDefinition.id, | ||
})) | ||
} | ||
|
||
function makeSteps({ | ||
pickle, | ||
supportCodeLibrary, | ||
newId, | ||
}: { | ||
pickle: messages.Pickle | ||
supportCodeLibrary: ISupportCodeLibrary | ||
newId: () => string | ||
}): messages.TestStep[] { | ||
return pickle.steps.map((pickleStep) => { | ||
const stepDefinitions = supportCodeLibrary.stepDefinitions.filter( | ||
(stepDefinition) => stepDefinition.matchesStepName(pickleStep.text) | ||
) | ||
return { | ||
id: newId(), | ||
pickleStepId: pickleStep.id, | ||
stepDefinitionIds: stepDefinitions.map( | ||
(stepDefinition) => stepDefinition.id | ||
), | ||
stepMatchArgumentsLists: stepDefinitions.map((stepDefinition) => { | ||
const result = stepDefinition.expression.match(pickleStep.text) | ||
return { | ||
stepMatchArguments: result.map((arg) => { | ||
return { | ||
group: mapArgumentGroup(arg.group), | ||
parameterTypeName: arg.parameterType.name, | ||
} | ||
}), | ||
} | ||
}), | ||
} | ||
}) | ||
} | ||
|
||
function mapArgumentGroup(group: Group): messages.Group { | ||
return { | ||
start: group.start, | ||
value: group.value, | ||
children: doesHaveValue(group.children) | ||
? group.children.map((child) => mapArgumentGroup(child)) | ||
: undefined, | ||
} | ||
} |
Oops, something went wrong.