Skip to content

Commit a72e3ab

Browse files
committed
chore: update http-request-mock version
1 parent 029fcd5 commit a72e3ab

File tree

7 files changed

+36
-15
lines changed

7 files changed

+36
-15
lines changed

config.js

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ module.exports = {
1616
'/photos/1': fs.readFileSync('./mock/samples/bypass.js', utf8),
1717
'/header': fs.readFileSync('./mock/samples/header.js', utf8),
1818
'/request-info': fs.readFileSync('./mock/samples/request.js', utf8),
19+
'/remote': fs.readFileSync('./mock/samples/remote.js', utf8),
1920
},
2021

2122
statics: {

mock/.runtime.js

+6
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,12 @@ if (process.env.NODE_ENV === "development") {
5757
"body": require('./samples/notfound.js'),
5858
"status": 404
5959
});
60+
mocker.mock({
61+
"url": "https://jsonplaceholder.typicode.com/remote",
62+
"method": "GET",
63+
"body": require('./samples/remote.js'),
64+
"remote": "http://jsonplaceholder.typicode.com/posts/1?a=1"
65+
});
6066
mocker.mock({
6167
"url": "https://jsonplaceholder.typicode.com/request-info",
6268
"method": "GET",

mock/samples/remote.js

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/**
2+
* @url https://jsonplaceholder.typicode.com/remote
3+
* @remote http://jsonplaceholder.typicode.com/posts/1?a=1
4+
* @method get
5+
*/
6+
module.exports = function (remote) {
7+
console.log('remote response:', remote);
8+
return {
9+
code: 0,
10+
msg: 'ok',
11+
data: remote.responseJson
12+
};
13+
};

package-lock.json

+13-13
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"@babel/plugin-transform-runtime": "^7.16.8",
2424
"axios": "^0.26.0",
2525
"got": "^12.0.1",
26-
"http-request-mock": "^1.6.23",
26+
"http-request-mock": "^1.7.5",
2727
"koa": "^2.13.1",
2828
"koa-router": "^10.1.1",
2929
"ts-jest": "^27.1.2"

server.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const request = async (url) => {
1717
result = JSON.stringify(res.data, null, 2);
1818
headers = JSON.stringify(res.headers, null, 2);
1919
} catch(err) {
20-
console.log('axios.get err:', err.stack)
20+
console.log('axios.get err:', url, '\n', err.stack)
2121
result = err.message;
2222
headers = '-';
2323
}

tpl.html

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ <h5>http-request-mock: Integration with nodejs</h5>
3535
<a href="/photos/1?bypass=2">/bypass2</a>
3636
<a href="/header">/header</a>
3737
<a href="/request-info?a=123&b=456">/request-info</a>
38+
<a href="/remote?a=123&b=456">/remote</a>
3839
</div>
3940

4041
<br>

0 commit comments

Comments
 (0)