forcedotcom / LightningTestingService

Apache License 2.0
122 stars 35 forks source link

Sleep utility function #21

Closed keirbowden closed 7 years ago

keirbowden commented 7 years ago

It would be useful to have a sleep type function in the $T namespace. For example, I have moved some singleton functionality into a JavaScript library that my components load via ltng:require and they defer their initialisation until that script is loaded. In the case of unit tests I just want to sleep for a couple of seconds to allow the library to load and then carry out the tests.

I don't want to artificially set an attribute or the like just to be able to use waitFor, and given that my lightning component might be running at a different API version to the baseTestRunner component I can't guarantee that I can load it there and attach it to the correct Window/SecureWindow object.

I've written my own, obviously, but not the most efficient if everyone has to do that going forward :)

esalman-sfdc commented 7 years ago

I am wondering how can this be achieved without making the tests flappy/brittle. For example, for selenium/webdriver as well it has become a fairly standard best-practice to wait for something vs sleeping as a result of test owners getting burnt by flaky results :)

As you pointed out, if all components have locker enabled (v.40+) its easier to do (by letting the library add some marker). Is there anything else that the component under test do you could wait on (directly or via a test-wrapper component)?

Basically I am worried that providing a utility like sleep (well versed users like yourself may not be impacted as much) may result in adoption of an anti-pattern (one that results in false positives when it comes to failures).

What do you think?

keirbowden commented 7 years ago

I take your point about the fact that sleeping is brittle, but I'm also loathe to set attributes solely for the purpose of indicating to tests that they can proceed. Interesting that you bring up Selenium as that was the same direction I was coming from. I'll have a bit more of a think about it over the next few days.

keirbowden commented 7 years ago

I'll cave on this one - I can't come up with a good rebuttal to your reasons :)