forwardemail / forwardemail/supertest

Error response: WebSockets request was expected

Open
#787 6 comments 1 reaction 0 assignees View on GitHub
Dominant language
JavaScript
Stars
14.4k
Forks
782
PR merge metrics
No merged PRs in 30d

Description

I have an almost identical test case to https://github.com/visionmedia/supertest/issues/566 , except in my test I'm iterating over the `await request().get().expect()` 1000 times, to test the performance of the endpoint.

80% of the time, the tests pass, but occasionally I hit the following issue.

> Error: expected '{"mydata":0}' response body, got 'WebSockets request was expected\r\n'

(400 Bad Request)

Has anyone seen this before?

I've tried adding Promise awaits for the handlers in the beforeEach/afterEach, to no avail.

---

Node: v18.3.0
Express: 4.17.1
Supertest: 6.2.4

TestCase.ts
```javascript
import express, { Application } from 'express'
import { Server } from 'http'
import { describe, it } from 'mocha'
import request from 'supertest'
import MyRouter from '../../src/routes/MyRouter'

describe('wip PerformanceTesting - 1000x should be less than X milliseconds', () => {
const app: Application = express().use(MyRouter)
let server: Server

beforeEach(async () => {
server = await new Promise((resolve) => {
const s = app.listen(0, () => resolve(s))
})
})

afterEach(async () => {
await new Promise((resolve) => server.close(() => resolve(null)))
})

it('my performance test', async () => {
for (let i = 0; i < 1000; i++) await request(app).get('/api/sales/data').expect('{"mydata":0}').expect(200)
}).timeout(1000)
})

```

Contributor guide

Open the contributing guide

Research direction

Start with the repeated request case in TestCase.ts, using MyRouter and the /api/sales/data endpoint, then inspect the beforeEach and afterEach server lifecycle. Reproduce the intermittent 400 response with the listed Node, Express, and Supertest versions; done means explaining why some of the 1000 requests receive the WebSockets response and establishing reliable expected responses.

Written by the indexing model from the issue text.

Assessment

Tech stack
express, javascript, node.js
Domain
testing-qa
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.