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

:target :karma tests are failing when shadow.load is used #889

Closed
Valdermeyder opened this issue May 28, 2021 · 2 comments
Closed

:target :karma tests are failing when shadow.load is used #889

Valdermeyder opened this issue May 28, 2021 · 2 comments

Comments

@Valdermeyder
Copy link

Valdermeyder commented May 28, 2021

Karma throws "Exception: Error: shadow.loader API was called before shadow.loader.init!" when shadow.lazy modules are used inside a tested function

Example

https://github.com/Valdermeyder/karma-modules-support

Workaround

Add js file with next content

(function () {
  goog.global.shadow$modules = {infos: {test: null}, uris: {test: []}}
  shadow.loader.init("");
})();

to karma.conf.js -> files configuration
You can find exact code changes here

Probable solution

:target :karma should support :module-loader true configuration in the same way as :target :browser-test does:

  • It shouldn't load modules if their configuration is not provided by it should init shadow.loader when :module-loader true

Versions

  • "karma": "^6.3.2"
  • "karma-chrome-launcher": "^3.1.0"
  • "karma-cljs-test": "^0.1.0"
  • "shadow-cljs": "2.14.1"
@thheller
Copy link
Owner

thheller commented May 28, 2021

In 2.14.2 I added a new :closure-defines {shadow.loader.TEST true} option you can set for your build to put the loader into test mode. That will just treat all modules as already loaded and any load call will always succeed. It assumes that you will require the code that would otherwise be loaded dynamically directly in your test.

@Valdermeyder
Copy link
Author

@thheller thanks for the fix, it works fine. I have updated the demo repo with a fix

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