Socket
Socket
Sign inDemoInstall

egg-mock

Package Overview
Dependencies
8
Maintainers
4
Versions
130
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.0.5 to 0.0.6

7

History.md
0.0.6 / 2016-10-24
==================
* feat: cluster should wait process exit (#11)
* docs:update readme (#9)
* docs: update readme
0.0.5 / 2016-10-11

@@ -3,0 +10,0 @@ ==================

11

lib/cluster.js

@@ -153,6 +153,13 @@ 'use strict';

* kill the process
* @return {Promise} promise
*/
close() {
this.proc.kill('SIGTERM');
this.closed = true;
return new Promise(resolve => {
if (!this.proc.connected) return resolve();
this.proc.kill('SIGTERM');
this.proc.on('exit', () => {
this.closed = true;
resolve();
});
});
}

@@ -159,0 +166,0 @@

2

package.json
{
"name": "egg-mock",
"version": "0.0.5",
"version": "0.0.6",
"eggPlugin": {

@@ -5,0 +5,0 @@ "name": "egg-mock"

@@ -38,3 +38,3 @@ # egg-mock

```js
const mm = require('@ali/mm');
const mm = require('egg-mock');
const request = require('supertest');

@@ -105,24 +105,26 @@

插件测试会通过 [@ali/egg-web-names](http://gitlab.alibaba-inc.com/egg/egg-web-names) 找默认框架,也可以指定 customEgg,比如希望在 chair 和 midway 同时测试此插件。
如果想测试插件挂载到某个框架里测试,可以通过 [egg-web-names](https://github.com/eggjs/egg-web-names) 找默认框架,也可以指定 customEgg,比如希望在 aliyun-egg 和 framework-b 同时测试此插件。
```js
describe('chair', function() {
before(function(done) {
this.app = mm.app({
describe('aliyun-egg', function() {
let app;
before(() => {
app = mm.app({
baseDir: 'apps/demo',
customEgg: path.join(__dirname, 'node_modules/@ali/egg'),
customEgg: path.join(__dirname, 'node_modules/aliyun-egg'),
});
this.app.ready(done);
return app.ready();
});
})
});
describe('midway', function() {
before(function(done) {
this.app = mm.app({
describe('framework-b', function() {
let app;
before(() => {
app = mm.app({
baseDir: 'apps/demo',
customEgg: path.join(__dirname, 'node_modules/midway'),
customEgg: path.join(__dirname, 'node_modules/framework-b'),
});
this.app.ready(done);
return app.ready();
});
})
});
```

@@ -153,23 +155,17 @@

```js
const mm = require('egg-mock');
describe('test/app.js', function() {
let app, config;
before(function(done) {
before(() => {
app = mm.cluster();
app.ready(done);
return app.ready();
});
before(function(done) {
request(app.callback())
after(() => app.close());
afterEach(mm.restore);
it('some test', () => {
return request(app.callback())
.get('/config')
.end(function(err, res) {
should.not.exists(err);
// 获取 app.config,在 controller
// this.body = this.app.config;
config = res.body;
done();
})
.expect(200)
});
after(function() {
app.close();
})
afterEach(mm.restore);
});

@@ -200,3 +196,3 @@ ```

具体值见 http://gitlab.alibaba-inc.com/egg/egg-loader/blob/master/lib/base_loader.js#L102
具体值见 https://github.com/eggjs/egg-core/blob/master/lib/loader/egg_loader.js#L82

@@ -242,3 +238,3 @@ ### mm.consoleLevel(level)

指定框架路径,默认会根据 [@ali/egg-web-names](http://gitlab.alibaba-inc.com/egg/egg-web-names) 的先后顺序搜索框架路径。
指定框架路径,默认会根据 [egg-web-names](https://github.com/eggjs/egg-web-names) 的先后顺序搜索框架路径。

@@ -256,6 +252,2 @@ 对于框架的测试用例,可以指定 true,见上面示例。

#### antxpath {String}
传入外部的 antx 配置
#### plugin

@@ -324,35 +316,2 @@

### app.mockProxy(proxy, methodName, fn)
使用此 mock,args 是经过 proxyArgsConvertor 返回的结果, 可以保证单元测试的参数通过参数类型检查。
```js
app.mockProxy('authManager', 'retrieveDataPermission', function* (ctx, methodName, args) {
return { foo: 'bar' };
});
```
也可以便捷地 mock proxy 返回特定数据
```js
app.mockProxy('account', 'getAccountInfo', { name: 'foo' });
```
### app.mockProxyError(proxy, methodName[, error])
便捷地 mock proxy 抛出指定异常
```js
app.mockProxyError('account', 'getAccountInfo', new Error('mock error'));
app.mockProxyError('account2', 'getAccountInfo', 'mock error string is ok');
```
### app.mockProxyByScene(proxy, methodName, scene)
按照场景来 mock proxy 的返回内容。所有的场景数据都放在 `${baseDir}/mocks_data/proxy/${proxyName}/${methodName}/${scene}.js` 的文件中。
```js
app.mockProxyByScene('account', 'getAccountInfo', 'scene_1');
```
### app.mockService(service, methodName, fn)

@@ -368,3 +327,3 @@

按照场景来 mock service 的返回内容,和 `mockProxyByScene` 类似。所有的场景数据都放在 `${baseDir}/mocks_data/service/${serviceName}/${methodName}/${scene}.js` 的文件中。
按照场景来 mock service 的返回内容,所有的场景数据都放在 `${baseDir}/mocks_data/service/${serviceName}/${methodName}/${scene}.js` 的文件中。

@@ -401,17 +360,2 @@ ```js

### app.mockAntx()
模拟 antx
```js
app.get('/', function*() {
this.body = this.app.antx.a;
})
app.mockAntx({ a: 1 });
request(app.callback())
.post('/')
.expect('1', done);
```
### app.mockUrllib(url, method, data)

@@ -423,15 +367,15 @@

app.get('/', function*() {
const ret = yield this.curl('http://www.alipay.com');
const ret = yield this.curl('https://eggjs.org ');
this.body = ret.data.toString();
});
app.mockUrllib('http://www.alipay.com', {
app.mockUrllib('https://eggjs.org ', {
// 模拟的参数,可以是 buffer / string / json,
// 都会转换成 buffer
// 按照请求时的 options.dataType 来做对应的转换
data: 'mock alipay',
data: 'mock taobao',
});
request(app.callback())
.post('/')
.expect('mock alipay', done);
.expect('mock taobao', done);
```

@@ -438,0 +382,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc