@@ -3,9 +3,9 @@ import path from 'node:path';
33import { mock } from 'node:test' ;
44
55import { CrosscutAdviceFactory } from '@eggjs/aop-decorator' ;
6- import { EggPrototypeLifecycleUtil , LoadUnitFactory , LoadUnitLifecycleUtil } from '@eggjs/metadata' ;
7- import { CoreTestHelper , EggTestContext } from '@eggjs/module-test-util' ;
8- import { EggObjectLifecycleUtil , LoadUnitInstanceFactory } from '@eggjs/tegg-runtime' ;
6+ import { EggPrototypeLifecycleUtil , LoadUnitLifecycleUtil } from '@eggjs/metadata' ;
7+ import { CoreTestHelper , EggTestContext , LoaderUtil } from '@eggjs/module-test-util' ;
8+ import { EggObjectLifecycleUtil } from '@eggjs/tegg-runtime' ;
99import type { LoadUnitInstance } from '@eggjs/tegg-types' ;
1010import { describe , beforeEach , afterEach , it } from 'vitest' ;
1111
@@ -64,10 +64,7 @@ describe('test/aop-runtime.test.ts', () => {
6464 } ) ;
6565
6666 afterEach ( async ( ) => {
67- for ( const module of modules ) {
68- await LoadUnitFactory . destroyLoadUnit ( module . loadUnit ) ;
69- await LoadUnitInstanceFactory . destroyLoadUnitInstance ( module ) ;
70- }
67+ await CoreTestHelper . destroyModules ( modules ) ;
7168 EggPrototypeLifecycleUtil . deleteLifecycle ( eggPrototypeCrossCutHook ) ;
7269 LoadUnitLifecycleUtil . deleteLifecycle ( loadUnitAopHook ) ;
7370 EggObjectLifecycleUtil . deleteLifecycle ( eggObjectAopHook ) ;
@@ -182,12 +179,23 @@ describe('test/aop-runtime.test.ts', () => {
182179 EggObjectLifecycleUtil . registerLifecycle ( eggObjectAopHook ) ;
183180 } ) ;
184181
182+ afterEach ( ( ) => {
183+ EggPrototypeLifecycleUtil . deleteLifecycle ( eggPrototypeCrossCutHook ) ;
184+ LoadUnitLifecycleUtil . deleteLifecycle ( loadUnitAopHook ) ;
185+ EggObjectLifecycleUtil . deleteLifecycle ( eggObjectAopHook ) ;
186+ } ) ;
187+
185188 it ( 'should throw' , async ( ) => {
186- await assert . rejects ( async ( ) => {
187- await CoreTestHelper . prepareModules ( [
188- path . join ( __dirname , 'fixtures/modules/should_throw' ) ,
189- ] ) ;
190- } , / A o p A d v i c e \( P o i n t c u t A d v i c e \) n o t f o u n d i n l o a d U n i t s / ) ;
189+ const modulePath = path . join ( __dirname , 'fixtures/modules/should_throw' ) ;
190+ const { innerObjectLoadUnitInstance } = await LoaderUtil . buildGlobalGraph ( [ modulePath ] ) ;
191+ try {
192+ await assert . rejects (
193+ ( ) => CoreTestHelper . getLoadUnitInstance ( modulePath ) ,
194+ / A o p A d v i c e \( P o i n t c u t A d v i c e \) n o t f o u n d i n l o a d U n i t s / ,
195+ ) ;
196+ } finally {
197+ await CoreTestHelper . destroyModules ( [ innerObjectLoadUnitInstance ] ) ;
198+ }
191199 } ) ;
192200 } ) ;
193201
@@ -219,10 +227,7 @@ describe('test/aop-runtime.test.ts', () => {
219227 } ) ;
220228
221229 afterEach ( async ( ) => {
222- for ( const module of modules ) {
223- await LoadUnitFactory . destroyLoadUnit ( module . loadUnit ) ;
224- await LoadUnitInstanceFactory . destroyLoadUnitInstance ( module ) ;
225- }
230+ await CoreTestHelper . destroyModules ( modules ) ;
226231 EggPrototypeLifecycleUtil . deleteLifecycle ( eggPrototypeCrossCutHook ) ;
227232 LoadUnitLifecycleUtil . deleteLifecycle ( loadUnitAopHook ) ;
228233 EggObjectLifecycleUtil . deleteLifecycle ( eggObjectAopHook ) ;
0 commit comments