-
Notifications
You must be signed in to change notification settings - Fork 398
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
build: remove koa support and migrate to jest and eslint #553
Conversation
Refactored tests to use Jest/Axios Removed Koa support Replaced mocha, chai, sinon and nyc with Jest Replaced chakram with axios, qs and form-data Removed source-map-support, request and cross-env as they are no longer used Added express typings to ExpressMiddlewareInterface Updated all dependencies Removed tslint in preparation for migration to eslint
Hi @rmuchall, First of all, thanks for submitting the PR. I will paste the logs below for your reference: Click to expand!> $ npm run test ⬡ 12.0.0 [±rmuchall-jest-eslint ✓]
> [email protected] pretest /home/jotamorais/dev/oss/routing-controllers
> npm run lint
> [email protected] lint /home/jotamorais/dev/oss/routing-controllers
> eslint --config ./.eslintrc.js --ext .ts ./src ./test
> [email protected] test /home/jotamorais/dev/oss/routing-controllers
> rimraf coverage && jest --coverage
PASS test/functional/middlewares-order.spec.ts (15.862s)
PASS test/functional/interceptors.spec.ts (16.979s)
PASS test/functional/controller-methods.spec.ts
PASS test/functional/auth-decorator.spec.ts
PASS test/functional/class-transformer-options.spec.ts
FAIL test/functional/express-global-before-error-handling.spec.ts (20.891s)
● Console
console.error node_modules/jest-jasmine2/build/jasmine/Env.js:248
Unhandled error
console.error node_modules/jest-jasmine2/build/jasmine/Env.js:249
Error: listen EADDRINUSE: address already in use :::3001
at Server.setupListenHandle [as _listen2] (net.js:1226:14)
at listenInCluster (net.js:1274:12)
at Server.listen (net.js:1362:7)
at Function.listen (/home/jotamorais/dev/oss/routing-controllers/node_modules/express/lib/application.js:618:24)
at Object.<anonymous> (/home/jotamorais/dev/oss/routing-controllers/test/functional/express-global-before-error-handling.spec.ts:58:47)
at /home/jotamorais/dev/oss/routing-controllers/node_modules/jest-jasmine2/build/queueRunner.js:45:12
at new Promise (<anonymous>)
at mapper (/home/jotamorais/dev/oss/routing-controllers/node_modules/jest-jasmine2/build/queueRunner.js:28:19)
at /home/jotamorais/dev/oss/routing-controllers/node_modules/jest-jasmine2/build/queueRunner.js:75:41
at processTicksAndRejections (internal/process/task_queues.js:88:5)
● custom express global before middleware error handling › should call global error handler middleware with CustomError
.............
● express middlewares › should handle errors in custom middlewares
Timeout - Async callback was not invoked within the 5000ms timeout specified by jest.setTimeout.Error: Timeout - Async callback was not invoked within the 5000ms timeout specified by jest.setTimeout.
at mapper (node_modules/jest-jasmine2/build/queueRunner.js:27:45)
● express middlewares › should handle errors in custom middlewares
TypeError: Cannot read property 'status' of undefined
191 | return axios.get("/customMiddlewareWichThrows")
192 | .catch((error: AxiosError) => {
> 193 | expect(error.response.status).toEqual(HttpStatusCodes.NOT_ACCEPTABLE);
| ^
194 | });
195 | });
196 | });
at test/functional/express-middlewares.spec.ts:193:39
● express middlewares › should handle errors in custom middlewares
expect.assertions(1)
Expected one assertion to be called but received zero assertion calls.
188 |
189 | it("should handle errors in custom middlewares", () => {
> 190 | expect.assertions(1);
| ^
191 | return axios.get("/customMiddlewareWichThrows")
192 | .catch((error: AxiosError) => {
193 | expect(error.response.status).toEqual(HttpStatusCodes.NOT_ACCEPTABLE);
at Object.<anonymous> (test/functional/express-middlewares.spec.ts:190:16)
Test Suites: 8 failed, 14 passed, 22 total
Tests: 42 failed, 115 passed, 157 total
Snapshots: 0 total
Time: 32.363s
Ran all test suites.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! routing-controllers@0.9.0 test: `rimraf coverage && jest --coverage`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the routing-controllers@0.9.0 test script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /home/jotamorais/.npm/_logs/2020-04-22T17_19_19_717Z-debug.log
Tests: 42 failed, 115 passed, 157 total
Snapshots: 0 total
Time: 32.363s
Ran all test suites.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! routing-controllers@0.9.0 test: `rimraf coverage && jest --coverage`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the routing-controllers@0.9.0 test script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /home/jotamorais/.npm/_logs/2020-04-22T17_19_19_717Z-debug.log
After trying different approaches, I believe the best fix is to use the "test": "rimraf coverage && jest --coverage --runInBand --detectOpenHandles" Let me your thoughts. |
Hi @jotamorais, Many thanks for your reply and your comments :) I do not encounter the same errors that you are experiencing but I would like to try and solve this mystery. I wonder if the issue might be environmental. May I ask: Thanks, |
@rmuchall It could be an environment/platform issue, but since this is supposed to be cross-platform, I think we should fix it for all.
|
@jotamorais |
@jotamorais |
@jotamorais |
@jotamorais |
@jotamorais |
Ok. Let me know your findings. |
Hi @jotamorais, I've completed my investigation of this issue :) The reason the tests are failing are because multiple threads are attempting to create express servers on the same port (3001). This leads to a deadlock. I attempted to refactor the tests to pull from a pool of ports. However, this solution is currently blocked because Jest does not support custom environments written in TypeScript. Although this feature is planned for Jest v26.0 (jestjs/jest#8751). Your original suggestion of using --runInBand is therefore the only available solution. Many thanks for your help and patience :) |
Thank you! |
Blocking this as tooling will be added from the other TypeStack repos. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Blocking
Hmm, I took the liberty of using your tests, (thanks!) but it seems they are failing for me too even with the runInBand flag. You can check in #601. |
Superset by #601 |
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Hi folks,
Background
I really like this library and since maintenance has been sparse for a while I thought I'd fork it and maintain it for my own internal projects. I've made some possibly controversial changes and I expect this pull request to be rejected but I submit it in case it is of use to you.
NB: Any changes I make to my fork will be publicly available via my Github and I'll place a big disclaimer informing people they should use the original typestack package. I don't want to step on any toes - you guys are awesome and I use many of your libraries :)
With this first pull request I've been careful not to make any functional changes other than the ones listed below. So hopefully there should be no breaking changes (other than the removal of koa).
Action taken
Removed koa support
Reasoning
I don't use Koa :)
To reduce the cognitive/maintenance load
Koa has monthly downloads of just 3.4% of express downloads
https://npmcompare.com/compare/express,koa
Action taken
Replaced mocha, chai, sinon and nyc with jest
Reasoning
To normalize the test framework across all my projects
Jest appears to be a more complete framework
Jest is more popular
https://npmcompare.com/compare/jest,mocha
Action taken
Replaced chakram with axios, qs and form-data
Reasoning
chakram appears to be no longer maintained
chakram uses request under the hood which is deprecated
axios, qs and form-data appear to be popular and actively maintained
Action taken
Replaced tslint with eslint
Reasoning
tslint is deprecated and the recommended replacement is eslint
Other changes
Removed source-map-support, request and cross-env as they are no longer used
Added express typings to ExpressMiddlewareInterface
Updated all dependencies
Thanks,
Rob