Skip to content

Snapshot property warnings work incorrectly with helper functions #5449

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

Closed
Ogurecher opened this issue Aug 24, 2020 · 9 comments · Fixed by #5584
Closed

Snapshot property warnings work incorrectly with helper functions #5449

Ogurecher opened this issue Aug 24, 2020 · 9 comments · Fixed by #5584
Assignees
Labels
AREA: server FREQUENCY: critical SYSTEM: API TYPE: bug The described behavior is considered as wrong (bug).
Milestone

Comments

@Ogurecher
Copy link
Contributor

Using the example code from @Ogurecher I also get the warnings, despite them not being prefixed by await.

I am honestly baffled how a super hacky method like checking line numbers ever got merged. Not least because autoformatters such as Prettier will force the expect and selector to be on the same line in most cases. Adding a warning of this kind is fine but not with this implementation. I have made a hacky fix by putting my selectors on different lines for now but I hope this is changed in a future release.

Regardless, for me personally it is failing even with selector and expect on the same line and I've forked @Ogurecher 's sample repo and made a reproducable sample: https://github.com/favna/warning-example
Simply run npm run test to run testcafe here

Originally posted by @favna in #5250 (comment)

@Ogurecher
Copy link
Contributor Author

@favna, Thank you for the example. I've reproduced the issue on my side.

@favna
Copy link

favna commented Aug 24, 2020

Thanks for migrating my comment to an issue and trying my sample. Looking forward to see progress here.

@need-response-app need-response-app bot added the STATE: Need response An issue that requires a response or attention from the team. label Aug 24, 2020
@Ogurecher Ogurecher removed the STATE: Need response An issue that requires a response or attention from the team. label Aug 24, 2020
@xorxero
Copy link

xorxero commented Sep 11, 2020

Can this be solved already?

Makes looking through logs a nightmare I have to scroll thousands of lines of this useless warning to find what actually failed.

At least give an option to disable the warning.

@need-response-app need-response-app bot added the STATE: Need response An issue that requires a response or attention from the team. label Sep 11, 2020
@AndreyBelym
Copy link
Contributor

I set the critical status for this issue. We are trying to find a solution as soon as possible, stay tuned for updates.

@need-response-app need-response-app bot removed the STATE: Need response An issue that requires a response or attention from the team. label Sep 11, 2020
@AndreyBelym AndreyBelym added this to the Sprint #65 milestone Sep 14, 2020
@Ogurecher
Copy link
Contributor Author

#5389 (comment)

@Khartir
Copy link

Khartir commented Sep 25, 2020

@xorxero: I just stumbled upon this issue. A workaround is described here

@need-response-app need-response-app bot added the STATE: Need response An issue that requires a response or attention from the team. label Sep 25, 2020
@Ogurecher Ogurecher removed STATE: Need response An issue that requires a response or attention from the team. STATE: Need research labels Sep 25, 2020
@Ogurecher
Copy link
Contributor Author

For the team:
This issue is caused by the same reason as #5389.

When the snapshot property promise is resolved, its callsite is saved to a callsite storage. We check this storage in the .expect assertion call. If the storage contains a callsite with the same filename and lineNumber as the .expect's callsite, we delete it and raise a warning.

If the property was not awaited, the .expect would execute before the property promise's .then method. Thus, some callsites would remain in the storage after they were asserted (we delete them only in .expect). It works fine if we use our assertion only once, but causes the warnings to raise if we call .expect from the same line of code again.

@kflore16
Copy link

kflore16 commented Nov 24, 2021

Hello I have a helper class with a method that asserts a few things and this helper class extends a different helper class because it uses some of its functions.

async fillField(field) {
    const fieldSelector = await this.getInputSelector(
      field.fieldType,
      field.fieldKey
    )
    await t
      .expect(fieldSelector.textContent) //this flags the warning
      .notContains(field.name, { timeout: 20000 })
     //More stuff

raises that warning above.
The structure of the logic is that (inherited).getInputSelector(value,value) uses that value to determine the function to be used then returns the Selector passed by the other function thus resulting in a chain of await's per function reference like so:

targetSelector = await getInputSelector(string data, returns the Selector returned from next function) -> await getTypeSelector(string data, returns the Selector returned from next function) -> await fieldTypeSelector(string data and returns the selector)

It is not the case that at each return the data is wrapped in Selector() as it only gets returned as a Selector from fieldTypeSelector() function propogated downward.

TestCafe version 1.16.1

@need-response-app need-response-app bot added the STATE: Need response An issue that requires a response or attention from the team. label Nov 24, 2021
@AlexKamaev
Copy link
Contributor

@kflore16
This issue is closed. Please create a separate issue and share an example that we can run without any additional setup.

@need-response-app need-response-app bot removed the STATE: Need response An issue that requires a response or attention from the team. label Nov 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
AREA: server FREQUENCY: critical SYSTEM: API TYPE: bug The described behavior is considered as wrong (bug).
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants