333
schangxiang@126.com
2025-09-19 18966e02fb573c7e2bb0c6426ed792b38b910940
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
'use strict';
 
const mm = require('mm');
const cluster = require('./lib/cluster');
const app = require('./lib/app');
 
// egg-bin will set this flag to require files for instrument
if (process.env.EGG_BIN_PREREQUIRE) require('./lib/prerequire');
 
/**
 * @namespace mm
 */
 
function mock(...args) {
  return mm(...args);
}
module.exports = mock;
module.exports.default = mock;
 
// inherit & extends mm
Object.assign(mock, mm, {
  restore() {
    cluster.restore();
    mm.restore();
  },
 
  /**
   * Create a egg mocked application
   * @function mm#app
   * @param {Object} [options]
   * - {String} baseDir - The directory of the application
   * - {Object} plugins - Tustom you plugins
   * - {String} framework - The directory of the egg framework
   * - {Boolean} [true] cache - Cache application based on baseDir
   * - {Boolean} [true] coverage - Swtich on process coverage, but it'll be slower
   * - {Boolean} [true] clean - Remove $baseDir/logs
   * @return {App} return {@link Application}
   * @example
   * ```js
   * var app = mm.app();
   * ```
   */
  app,
 
  /**
   * Create a egg mocked cluster application
   * @function mm#cluster
   * @see ClusterApplication
   */
  cluster,
 
  /**
   * mock the serverEnv of Egg
   * @member {Function} mm#env
   * @param {String} env - contain default, test, prod, local, unittest
   * @see https://github.com/eggjs/egg-core/blob/master/lib/loader/egg_loader.js#L78
   */
  env(env) {
    mm(process.env, 'EGG_MOCK_SERVER_ENV', env);
    mm(process.env, 'EGG_SERVER_ENV', env);
  },
 
  /**
   * mock console level
   * @param {String} level - logger level
   */
  consoleLevel(level) {
    level = (level || '').toUpperCase();
    mm(process.env, 'EGG_LOG', level);
  },
 
  home(homePath) {
    if (homePath) {
      mm(process.env, 'EGG_HOME', homePath);
    }
  },
});
 
process.setMaxListeners(100);
 
process.once('SIGQUIT', () => {
  process.exit(0);
});
 
process.once('SIGTERM', () => {
  process.exit(0);
});
 
process.once('SIGINT', () => {
  process.exit(0);
});