Skip to content

Commit

Permalink
fix: use originalUrl to check mock call function request (#149)
Browse files Browse the repository at this point in the history
  • Loading branch information
fengmk2 authored Jan 18, 2023
1 parent ff796a6 commit abe1c07
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 8 deletions.
4 changes: 2 additions & 2 deletions app/middleware/cluster_app_mock.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ const co = require('co');

module.exports = () => {
return function clusterAppMock(ctx, next) {
if (ctx.path !== '/__egg_mock_call_function') return next();

// use originalUrl to make sure other middlewares can't change request url
if (ctx.originalUrl !== '/__egg_mock_call_function') return next();
debug('%s %s, body: %j', ctx.method, ctx.url, ctx.request.body);
const { method, property, args, needResult } = ctx.request.body;
if (!method) {
Expand Down
2 changes: 1 addition & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Application, Context, EggLogger } from 'egg';
import { MockMate } from 'mm';
import { Test } from 'supertest';
import { MockAgent } from 'urllib-next';
import { MockAgent } from 'urllib';

export { MockAgent };
interface EggTest extends Test {
Expand Down
2 changes: 1 addition & 1 deletion lib/mock_agent.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { MockAgent, setGlobalDispatcher, getGlobalDispatcher } = require('urllib-next');
const { MockAgent, setGlobalDispatcher, getGlobalDispatcher } = require('urllib');

let _mockAgent;
let _global;
Expand Down
4 changes: 1 addition & 3 deletions lib/request_call_function.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
'use strict';

const httpclient = require('urllib-next');
const httpclient = require('urllib');

const { port, method, args, property, needResult } = JSON.parse(process.argv[2]);
const url = `http://127.0.0.1:${port}/__egg_mock_call_function`;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"mm": "^3.0.2",
"sdk-base": "^3.0.1",
"supertest": "^6.2.4",
"urllib-next": "^3.2.3"
"urllib": "^3.10.1"
},
"peerDependencies": {
"egg": "^3.12.0",
Expand Down

0 comments on commit abe1c07

Please sign in to comment.