-
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): fixed the hooks implementation
- Loading branch information
Showing
9 changed files
with
190 additions
and
70 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,5 @@ | ||
--- | ||
"quickpickle": patch | ||
--- | ||
|
||
Fixed errors in the hook implementations. |
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,27 +1,5 @@ | ||
import parse from '@cucumber/tag-expressions'; | ||
|
||
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 const tagsFunction = (tagsExpression?: string): (tags: string[]) => boolean => { | ||
if (!tagsExpression) { | ||
return (tags: string[]) => true; | ||
} | ||
|
||
const parsedTagsExpression = parseTagsExpression(tagsExpression); | ||
|
||
return (tags: string[]) => { | ||
const result = parsedTagsExpression.evaluate(tags); | ||
return result; | ||
}; | ||
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}`) | ||
} |
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,34 @@ | ||
@sequential | ||
Feature: Testing hooks | ||
|
||
As a behavioral test writer | ||
I need a consistent way to run code before and after steps, scenarios, and test runs | ||
|
||
Scenario: Hooks: All hooks should work | ||
Given I run the tests | ||
Then the tests should pass | ||
|
||
@soft | ||
Scenario: Hooks: Hooks also work on @soft tests | ||
Given I run the tests | ||
Then the tests should pass | ||
|
||
@fails | ||
Scenario: Hooks: Errors are available in the hook | ||
Given I run the tests | ||
Then the tests should fail | ||
|
||
@clearErrorsAfterStep @soft | ||
Scenario: Hooks: The AfterStep hook can clear errors | ||
Given I run the tests | ||
Then the tests should fail | ||
|
||
@clearErrorsAfterStep @fails | ||
Scenario: Hooks: AfterStep must be @soft when clearing errors, or the test still fails | ||
Given I run the tests | ||
Then the tests should fail | ||
|
||
@soft @fails | ||
Scenario: Hooks: If the errors are not cleared, a @soft test still fails | ||
Given I run the tests | ||
Then the tests should fail |
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,69 @@ | ||
import { expect } from 'vitest'; | ||
import { Given, When, Then, BeforeAll, Before, BeforeStep, AfterStep, After, AfterAll, QuickPickleWorld } from 'quickpickle'; | ||
|
||
const log:any = {} | ||
|
||
BeforeAll(async () => { | ||
log.tests = {} | ||
}) | ||
|
||
Before(async (state) => { | ||
log.tests[state.info.scenario] = [] | ||
log.tests[state.info.scenario].push('Before') | ||
state.hooks = {} | ||
state.hooks.beforeHook = true | ||
}) | ||
|
||
BeforeStep(async (state) => { | ||
log.tests[state.info.scenario].push('BeforeStep') | ||
}) | ||
|
||
AfterStep({ tags:'clearErrorsAfterStep' }, async (state) => { | ||
state.info.errors = [] | ||
}) | ||
|
||
AfterStep(async (state) => { | ||
log.tests[state.info.scenario].push('errors: ' + state.info.errors.length) | ||
log.tests[state.info.scenario].push('AfterStep') | ||
}) | ||
|
||
After(async (state) => { | ||
log.tests[state.info.scenario].push('errors: ' + state.info.errors.length) | ||
log.tests[state.info.scenario].push('After') | ||
}) | ||
|
||
const testWithNoErrors = [ | ||
'Before', | ||
'BeforeStep', | ||
'errors: 0', | ||
'AfterStep', | ||
'BeforeStep', | ||
'errors: 0', | ||
'AfterStep', | ||
'errors: 0', | ||
'After', | ||
] | ||
|
||
const testWithError = [ | ||
'Before', | ||
'BeforeStep', | ||
'errors: 0', | ||
'AfterStep', | ||
'BeforeStep', | ||
'errors: 1', | ||
'AfterStep', | ||
'errors: 1', | ||
'After', | ||
] | ||
|
||
AfterAll(async () => { | ||
console.log('AfterAll') | ||
expect(log.tests).toMatchObject({ | ||
'Hooks: All hooks should work': testWithNoErrors, | ||
'Hooks: Hooks also work on @soft tests': testWithNoErrors, | ||
'Hooks: Errors are available in the hook': testWithError, | ||
'Hooks: The AfterStep hook can clear errors': testWithNoErrors, | ||
'Hooks: AfterStep must be @soft when clearing errors, or the test still fails': testWithNoErrors, | ||
'Hooks: If the errors are not cleared, a @soft test still fails': testWithError, | ||
}) | ||
}) |
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