How to use egg-mock - 10 common examples

To help you get started, we’ve selected a few egg-mock examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github midwayjs / midway / packages / midway-mock / src / mock.ts View on Github external
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));
};
github midwayjs / midway / packages / midway-mock / src / mock.ts View on Github external
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));
};
github alibaba / beidou / examples / benchmark / benchmark.js View on Github external
'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();
github eggjs / egg / test / async / _async.js View on Github external
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)
github eggjs / egg / test / utils.js View on Github external
exports.app = (name, options) => {
  options = formatOptions(name, options);
  const app = mm.app(options);
  return app;
};
github macacajs / macaca-datahub / test / .setup.js View on Github external
const restore = async () => {
  await app.model.Project.truncate();
  await app.model.Interface.truncate();
  await app.model.Scene.truncate();
  await app.model.Schema.truncate();
}