diff --git a/docs/source/en/intro/quickstart.md b/docs/source/en/intro/quickstart.md index 7ea8de8410..aad09dca93 100644 --- a/docs/source/en/intro/quickstart.md +++ b/docs/source/en/intro/quickstart.md @@ -87,7 +87,8 @@ Then edit the router file and add a mapping. ```js // app/router.js module.exports = app => { - app.get('/', app.controller.home.index); + const { router, controller } = app; + router.get('/', controller.home.index); }; ``` @@ -231,8 +232,9 @@ module.exports = NewsController; // app/router.js module.exports = app => { - app.get('/', app.controller.home.index); - app.get('/news', app.controller.news.list); + const { router, controller } = app; + router.get('/', controller.home.index); + router.get('/news', controller.news.list); }; ``` @@ -347,7 +349,6 @@ Suppose that we wanted to prohibit accesses from Baidu crawlers. Smart developers might quickly guess that we can achieve it by adding a [middleware](../basics/middleware.md) that checks the User-Agent. - ```js // app/middleware/robot.js // options === app.config.robot @@ -429,26 +430,15 @@ All the test files should place at `{app_root}/test/**/*.test.js`. ```js // test/app/middleware/robot.test.js -const assert = require('assert'); -const mock = require('egg-mock'); +const { app, mock, assert } = require('egg-mock/bootstrap'); describe('test/app/middleware/robot.test.js', () => { - let app; - before(() => { - app = mock.app(); - return app.ready(); - }); - - afterEach(mock.restore); - it('should block robot', () => { return app.httpRequest() .get('/') .set('User-Agent', "Baiduspider") .expect(403); }); - - // ... }); ``` @@ -457,7 +447,8 @@ Then add `npm scripts`. ```json { "scripts": { - "test": "egg-bin test" + "test": "egg-bin test", + "cov": "egg-bin cov" } } ``` diff --git a/docs/source/zh-cn/intro/quickstart.md b/docs/source/zh-cn/intro/quickstart.md index 1e8f172a85..e457e2e12b 100644 --- a/docs/source/zh-cn/intro/quickstart.md +++ b/docs/source/zh-cn/intro/quickstart.md @@ -81,7 +81,8 @@ module.exports = HomeController; ```js // app/router.js module.exports = app => { - app.get('/', app.controller.home.index); + const { router, controller } = app; + router.get('/', controller.home.index); }; ``` @@ -217,8 +218,9 @@ module.exports = NewsController; // app/router.js module.exports = app => { - app.get('/', app.controller.home.index); - app.get('/news', app.controller.news.list); + const { router, controller } = app; + router.get('/', controller.home.index); + router.get('/news', controller.news.list); }; ``` @@ -401,28 +403,15 @@ module.exports = SomeService; ```js // test/app/middleware/robot.test.js -const assert = require('assert'); -const mock = require('egg-mock'); +const { app, mock, assert } = require('egg-mock/bootstrap'); describe('test/app/middleware/robot.test.js', () => { - let app; - before(() => { - // 创建当前应用的 app 实例 - app = mock.app(); - // 等待 app 启动成功,才能执行测试用例 - return app.ready(); - }); - - afterEach(mock.restore); - it('should block robot', () => { return app.httpRequest() .get('/') .set('User-Agent', "Baiduspider") .expect(403); }); - - // ... }); ``` @@ -431,7 +420,8 @@ describe('test/app/middleware/robot.test.js', () => { ```json { "scripts": { - "test": "egg-bin test" + "test": "egg-bin test", + "cov": "egg-bin cov" } } ```