diff --git a/README.md b/README.md index 5d9ef3d..364e0b7 100644 --- a/README.md +++ b/README.md @@ -185,14 +185,14 @@ mm.app({ }); ``` -Environment list https://github.com/eggjs/egg-core/blob/master/lib/loader/egg_loader.js#L82 +Environment list ### mm.consoleLevel(level) Mock level that print to stdout/stderr ```js -// 不输出到终端 +// DON'T log to terminal mm.consoleLevel('NONE'); ``` @@ -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. @@ -341,7 +347,6 @@ const ctx = app.mockContext(); console.log(ctx.session.foo); ``` - ### app.mockService(service, methodName, fn) ```js @@ -349,7 +354,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(); }); ``` @@ -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(); diff --git a/README.zh_CN.md b/README.zh_CN.md index 534c81b..596ded2 100644 --- a/README.zh_CN.md +++ b/README.zh_CN.md @@ -190,7 +190,7 @@ mm.app({ }); ``` -具体值见 https://github.com/eggjs/egg-core/blob/master/lib/loader/egg_loader.js#L82 +具体值见 ### mm.consoleLevel(level) @@ -203,7 +203,6 @@ mm.consoleLevel('NONE'); 可选 level 为 `DEBUG`, `INFO`, `WARN`, `ERROR`, `NONE` - ### mm.home(homePath) 模拟操作系统用户目录 @@ -276,6 +275,12 @@ mm.app({ 如果是通过 ava 等并行测试框架进行测试,需要手动在执行测试前进行统一的日志清理,不能通过 mm 来处理,设置 `clean` 为 `false`。 +#### typescript {Boolean} + +开启 TypeScript 支持,默认关闭。 + +支持读取环境变量 `process.env.EGG_TYPESCRIPT`。 + ### app.httpRequest() 请求当前应用 http 服务的辅助工具。 @@ -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(); }); ``` @@ -374,7 +379,7 @@ it('should mock user name', function* () { app.mockServiceError('user', 'home', new Error('mock error')); ``` -### app.mockCsrf(); +### app.mockCsrf() 模拟 csrf,不用传递 token diff --git a/bootstrap.js b/bootstrap.js index 2c80e19..1eaf5a8 100644 --- a/bootstrap.js +++ b/bootstrap.js @@ -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()); diff --git a/index.d.ts b/index.d.ts index 21f5a24..de2d443 100644 --- a/index.d.ts +++ b/index.d.ts @@ -82,6 +82,11 @@ export interface MockOption { * Remove $baseDir/logs */ clean?: boolean; + + /** + * Enable typescript support + */ + typescript?: boolean; } type EnvType = 'default' | 'test' | 'prod' | 'local' | 'unittest'; diff --git a/lib/cluster.js b/lib/cluster.js index acf8b9c..594b089 100644 --- a/lib/cluster.js +++ b/lib/cluster.js @@ -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