refactor(server): refine types

This commit is contained in:
mytharcher 2024-08-04 08:24:51 +00:00
parent a9cc8a17fa
commit 77af3154cf
4 changed files with 11 additions and 6 deletions

View File

@ -28,5 +28,5 @@ export interface IPubSubAdapter {
close(): Promise<any>;
subscribe(channel: string, callback: PubSubCallback): Promise<any>;
unsubscribe(channel: string, callback: PubSubCallback): Promise<any>;
publish(channel: string, message: any): Promise<any>;
publish(channel: string, message: string): Promise<any>;
}

View File

@ -13,7 +13,7 @@ import ws from 'ws';
export { MockDatabase, mockDatabase } from '@nocobase/database';
export { default as supertest } from 'supertest';
export * from './memory-pub-sub-adapter';
export * from './mock-cluster';
export * from './mock-isolated-cluster';
export * from './mock-server';
export const pgOnly: () => any = () => (process.env.DB_DIALECT == 'postgres' ? describe : describe.skip);

View File

@ -14,19 +14,19 @@ import { getPortPromise } from 'portfinder';
import { uid } from '@nocobase/utils';
import { createMockServer } from './mock-server';
type ClusterOptions = {
type IsolatedClusterOptions = {
script?: string;
env?: Record<string, any>;
plugins?: string[];
instances?: number;
};
export class MockCluster {
export class MockIsolatedCluster {
private script = `${process.env.APP_PACKAGE_ROOT}/src/index.ts`;
private processes = [];
private mockApp;
constructor(private options: ClusterOptions = {}) {
constructor(private options: IsolatedClusterOptions = {}) {
if (options.script) {
this.script = options.script;
}

View File

@ -279,12 +279,17 @@ export type MockClusterOptions = MockServerOptions & {
appName?: string;
};
export type MockCluster = {
nodes: MockServer[];
destroy: () => Promise<void>;
};
export async function createMockCluster({
number = 2,
clusterName = `cluster_${uid()}`,
appName = `app_${uid()}`,
...options
}: MockClusterOptions = {}) {
}: MockClusterOptions = {}): Promise<MockCluster> {
const nodes: MockServer[] = [];
let dbOptions;