mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-25 14:28:51 +08:00
@@ -0,0 +1,40 @@
|
||||
import type { INestApplication } from '@nestjs/common';
|
||||
import type { TestFn } from 'ava';
|
||||
import ava from 'ava';
|
||||
import request from 'supertest';
|
||||
|
||||
import { buildAppModule } from '../../app.module';
|
||||
import { createTestingApp } from '../utils';
|
||||
|
||||
const test = ava as TestFn<{
|
||||
app: INestApplication;
|
||||
}>;
|
||||
|
||||
test.before('start app', async t => {
|
||||
// @ts-expect-error override
|
||||
AFFiNE.flavor = {
|
||||
type: 'doc',
|
||||
allinone: false,
|
||||
graphql: false,
|
||||
sync: false,
|
||||
renderer: false,
|
||||
doc: true,
|
||||
} satisfies typeof AFFiNE.flavor;
|
||||
const { app } = await createTestingApp({
|
||||
imports: [buildAppModule()],
|
||||
});
|
||||
|
||||
t.context.app = app;
|
||||
});
|
||||
|
||||
test.after.always(async t => {
|
||||
await t.context.app.close();
|
||||
});
|
||||
|
||||
test('should init app', async t => {
|
||||
const res = await request(t.context.app.getHttpServer())
|
||||
.get('/info')
|
||||
.expect(200);
|
||||
|
||||
t.is(res.body.flavor, 'doc');
|
||||
});
|
||||
@@ -20,6 +20,7 @@ test.before('start app', async t => {
|
||||
graphql: true,
|
||||
sync: false,
|
||||
renderer: false,
|
||||
doc: false,
|
||||
} satisfies typeof AFFiNE.flavor;
|
||||
const { app } = await createTestingApp({
|
||||
imports: [buildAppModule()],
|
||||
|
||||
@@ -18,6 +18,7 @@ test.before('start app', async t => {
|
||||
graphql: false,
|
||||
sync: false,
|
||||
renderer: true,
|
||||
doc: false,
|
||||
} satisfies typeof AFFiNE.flavor;
|
||||
const { app } = await createTestingApp({
|
||||
imports: [buildAppModule()],
|
||||
|
||||
@@ -18,6 +18,7 @@ test.before('start app', async t => {
|
||||
graphql: false,
|
||||
sync: true,
|
||||
renderer: false,
|
||||
doc: false,
|
||||
} satisfies typeof AFFiNE.flavor;
|
||||
const { app } = await createTestingApp({
|
||||
imports: [buildAppModule()],
|
||||
|
||||
@@ -58,6 +58,8 @@ export type TestingModule = BaseTestingModule & {
|
||||
export type TestingApp = INestApplication & {
|
||||
initTestingDB(): Promise<void>;
|
||||
[Symbol.asyncDispose](): Promise<void>;
|
||||
// get the url of the http server, e.g. http://localhost:random-port
|
||||
getHttpServerUrl(): string;
|
||||
};
|
||||
|
||||
function dedupeModules(modules: NonNullable<ModuleMetadata['imports']>) {
|
||||
@@ -180,6 +182,15 @@ export async function createTestingApp(
|
||||
await m[Symbol.asyncDispose]();
|
||||
await app.close();
|
||||
};
|
||||
|
||||
app.getHttpServerUrl = () => {
|
||||
const server = app.getHttpServer();
|
||||
if (!server.address()) {
|
||||
server.listen();
|
||||
}
|
||||
return `http://localhost:${server.address().port}`;
|
||||
};
|
||||
|
||||
return {
|
||||
module: m,
|
||||
app: app,
|
||||
|
||||
Reference in New Issue
Block a user