test(server): make server testing utils (#5544)

This commit is contained in:
liuyi
2024-01-11 06:40:55 +00:00
parent 9253e522aa
commit 12fdb18a80
20 changed files with 238 additions and 451 deletions
@@ -1,19 +1,20 @@
/// <reference types="../src/global.d.ts" />
import { Test, TestingModule } from '@nestjs/testing';
import { TestingModule } from '@nestjs/testing';
import ava, { type TestFn } from 'ava';
import { CacheModule } from '../src/cache';
import { ConfigModule } from '../src/config';
import { SessionModule, SessionService } from '../src/session';
import { createTestingModule } from './utils';
const test = ava as TestFn<{
session: SessionService;
app: TestingModule;
module: TestingModule;
}>;
test.beforeEach(async t => {
const module = await Test.createTestingModule({
const module = await createTestingModule({
imports: [
ConfigModule.forRoot({
redis: {
@@ -23,14 +24,14 @@ test.beforeEach(async t => {
CacheModule,
SessionModule,
],
}).compile();
});
const session = module.get(SessionService);
t.context.app = module;
t.context.module = module;
t.context.session = session;
});
test.afterEach.always(async t => {
await t.context.app.close();
await t.context.module.close();
});
test('should be able to set session', async t => {