Skip to content

Commit

Permalink
fix: clear all hooks after app close (#175)
Browse files Browse the repository at this point in the history
  • Loading branch information
killagu authored Dec 12, 2023
1 parent bb8a3bd commit 6fe12b9
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
3 changes: 3 additions & 0 deletions plugin/tegg/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,8 @@ export default class App {
if (this.configSourceEggPrototypeHook) {
this.app.loadUnitLifecycleUtil.deleteLifecycle(this.configSourceEggPrototypeHook);
}
if (this.loadUnitMultiInstanceProtoHook) {
this.app.loadUnitLifecycleUtil.deleteLifecycle(this.loadUnitMultiInstanceProtoHook);
}
}
}
24 changes: 24 additions & 0 deletions plugin/tegg/test/close.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import mm from 'egg-mock';
import assert from 'assert';
import path from 'path';

describe('test/close.test.ts', () => {
it('should clean lifecycle hooks', async () => {
mm(process.env, 'EGG_TYPESCRIPT', true);
mm(process, 'cwd', () => {
return path.join(__dirname, '..');
});
const app = mm.app({
baseDir: path.join(__dirname, 'fixtures/apps/schedule-app'),
framework: require.resolve('egg'),
});
await app.ready();
await app.close();

assert.equal(app.loadUnitLifecycleUtil.getLifecycleList().length, 0);
assert.equal(app.loadUnitInstanceLifecycleUtil.getLifecycleList().length, 0);
assert.equal(app.eggContextLifecycleUtil.getLifecycleList().length, 0);
assert.equal(app.eggPrototypeLifecycleUtil.getLifecycleList().length, 0);
assert.equal(app.eggObjectLifecycleUtil.getLifecycleList().length, 0);
});
});

0 comments on commit 6fe12b9

Please sign in to comment.