Skip to content

Commit

Permalink
Allow pool restarts on config change
Browse files Browse the repository at this point in the history
Vitest will dispose of the pool and recreate it when the Vitest config
changes. This was causing `Miniflare` instances to be disposed, then
reused when the pool was recreated. This change moves the project
cache from the module-level to a "pool-level" local variable.
  • Loading branch information
mrbbot committed Feb 7, 2024
1 parent adec570 commit ba86a74
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions packages/vitest-pool-workers/src/pool/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,7 @@ function assertCompatibleVitestVersion(ctx: Vitest) {
}

export default function (ctx: Vitest): ProcessPool {
// This function is called when config changes and may be called on re-runs
assertCompatibleVitestVersion(ctx);

return {
Expand Down Expand Up @@ -767,13 +768,15 @@ export default function (ctx: Vitest): ProcessPool {
// thingModule.importers.add(testModule);
},
async close() {
// `close()` will be called when shutting down Vitest or updating config
log.debug("Shutting down runtimes...");
const promises: Promise<unknown>[] = [];
for (const project of allProjects.values()) {
if (project.mf !== undefined) {
promises.push(forEachMiniflare(project.mf, (mf) => mf.dispose()));
}
}
allProjects.clear();
await Promise.all(promises);
},
};
Expand Down

0 comments on commit ba86a74

Please sign in to comment.