test: always exec afterEach in ava test (#4303)

Co-authored-by: Peng Xiao <pengxiao@outlook.com>
This commit is contained in:
X1a0t
2023-09-11 17:30:39 +08:00
committed by GitHub
parent 49c8928a09
commit a25a31c105
14 changed files with 20 additions and 15 deletions

View File

@@ -68,7 +68,7 @@ test.beforeEach(async t => {
await t.context.app.init();
});
test.afterEach(async t => {
test.afterEach.always(async t => {
await t.context.app.close();
});

View File

@@ -42,7 +42,7 @@ test.beforeEach(async () => {
auth = module.get(AuthService);
});
test.afterEach(async () => {
test.afterEach.always(async () => {
await module.close();
});

View File

@@ -1,16 +1,21 @@
import { Test } from '@nestjs/testing';
import { Test, TestingModule } from '@nestjs/testing';
import test from 'ava';
import { Config, ConfigModule } from '../config';
let config: Config;
let module: TestingModule;
test.beforeEach(async () => {
const module = await Test.createTestingModule({
module = await Test.createTestingModule({
imports: [ConfigModule.forRoot()],
}).compile();
config = module.get(Config);
});
test.afterEach.always(async () => {
await module.close();
});
test('should be able to get config', t => {
t.true(typeof config.host === 'string');
t.is(config.env, 'test');

View File

@@ -40,7 +40,7 @@ test.beforeEach(async () => {
await app.init();
});
test.afterEach(async () => {
test.afterEach.always(async () => {
await app.close();
await m.close();
timer.restore();

View File

@@ -54,7 +54,7 @@ test.beforeEach(async () => {
await app.init();
});
test.afterEach(async () => {
test.afterEach.always(async () => {
await app.close();
});

View File

@@ -65,7 +65,7 @@ test.beforeEach(async () => {
auth = module.get(AuthService);
});
test.afterEach(async () => {
test.afterEach.always(async () => {
await module.close();
});

View File

@@ -114,7 +114,7 @@ test.beforeEach(async () => {
mail = module.get(MailService);
});
test.afterEach(async () => {
test.afterEach.always(async () => {
await app.close();
});

View File

@@ -17,7 +17,7 @@ test.beforeEach(async () => {
metrics = module.get(Metrics);
});
test.afterEach(async () => {
test.afterEach.always(async () => {
await module.close();
});

View File

@@ -27,7 +27,7 @@ test.beforeEach(async t => {
t.context.session = session;
});
test.afterEach(async t => {
test.afterEach.always(async t => {
await t.context.app.close();
});

View File

@@ -33,7 +33,7 @@ test.beforeEach(async () => {
await app.init();
});
test.afterEach(async () => {
test.afterEach.always(async () => {
await app.close();
});

View File

@@ -45,7 +45,7 @@ test.beforeEach(async () => {
await app.init();
});
test.afterEach(async () => {
test.afterEach.always(async () => {
await app.close();
});

View File

@@ -56,7 +56,7 @@ test.beforeEach(async t => {
t.context.mail = mail;
});
test.afterEach(async t => {
test.afterEach.always(async t => {
await t.context.app.close();
});

View File

@@ -59,7 +59,7 @@ test.beforeEach(async t => {
await t.context.app.init();
});
test.afterEach(async t => {
test.afterEach.always(async t => {
await t.context.app.close();
});

View File

@@ -48,7 +48,7 @@ test.beforeEach(async t => {
t.context.app = app;
});
test.afterEach(async t => {
test.afterEach.always(async t => {
await t.context.app.close();
});