karma: Calling config.set asynchronously not working

I’m trying to call config.set asynchronously in my configuration function. Doing this because we use a tool that finds an available port asynchronously, so we don’t have all the configuration at the time the call to our configuration function is made. It appears as though the function never gets called.

About this issue

  • Original URL
  • State: closed
  • Created 10 years ago
  • Reactions: 4
  • Comments: 18 (2 by maintainers)

Most upvoted comments

i am having same problem, but not for port checking but rather parsing some environment configs with shell-source which only works async. so our webpack config is actually a promise but karma does not accept that.

changing this will break backwards compatibility

Would it? It seems like currently, JS Karma config files export plain objects. They could be backward-compatibly distinguished from thenables (terminology from here) by the presence of a then function-valued property. Supposing it’s safe to say that no function-valued then properties might currently be used for anything…

🎉 This issue has been resolved in version 6.3.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

This sure would simplify things for karma configurations involving starting upstreamProxy and finding available ports etc. Right now I am finding myself writing wrapper CLI for karma to coordinate upstreamProxy servers and karma server starts so I don’t have to include boilerplate scripts in all my projects that need them. If I could just make the exported function that calls config.set() return a promise, that would me wonderful.

I’d suggest going the route @maksimr has suggested and starting karma programmatically. That way you can do all of your async setup first, and then as a final step pass the constructed config to karma.

It does invert things compared to using the cli, but it will work fine.