Open hggaguilera opened 3 years ago
We have this issue too. Your call to initialize()
returns a promise. So that's why you are getting a 404 – the routes aren't yet configured. You can verify this by debugging and inspecting app._router.stack
.
However, my problem is that my test just seems to hang when importing my app.js
file with an initialize()
call. As soon as I comment out initialize()
in app.js
, I get the same result as OP, 404s.
bump
Hey checkout jest-light-runner
@itswoop & @hggonzalez we found that adding in a block to our pkg.json with the following code:
"runner": "jest-light-runner"
}```
also run an npm install for https://www.npmjs.com/package/jest-light-runner
`npm i jest-light-runner` we are on Node 16.17 and everything is working for us.
Might be related.
I got an issue with OAS 3.0. Jest returns the following error:
Test suite failed to run
A jest worker process (pid=46310) was terminated by another process: signal=SIGSEGV, exitCode=null. Operating system logs may contain more information on why this occurred.
at ChildProcessWorker._onExit (node_modules/jest-worker/build/workers/ChildProcessWorker.js:366:23)
The error will go away if I comment out initialize()
in app.js
.
The Jest crash has something to do with the following two configuration fields:
await initialize({
...
routesGlob: "**/*.{ts,js}",
routesIndexFileRegExp: /(?:index)?\.[tj]s$/,
...
});
If I comment them out to use default one, it seems not able to generate path correctly (got 404 instead of 200):
● GET /v2/todos › should return 200 for todos get request
expect(received).toEqual(expected) // deep equality
Expected: 200
Received: 404
110 | it('should return 200 for todos get request', async () => {
111 | const res = await req.get('/v2/todos');
112 | expect(res.statusCode).toEqual(200);
Update: the reason why it got 404, because paths
isn't populated since the following test case is passing:
describe('Get /v2/api-docs', () => {
it('should return 200 for api docs request', async () => {
const res = await req.get('/v2/api-docs');
expect(res.statusCode).toEqual(200);
//prove supertest not working with express-openapi since paths not populated
expect(res.body.paths).toEqual({});
});
});
@mwithington: It is working with jest-light-runner
as suggested by you against js files instead the ones ts-jest transformed from ts files.
So it appears to be typescript related problem when working express-open-api and supertest together.
I been trying to write some test with using using OpenAPI 2.0, I'm using this library to add the paths via the controllers but I always get a 404 response back from the tests,
Here is my
openapi.json
this is my controller
message.js
and here is my
app.js
configas for my test I only have the following
here is the console output.