Skip to content
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

Unnecessarily inserts await #40

Open
amk221 opened this issue Jan 16, 2020 · 7 comments
Open

Unnecessarily inserts await #40

amk221 opened this issue Jan 16, 2020 · 7 comments

Comments

@amk221
Copy link

amk221 commented Jan 16, 2020

If this code mod is run on an app a second time (to update more tests that have since been added), then it does this:

click('button'); // Intentionally no await
await waitUntil(() => { ... });
await click('button'); // Intentionally no await
await waitUntil(() => { ... });

This then breaks the test suite because await click waits for everything to settle, so waitUntil can't do it's thing.

@snewcomer
Copy link

Is the condition inside waitUntil ephemeral? Meaning, even after a macro task tick + settledness, I would imagine the condition would still be truthy?

@amk221
Copy link
Author

amk221 commented Jan 17, 2020

I’ll set up a test repo. It could well be me doing something wrong.

@amk221
Copy link
Author

amk221 commented Jan 18, 2020

Here is a test repo.

If the codemod is run against it, it will insert await, where there was intentionally no await to begin with.

Related discord conversation (from July 2019)

@snewcomer
Copy link

Oh you are testing intermediate states. My bad.

Because tests were not async/await before, the more general assumption of this codemod is that the tests are now enabled with this feature. So I'm not sure there is a way to infer that you are testing intermediate states with the codemod sadly.

Reference tests:

https://github.com/ember-codemods/ember-test-helpers-codemod/blob/master/transforms/integration/__testfixtures__/click.input.js

https://github.com/ember-codemods/ember-test-helpers-codemod/blob/master/transforms/integration/__testfixtures__/click.output.js

@amk221
Copy link
Author

amk221 commented Jan 19, 2020

Are you saying it’s not possible to fix?

It’s a very annoying bug... consider a large app with a big team of varying ember experience...

The ‘old’ (or less desirable) techniques for testing are still perfectly, so it’s still useful to run this codemod against an app that it has already been run on.

But this means we then have to go through the diff (which could be huge, and remove all the awaits that have been put back.

@snewcomer
Copy link

I'm sure we could avoid adding await if the callback is already async/await enabled (thus we can make the a reasonable assumption you are testing an intermediate state). But otherwise no. Do you think that might help?

@amk221
Copy link
Author

amk221 commented Jan 19, 2020

I think so! Tbh I'm surprised nobody else has mention this before :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants