-
Notifications
You must be signed in to change notification settings - Fork 241
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
Error when mutating code that uses any-promise #1164
Comments
The code we're testing isn't in a public repo, but if it'd help I can make a cut-down example which reproduces the problem. |
@frostmar Thanks for letting us know! As a test, could you try to configure the command testrunner? |
Yup, swapping the config to I guess the stryker ChildProcessProxyWorker and code under test are then in separate processes? |
The command test runners runs the command in a separate process if I recall correctly. Other test runners run directly inside the worker (which is already a child process). So it looks like the dependency inside of stryker is not the issue, but instead the fact that your tests are executed multiple times in the same process. Is it possible for you to perform a cleanup of the promise functionality instead of relying on the closing of the process to clean it up? |
I believe it's a dependency in the stryker worker that leads to the problem, rather than running tests repeatedly. The flow of control is something like:
any-promise should be OK running the same tests multiple times, as re-registering the same implementation is harmless.
|
@frostmar thanks for spotting this issue and all your hard work! It is difficult to guarantee a clean environment. One would think you can use fs/mz without side effects... too bad 😓 The most pragmatic thing we can do is just remove mz in it's entirely from our dependencies. @simondel what do you think? |
I think we can remove fs/mz, but I believe you had some convincing arguments on why we wanted to use this package instead of the regular fs package. Do you still recall them @nicojs? |
Most definitely. We mostly (only?) use it to get a promisyfied api around The main issue with mz/fs is that it supports |
I like the fact of keeping promises. If that's not possible, we could always promisify the methods we use ourselves. |
I'm trying to remove TLDR; I thing we should introduce a utility library to the packages. Long version:
That's why I've decided to create our own promisified api. The problem is that it should be centralized an a shared dependency. I don't want to pollute the @simondel do you agree? |
@nicojs Sounds good! |
Summary
If the code under test uses package
any-promise
, and registers any promise implementation other than the default, running stryker exits with an error like this:This is because any-promise only allows one promise implementation to be registered, and once that's done it cannot be changed. In our case the code under test contains
require('any-promise/register/bluebird')
From an initial look, stryker itself doesn't use any-promise directly, but the
ChildProcessProxyWorker
usesmz/fs
which depends on any-promise.mz
doesn't require any specific promise implementation, but causes any-promise to register the default native promises, and does so first (before the code under test gets required).We'd love to use stryker on code that uses any-promise, would either of these solutions be acceptable?
Refactor the child worker code so it doesn't use any dependencies that require
any-promise
This lets the code under test be the first use of any-promise, and select the promise implementation.
The npm dependency tree suggests the only dependency in the child worker using any-promise is
mz
:Add a stryker config option to declare the promise implementation desired by the code under test; allowing it to be pre-registered with any-promise
ChildProcessProxyWorker
would be passed the config option, and callrequire(
any-promise/register/${anyPromiseLibrary)
so the preferred promise implementation would be registered before requiring any libraries in the stryker child worker which also use any-promiseStryker config
Stryker environment
note sure what the missing peer-dep is about?
Your Environment
Add stryker.log
stryker.log
The text was updated successfully, but these errors were encountered: