Dive into secure and efficient coding practices with our curated list of the top 10 examples showcasing 'egg-mock' in functional components in JavaScript. Our advanced machine learning engine meticulously scans each line of code, cross-referencing millions of open source libraries to ensure your implementation is not just functional, but also robust and secure. Elevate your React applications to new heights by mastering the art of handling side effects, API calls, and asynchronous operations with confidence and precision.
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();
}