feat(test): add quickstart

This commit is contained in:
chenos 2023-12-02 09:40:22 +08:00
parent 52c83cadb3
commit 7adb162cc8
2 changed files with 11 additions and 9 deletions

View File

@ -1,4 +1,4 @@
import { Database, mockDatabase } from '@nocobase/database'; import { mockDatabase } from '@nocobase/database';
import Application, { AppSupervisor, ApplicationOptions, Gateway, PluginManager } from '@nocobase/server'; import Application, { AppSupervisor, ApplicationOptions, Gateway, PluginManager } from '@nocobase/server';
import jwt from 'jsonwebtoken'; import jwt from 'jsonwebtoken';
import qs from 'qs'; import qs from 'qs';
@ -81,6 +81,14 @@ export class MockServer extends Application {
await this.db.clean({ drop: true }); await this.db.clean({ drop: true });
} }
async quickstart(options: { clean?: boolean } = {}) {
const { clean } = options;
if (clean) {
await this.cleanDb();
}
await this.runCommand('start', '--quickstart');
}
protected createDatabase(options: ApplicationOptions) { protected createDatabase(options: ApplicationOptions) {
const oldDatabase = this._db; const oldDatabase = this._db;

View File

@ -1,19 +1,13 @@
import { mockServer, MockServer } from '@nocobase/test'; import { mockServer, MockServer } from '@nocobase/test';
import PluginACL from '../../server';
export async function prepareApp(): Promise<MockServer> { export async function prepareApp(): Promise<MockServer> {
const app = mockServer({ const app = mockServer({
registerActions: true, registerActions: true,
acl: true, acl: true,
plugins: ['error-handler', 'users', 'ui-schema-storage', 'collection-manager', 'auth'], plugins: ['acl', 'error-handler', 'users', 'ui-schema-storage', 'collection-manager', 'auth'],
}); });
await app.db.clean({ drop: true }); await app.quickstart({ clean: true });
app.plugin(PluginACL, {
name: 'acl',
});
await app.loadAndInstall({ clean: true });
await app.start();
return app; return app;
} }