Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support ts #70

Merged
merged 1 commit into from
Mar 28, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -185,14 +185,14 @@ mm.app({
});
```

Environment list https://github.com/eggjs/egg-core/blob/master/lib/loader/egg_loader.js#L82
Environment list <https://github.com/eggjs/egg-core/blob/master/lib/loader/egg_loader.js#L82>

### mm.consoleLevel(level)

Mock level that print to stdout/stderr

```js
// 不输出到终端
// DON'T log to terminal
mm.consoleLevel('NONE');
```

Expand Down Expand Up @@ -265,6 +265,12 @@ Clean all logs directory, default is true.

If you are using `ava`, disable it.

#### typescript {Boolean}

Enable Typescript support, default is false.

Support read from `process.env.EGG_TYPESCRIPT`.

### app.httpRequest()

Request current app http server.
Expand Down Expand Up @@ -341,15 +347,14 @@ const ctx = app.mockContext();
console.log(ctx.session.foo);
```


### app.mockService(service, methodName, fn)

```js
it('should mock user name', function* () {
app.mockService('user', 'getName', function* (ctx, methodName, args) {
return 'popomore';
});
const ctx = app.mockContext();
const ctx = app.mockContext();
yield ctx.service.user.getName();
});
```
Expand All @@ -362,7 +367,7 @@ You can mock an error for service
app.mockServiceError('user', 'home', new Error('mock error'));
```

### app.mockCsrf();
### app.mockCsrf()

```js
app.mockCsrf();
Expand Down
13 changes: 9 additions & 4 deletions README.zh_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ mm.app({
});
```

具体值见 https://github.com/eggjs/egg-core/blob/master/lib/loader/egg_loader.js#L82
具体值见 <https://github.com/eggjs/egg-core/blob/master/lib/loader/egg_loader.js#L82>

### mm.consoleLevel(level)

Expand All @@ -203,7 +203,6 @@ mm.consoleLevel('NONE');

可选 level 为 `DEBUG`, `INFO`, `WARN`, `ERROR`, `NONE`


### mm.home(homePath)

模拟操作系统用户目录
Expand Down Expand Up @@ -276,6 +275,12 @@ mm.app({

如果是通过 ava 等并行测试框架进行测试,需要手动在执行测试前进行统一的日志清理,不能通过 mm 来处理,设置 `clean` 为 `false`。

#### typescript {Boolean}

开启 TypeScript 支持,默认关闭。

支持读取环境变量 `process.env.EGG_TYPESCRIPT`。

### app.httpRequest()

请求当前应用 http 服务的辅助工具。
Expand Down Expand Up @@ -361,7 +366,7 @@ it('should mock user name', function* () {
app.mockService('user', 'getName', function* (ctx, methodName, args) {
return 'popomore';
});
const ctx = app.mockContext();
const ctx = app.mockContext();
yield ctx.service.user.getName();
});
```
Expand All @@ -374,7 +379,7 @@ it('should mock user name', function* () {
app.mockServiceError('user', 'home', new Error('mock error'));
```

### app.mockCsrf();
### app.mockCsrf()

模拟 csrf,不用传递 token

Expand Down
1 change: 1 addition & 0 deletions bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const mock = require('./index').default;

const options = {};
if (process.env.EGG_BASE_DIR) options.baseDir = process.env.EGG_BASE_DIR;
if (process.env.EGG_TYPESCRIPT) options.typescript = process.env.EGG_TYPESCRIPT;
const app = mock.app(options);

before(() => app.ready());
Expand Down
5 changes: 5 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ export interface MockOption {
* Remove $baseDir/logs
*/
clean?: boolean;

/**
* Enable typescript support
*/
typescript?: boolean;
}

type EnvType = 'default' | 'test' | 'prod' | 'local' | 'unittest';
Expand Down
1 change: 1 addition & 0 deletions lib/cluster.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class ClusterApplication extends Coffee {
* - {String} baseDir - The directory of the application
* - {Object} plugins - Tustom you plugins
* - {String} framework - The directory of the egg framework
* - {Boolean} [typescript] - Enable TypeScript support
* - {Boolean} [cache=true] - Cache application based on baseDir
* - {Boolean} [coverage=true] - Swtich on process coverage, but it'll be slower
* - {Boolean} [clean=true] - Remove $baseDir/logs
Expand Down