Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
mm.app = (options): MidwayMockApplication => {
if (process.env.MIDWAY_BASE_DIR && !options.baseDir) { options.baseDir = process.env.MIDWAY_BASE_DIR; }
if (process.env.MIDWAY_FRAMEWORK_PATH && !options.framework) { options.framework = process.env.MIDWAY_FRAMEWORK_PATH; }
// @ts-ignore
return mock.app(Object.assign({
framework: options.framework || defaultFramework,
typescript: !!require.extensions['.ts'],
}, options));
};
mm.cluster = (options) => {
if (process.env.MIDWAY_BASE_DIR && !options.baseDir) { options.baseDir = process.env.MIDWAY_BASE_DIR; }
if (process.env.MIDWAY_FRAMEWORK_PATH && !options.framework) { options.framework = process.env.MIDWAY_FRAMEWORK_PATH; }
// @ts-ignore
return mock.cluster(Object.assign({
framework: options.framework || defaultFramework,
typescript: !!require.extensions['.ts'],
}, options));
};
'use strict';
const Benchmark = require('benchmark');
const mm = require('egg-mock');
const table = require('markdown-table');
mm.consoleLevel('NONE');
// Benchmark.options.minSamples = 100;
let app = null;
const startApp = async () => {
process.env.NODE_ENV = 'production';
mm.env('prod');
app = mm.app({
baseDir: __dirname,
framework: 'beidou',
});
await app.ready();
await app.httpRequest().get('/');
};
const stopApp = () => app && app.close();
describe('test/async.test.js', () => {
afterEach(mm.restore);
let app;
before(async () => {
app = utils.app('apps/async-app');
await app.ready();
assert(app.beforeStartExectuted);
assert(app.scheduleExecuted);
});
after(async () => {
await app.close();
assert(app.beforeCloseExecuted);
});
it('middleware, controller and service support async functions', async () => {
await app.httpRequest()
.get('/api')
.expect(200)
exports.app = (name, options) => {
options = formatOptions(name, options);
const app = mm.app(options);
return app;
};
const restore = async () => {
await app.model.Project.truncate();
await app.model.Interface.truncate();
await app.model.Scene.truncate();
await app.model.Schema.truncate();
}