-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(main): fix tagged hooks implementation to match cucumber
- Loading branch information
Showing
10 changed files
with
132 additions
and
54 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
--- | ||
"quickpickle": patch | ||
--- | ||
|
||
Fix tagged hooks to match [@cucumber/cucumber implementation]. | ||
Tagged hooks are hooks that only run in the context of certain tags; | ||
for example, a BeforeAll hook that only starts the server for | ||
Features tagged with "@server". | ||
|
||
This change also adds info about the Feature to the "common" variable. | ||
|
||
[@cucumber/cucumber implementation]: | ||
https://github.com/cucumber/cucumber-js/blob/main/docs/support_files/hooks.md |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,45 @@ | ||
import { intersection } from 'lodash-es' | ||
import parse from '@cucumber/tag-expressions'; | ||
|
||
export function normalizeTags(tags?:string|string[]|undefined):string[] { | ||
if (!tags) return [] | ||
tags = Array.isArray(tags) ? tags : tags.split(/\s*,\s*/g) | ||
return tags.filter(Boolean).map(tag => tag.startsWith('@') ? tag : `@${tag}`) | ||
} | ||
|
||
/** | ||
* | ||
* @param confTags string[] | ||
* @param testTags string[] | ||
* @returns boolean | ||
*/ | ||
export function tagsMatch(confTags:string[], testTags:string[]) { | ||
let tags = intersection(confTags.map(t => t.toLowerCase()), testTags.map(t => t.toLowerCase())) | ||
return tags?.length ? tags : null | ||
} | ||
|
||
interface TagExpression { | ||
evaluate: (tags: string[]) => boolean; | ||
} | ||
|
||
const parseTagsExpression = (tagsExpression: string): TagExpression => { | ||
try { | ||
const parsedExpression = parse(tagsExpression); | ||
return parsedExpression; | ||
} catch (error) { | ||
throw new Error(`Failed to parse tag expression: ${(error as Error).message}`); | ||
} | ||
} | ||
|
||
export function tagsFunction(tagsExpression?:string):(tags: string[])=>boolean { | ||
if (!tagsExpression) { | ||
return () => true; | ||
} | ||
|
||
const parsedTagsExpression = parseTagsExpression(tagsExpression); | ||
|
||
return (tags: string[]) => { | ||
const result = parsedTagsExpression.evaluate(tags); | ||
return result; | ||
}; | ||
} |
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,5 @@ | ||
@taggedBeforeAll | ||
Feature: Tags for BeforeAll work | ||
|
||
Scenario: Hooks: testing taggedBeforeAll | ||
Then the variable "common.taggedBeforeAll" should be "taggedBeforeAll" |