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

32 lines
787 B
TypeScript
Raw Normal View History

import path from 'path';
import supertest from 'supertest';
import { MockServer, mockServer } from '@nocobase/test';
import plugin from '../';
2021-03-28 13:34:51 +08:00
export async function getApp(options = {}): Promise<MockServer> {
const app = mockServer({
...options,
cors: {
2021-12-06 21:23:34 +08:00
origin: '*',
},
});
app.plugin(plugin);
2021-09-14 11:09:26 +08:00
app.db.import({
2021-12-06 21:23:34 +08:00
directory: path.resolve(__dirname, './tables'),
});
2021-12-06 21:23:34 +08:00
await app.loadAndInstall();
2021-12-06 21:23:34 +08:00
return app;
}
// because the app in supertest will use a random port
export function requestFile(url, agent) {
// url starts with double slash "//" will be considered as http or https
// url starts with single slash "/" will be considered from local server
2021-12-06 21:23:34 +08:00
return url[0] === '/' && url[1] !== '/' ? agent.get(url) : supertest.agent(url).get('');
}