Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: allow to call mockHttpclient multi times #165

Merged
merged 6 commits into from
Nov 8, 2023

Conversation

fengmk2
Copy link
Member

@fengmk2 fengmk2 commented Nov 7, 2023

closes #164

Checklist
  • npm test passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines
Affected core subsystem(s)
Description of change

@fengmk2 fengmk2 added the bug label Nov 7, 2023
@fengmk2 fengmk2 requested a review from killagu November 7, 2023 15:49
return mockUrl.test(`${requestOrigin}${path}`);
for (const config of mockConfigs) {
if (config.mockUrl.test(`${requestOrigin}${path}`)) {
mm(app, '__httpclientNextMockConfigIndex', config.mockConfigIndex);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

有并发请求的时候会不会有问题?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

两次 mock,Promose.all 中的请求都匹配了。

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

只会命中第一个 mockUrl

app.mockHttpclient(/\/mock_url/, {
data: Buffer.from('mock 1 match response'),
});
app.mockHttpclient(/\/mock_url/, {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

加了相同 mock 校验,只会返回第一个 mock 结果

@@ -63,6 +63,9 @@ module.exports = app => {
* @return {Context} this
*/

const MOCK_CONFIGS = Symbol('MOCK_CONFIGS');
const MOCK_CONFIG_INDEX = Symbol('MOCK_CONFIG_INDEX');
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

换成 Symbol 不被外部获取到

@fengmk2 fengmk2 merged commit 370e42d into master Nov 8, 2023
6 checks passed
@fengmk2 fengmk2 deleted the support-mockhttpclient-multi-times branch November 8, 2023 00:53
fengmk2 pushed a commit that referenced this pull request Nov 8, 2023
[skip ci]

## [5.10.9](v5.10.8...v5.10.9) (2023-11-08)

### Bug Fixes

* allow to call mockHttpclient multi times ([#165](#165)) ([370e42d](370e42d))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

mockHttpclient 调用2次只会命中第一次的逻辑
2 participants