You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is your feature request related to a problem or a nice-to-have?? Please describe.
Before ESM, you could run mocha programmatically several times during the same process (see issues #995 and #2783). For example, this works fine:
And in that case, the tests won't run the second time. This happens because the ESM cache is used, and modules cannot be unloaded from there.
Describe the solution you'd like
As far as I know, there are two ways to deal with this problem:
Run the tests in a separate process
Use a query string or hash in the URL objects passed to the dynamic import to invalidate the cache
The first option doesn't work for us because of performance reasons, since we need to load our application again, which is kind of slow.
The second option might work. It would leak memory, but that's acceptable in our use case.
The problem is that we don't have any way to hook into the code that converts the given files to URL. If that was possible, then we would be able to pass a random hash to the resolved URLs to make sure that the cache is invalidated.
Maybe a better solution would be to accept URL objects in Mocha.addFile.
Describe alternatives you've considered
Described in the previous section.
Additional context
Our tool is a task runner that, among other things, has a test task that uses Mocha under the hood. We are working on adding support for ESM, but we need the task to work when it's programmatically called more than once during the same execution.
The text was updated successfully, but these errors were encountered:
Is your feature request related to a problem or a nice-to-have?? Please describe.
Before ESM, you could run mocha programmatically several times during the same process (see issues #995 and #2783). For example, this works fine:
If you want to support both CJS and ESM tests though, you need to add a call to
loadFilesAsync
:And in that case, the tests won't run the second time. This happens because the ESM cache is used, and modules cannot be unloaded from there.
Describe the solution you'd like
As far as I know, there are two ways to deal with this problem:
The first option doesn't work for us because of performance reasons, since we need to load our application again, which is kind of slow.
The second option might work. It would leak memory, but that's acceptable in our use case.
The problem is that we don't have any way to hook into the code that converts the given files to URL. If that was possible, then we would be able to pass a random hash to the resolved URLs to make sure that the cache is invalidated.
Maybe a better solution would be to accept URL objects in
Mocha.addFile
.Describe alternatives you've considered
Described in the previous section.
Additional context
Our tool is a task runner that, among other things, has a
test
task that uses Mocha under the hood. We are working on adding support for ESM, but we need the task to work when it's programmatically called more than once during the same execution.The text was updated successfully, but these errors were encountered: