Skip to content

Issue #11132 - adding hookName to beforeHook and afterHook#11148

Merged
christian-bromann merged 14 commits intowebdriverio:mainfrom
HananArgov:master
Oct 4, 2023
Merged

Issue #11132 - adding hookName to beforeHook and afterHook#11148
christian-bromann merged 14 commits intowebdriverio:mainfrom
HananArgov:master

Conversation

@HananArgov
Copy link
Contributor

@HananArgov HananArgov commented Sep 11, 2023

Proposed changes

Adding hookName to beforeHook and afterHook per issue #11132

Types of changes

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update

Checklist

  • I have read the CONTRIBUTING doc
  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation (if appropriate)
  • I have added proper type definitions for new commands (if appropriate)

Further comments

as seen in the issue, this will able us to see which hook is referred in beforeHook and afterHook

Reviewers: @webdriverio/project-committers

Copy link
Member

@erwinheitzman erwinheitzman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice going 👍

string,
number
number,
string?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From what I can tell, this isn't optional and is always passed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'm leaving this optional, since runSpec in testInterfaceWrapper calls it as well, and then we'll add an unused argument (origFn.name is it)

) {
const retries = { attempts: 0, limit: repeatTest }
const beforeArgs = beforeFnArgs(this)
if (type !== 'Test') {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's explicitly add it to the functions we want instead of adding it to everything but Test

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'm not sure if i understood what you meant, or know how implement.

do you mean that i'll need to remove the if, so it would work with type==='Test' as well? or that when we push to this to afterArgs/beforeArgs the hookName will be inserted as well, as part of line 70.

if it's the second one, i'm a bit stumped here, since i can't quite understand how to do this (help wanted 🙂)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed the comparison to look for Hook, since we want to implement this on all hooks

@webdriverio webdriverio deleted a comment Sep 12, 2023
@webdriverio webdriverio deleted a comment Sep 12, 2023
Copy link
Member

@erwinheitzman erwinheitzman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left another comment.

We also have to update the docs and templates with the new argument

HananArgov and others added 3 commits September 12, 2023 16:25
fix according to comment

Co-authored-by: Erwin Heitzman <15839059+erwinheitzman@users.noreply.github.com>
@HananArgov
Copy link
Contributor Author

#11148 (review)
i've updated the templates and documents, except for the i18n, since I don't know the other languages

Copy link
Member

@christian-bromann christian-bromann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice to have a test for this to ensure we verify this functionality!

Copy link
Member

@christian-bromann christian-bromann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One comment on the position of the argument in the afterHook interface. Also, I still would like to see a smoke test that verifies this feature exist.

*/
afterHook?(test: Test, context: any, result: TestResult): unknown | Promise<unknown>
*/
afterHook?(test: Test, context: any, hookName: string, result: TestResult): unknown | Promise<unknown>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be a potentially breaking change for user that access the result object, how about we also add it as last argument?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'm trying to do so, but i'm getting an compiling issue with this part:
image

any idea on what to do here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

        const emitHookEvent = (
            fnName: string,
            eventType: string
        ) => (
            _test: never,
            _context: never,
            { error }: { error?: jasmine.FailedExpectation } = {},
            _hookName: never

Copy link
Member

@christian-bromann christian-bromann Sep 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just leave out the _hookName parameter

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small reminder to update the docs/templates since the argument is now last

@erwinheitzman
Copy link
Member

Ping @HananArgov

@HananArgov
Copy link
Contributor Author

sorry, i've been on vacation abroad for a while, and came back today.
i've done the changes, please review them again, hopefully I didn't miss anything

@HananArgov
Copy link
Contributor Author

any idea on why the tests failed? i'm not sure if they are related to the changes i've made

@christian-bromann
Copy link
Member

@HananArgov it seems that the coverage dropped, feel free to update the branch coverage to 88%

@HananArgov
Copy link
Contributor Author

@christian-bromann i'm now getting this issue:

packages/wdio-jasmine-framework/src/index.ts(159,33): error TS2345: Argument of type '(_test: never, _context: never, { error }?: { error?: jasmine.FailedExpectation | undefined; }) => void' is not assignable to parameter of type '(test: any, context: any, hookName: string) => unknown'.
  Types of parameters '__2' and 'hookName' are incompatible.
    Type 'string' has no properties in common with type '{ error?: FailedExpectation | undefined; }'.

I can't understand what to do here.
is there a chance maybe to arrange a video meeting to try and solve this?
I think I went way over my knowledge here

@christian-bromann
Copy link
Member

is there a chance maybe to arrange a video meeting to try and solve this?

Sure, please feel free to block a slot in the Open Office Hours.

Copy link
Member

@christian-bromann christian-bromann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work, LGTM 👍

@christian-bromann christian-bromann added the PR: New Feature 🚀 PRs that contain new features label Oct 4, 2023
@christian-bromann christian-bromann merged commit b314ac1 into webdriverio:main Oct 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

PR: New Feature 🚀 PRs that contain new features

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants