egg-mock icon indicating copy to clipboard operation
egg-mock copied to clipboard

[fix] fix run server without wait until app ready

Open Sesna opened this issue 3 years ago • 3 comments

mock server need to be started after app ready, be cause router plugin are run in beforeHook, now I can't do the api test, even the buildin unit test are failed.

before: image

after: image

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

Sesna avatar Apr 29 '22 11:04 Sesna

Add a test case to show where is the problem?

fengmk2 avatar Apr 29 '22 13:04 fengmk2

@fengmk2 you may notice that the test case build in egg.js itselt could not pass already, as my first screenshot show, the http client will response 404 cause failed once it request a specify url. because the mock server start without wait router module to register it routes to middleware.

image

node_modules/egg-core/lib/egg.js // L303 - 305, routes register in beforeStart hook.

image

node_modules/egg-mock/lib/app.js // L106 - 107, mock server start without wait routes registered

This bug cause mock server start without any routes, and all test case related with route response 404.

So, in this PR, I just fix this bug, and no need to provide more test case, just let the buildin test case pass. can run

npx mocha test/mock_request.test.js

to see the effects, now all test cases should be passed.

Sesna avatar May 09 '22 03:05 Sesna

The master branch ci is pass https://github.com/eggjs/egg-mock/runs/6345153680?check_suite_focus=true

fengmk2 avatar May 09 '22 09:05 fengmk2