question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to test lazy Engines

See original GitHub issue

WARNING: Long post ahead with lots of details

Current State of Things

Lazy Engines pose an interesting problem with testing. Since web application test suites generally don’t start a unique browser instance (or even tab instance) for each test, any assets loaded during one test are likely to persist to all subsequent tests. Additionally, since the test modules are defined eagerly, all imports for those test most be present at the beginning of loading the test suite. This has led to the current recommendation that all lazy assets be loaded preemptively in testing environments, using the preloadAssets helper provided by ember-asset-loader.

This approach leaves much to be desired as at no point do you actually test the lazy loading behavior. This is especially important when working with an application with multiple lazy Engines as it is impossible to identify user flow-dependent failures, such as one area accidentally depending on a lazily loaded asset, during your automated testing.

Previously Discussed Solutions

One theoretical approach to fix the above problem is to run each test as part of a unique context, through either multiple browser instances or even iframes. This however is likely to incur a significant performance penalty when used with large test suites as larger applications are likely to have a high initial start up cost. In some test attempts, this has been prohibitively expensive even with distributed/parallelized test suites.

Proposed Solution

Given the above, it seems likely that the best approach lies somewhere between “load all the things upfront” and “reset the world for every test”. To that end, an approach similar to one @rwjblue has brought up seems to make sense. That is, at the start of a test suite, we should capture a list of all loaded modules, then, after each test, we can evict any modules that are not part of that initial list and unload <script> and <link> elements that were introduced.

One potential concern with this approach is that it won’t properly account for modules that alter global modules or leave some residual state. This is a problem, but I do not think it is one for us to try and solve as these issues are likely to surface even with preloading of all assets. We can detect new globals by using QUnit.config.noglobals, but the other class of issues will likely be highly specific to the application under test.

Given the above, I think the “module reset” solution is likely to yield the best results.

cc/ @rwjblue @nathanhammond

Issue Analytics

  • State:open
  • Created 7 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
mydeacommented, Feb 21, 2017

Sure, I opened #341 !

0reactions
trentmwilliscommented, Feb 20, 2017

@mydea can you please open a new issue for your specific problem?

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to test Reac Lazy inside an object - Stack Overflow
You can use @testing-library/react to test the React.lazy() method. In addition, if the lazy-loaded component is too complex and you only ...
Read more >
Tracing sensor wiring and checking for 'lazy' sensors - Issuu
Tracing sensor wiring and checking for 'lazy' sensors ... The B stands for “bank,” and 1 and 2 indicates which bank of the...
Read more >
ember-engines/engine-testing: A dummy application ... - GitHub
A dummy application to verify the build system of ember-engines - GitHub - ember-engines/engine-testing: A dummy application to verify the build system of ......
Read more >
Lazy Parsing in JavaScript Engines - ariya.io
In reality, lazy parser can be slightly complicated, this involves handling strict mode properly, making sure parsing error is taken care, ...
Read more >
Lazy JavaScript Parsing in V8 - Matt Zeunert
JavaScript engines use a mechanism called lazy parsing to run code more quickly. This post will explain lazy parsing, how it's beneficial, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found