tachybase_todo/packages/plugins/verification/src/__tests__/index.ts
chenos 249dff16d3
refactor: plugin manager (#965)
* feat: improve code

* chore: update version

* feat: api service

* fix: api services

* feat: improve code

* feat: improve code

* feat: improve code

* feat: pm socket

* fix: test errors

* feat: add built-in plugins before upgrade

* feat: update docs

* feat: improve code

* fix: after load
2022-10-27 13:00:16 +08:00

40 lines
784 B
TypeScript

import { MockServer, mockServer } from '@nocobase/test';
import path from 'path';
import { ApplicationOptions } from '@nocobase/server';
import Plugin from '..';
export function sleep(ms: number) {
return new Promise(resolve => {
setTimeout(resolve, ms);
});
}
interface MockAppOptions extends ApplicationOptions {
manual?: boolean;
}
export async function getApp({ manual, ...options }: MockAppOptions = {}): Promise<MockServer> {
const app = mockServer(options);
app.plugin(Plugin, { name: 'verification' });
await app.load();
await app.db.import({
directory: path.resolve(__dirname, './collections')
});
try {
await app.db.sync();
} catch (error) {
console.error(error);
}
if (!manual) {
await app.start();
}
return app;
}