tachybase_todo/packages/plugin-file-manager/src/__tests__/index.ts

35 lines
782 B
TypeScript
Raw Normal View History

import path from 'path';
import supertest from 'supertest';
import { MockServer, mockServer } from '@nocobase/test';
import plugin from '../server';
2021-03-28 13:34:51 +08:00
export async function getApp(options = {}): Promise<MockServer> {
const app = mockServer({
...options,
cors: {
origin: '*'
}
});
app.plugin(require('@nocobase/plugin-collections/src/server').default);
app.plugin(plugin);
await app.load();
2021-09-14 11:09:26 +08:00
app.db.import({
directory: path.resolve(__dirname, './tables')
});
try {
2021-09-14 11:09:26 +08:00
await app.db.sync();
} catch (error) {
console.error(error);
}
return app;
}
// because the app in supertest is using a random port
export function requestFile(url, agent) {
return path.isAbsolute(url)
? agent.get(url)
: supertest.agent(url).get('');
}