1 | 'use strict';
|
2 |
|
3 | const methods = require('methods');
|
4 | const EggTest = require('./http_test');
|
5 | const mockHttpServer = require('./mock_http_server');
|
6 | const pkg = require('../package.json');
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 | module.exports = app => {
|
20 | const server = mockHttpServer(app);
|
21 | const obj = {};
|
22 | for (const method of methods) {
|
23 | obj[method] = url => {
|
24 |
|
25 | if (url[0] !== '/') {
|
26 | const realUrl = app.router.pathFor(url);
|
27 | if (!realUrl) throw new Error(`Can\'t find router:${url}, please check your \'app/router.js\'`);
|
28 | url = realUrl;
|
29 | }
|
30 |
|
31 | const eggTest = new EggTest(server, method, url);
|
32 | eggTest.set('user-agent', `egg-mock/${pkg.version}`);
|
33 | return eggTest;
|
34 | };
|
35 | }
|
36 | obj.del = obj.delete;
|
37 | return obj;
|
38 | };
|