-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Calling config.set asynchronously not working #1259
Comments
To demonstrate this, you can do this: 'use strict';
module.exports = function(config) {
var configuration = {...};
setTimeout(config.set.bind(config), 10, [configuration]);
}; |
It looks like this isn't really a bug, and is just bad design. The config.set function simply replaces object properties on the configuration object. It does not notify karma when configuration is finalized, therefore, In any case I'm fairly sure changing this will break backwards compatibility. So if there is an improvement here, it will probably need to go in the next release. |
@kahnjw configuration step is not asynchronous. I think this was made because it covers most cases and it is simple. Now Something like this: getFreeAvailablePort.sh && karma start or run karma programmatically from node script how it do karma-grunt.
Really I don't see problem with function
PR welcome Thanks! |
The way it is currently we give the user a callback to extend configuration with. That is fine, but in javascript, when given a callback, one expects it will behave the same whether called synchronously or asynchronously. If the goal is to require a synchronous extend, for whatever reason, it would be more clear to require something like this: module.exports = function(config) {
return config.extend({
my: 'overrides'
});
}; Making the user return the extended object makes it clear that this must be done synchronously. I say this because I spent about 30 minutes trying to figure this out, assuming that
I'd like to help out with this and I'll be looking into making it async today. Thanks. |
@kahnjw Any progress on making it async? |
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. |
i am having same problem, but not for port checking but rather parsing some environment configs with shell-source which only works async. |
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 |
Wow this was a long time ago. IIRC it would break compatibility if consumers are inadvertently depending on an asynchronous config.set call effectively being a noop. If you're strictly adhering to semver it's a major bump but I don't think anyone is that extreme. A minor version bump is definitely necessary though. All assuming Karma follows semver (might not though 🤷). Not sure what this has to do with thenables/promises/whatever. If a thenable were added to achieve the asynchrony through a different interface, you'd still need a minor semver bump so it's sort of all the same I guess. |
Ah, hadn't considered that. Feels very 'edge case'-y to me. Like you experienced back in 2014 (!), I suspect people have must-have information in
Yep. To clarify, my previous post was contemplating making the karma.config.js interface be "a CommonJS module whose export is either a plain object or a thenable that fulfills to a plain object". |
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. |
Any update on this issue? I am having the same problem, as the karma configuration in our project is generated asynchronously. I would like to assign the async configuration object to the configuration object in karma.conf.js to allow other developer to override it. module.exports = async function (config) {
const karmaConfig = await getKarmaConfig("dev");
config.set({
...karmaConfig
});
return config;
}; |
Is there any movement for this? What can we do to help with this? |
Also running into this issue. I plan to "hack" around this by using |
The feature boils down to adding |
@devoto13 , I was actually looking at putting together a PR, and I realized the trickle-down effect which would impact the public https://github.com/karma-runner/karma/blob/master/lib/server.js#L68 Also, I think you mean this line (maybe a recent change on master branch changed the line number?): https://github.com/karma-runner/karma/blob/master/lib/config.js#L412 If you have suggestions on how to keep the API compatible (or are willing to break API compatibility), then putting together a PR shouldn't be difficult. Perhaps just moving the config parsing into the Thanks! |
Unfortunately, this is not enough as there are other places, where I did a bit of thinking on the backward compatible design. This way we can land this feature in the minor release and then perform a breaking cleanup in the next major. Let me know what you think.
In the next major we can clean up the flag and turn this behavior on by default. This will break public API consumers, but hopefully, they are already updated by the time because of a warning. Does this sound reasonable? |
🎉 This issue has been resolved in version 6.3.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
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.The text was updated successfully, but these errors were encountered: