overleaf/libraries/fetch-utils
Antoine Clausse 5afa892981 [fetch-utils] Fix unit tests (#20210)
* [fetch-utils] Fix FetchUtilsTests.js tests

* Cleanup between tests
* Define `AbortError`

* [fetch-utils] Add `expectConnectionCount` showcasing that the connection stays on when the stream is destroyed

* Revert "[fetch-utils] Add `expectConnectionCount` showcasing that the connection stays on when the stream is destroyed"

This reverts commit b10da7b3fc06a7345df8fd70f27fad70a478bbb4.

* [fetch-utils] Fix `supports abort signals` test

* [fetch-utils] Add tests "aborts the request when the request body is destroyed during transfer"

* [fetch-utils] Add extra waiting step before `expectRequestAborted`

* [fetch-utils] Add `while (!req?.destroyed) await wait(10)`

Unfortunately I couldn't find a better event to await.

To try with this to test flakiness
```
for i in {1..100}; do npm run test:unit || break; echo "Run $i completed"; done
```

* [fetch-utils] Replace arbitrary `wait(10)` by `this.server.waitForEvent('request-received')`

* [fetch-utils] Improve tests per PR comments

See https://github.com/overleaf/internal/pull/20210

1. Replace `waitForEvent` with `once`
2. Replace `waitForRequestAborted` by `expectRequestAborted`
3. Add comment in `expectRequestAborted` empty catch block

Non-flakiness rechecked with `for i in {1..100}; do npm run test:unit || break; echo "Run $i completed"; done`

* [fetch-utils] Add small wait before checking `lastReq === undefined`

Per https://github.com/overleaf/internal/pull/20210#discussion_r1743329462

GitOrigin-RevId: 5fe542e0a8e6011307e03237e2f81404d9a0e674
2024-09-05 08:05:57 +00:00
..
test [fetch-utils] Fix unit tests (#20210) 2024-09-05 08:05:57 +00:00
.dockerignore Merge pull request #14029 from overleaf/bg-csh-kustomize-spelling-2 2023-07-26 08:04:39 +00:00
.gitignore Merge pull request #14029 from overleaf/bg-csh-kustomize-spelling-2 2023-07-26 08:04:39 +00:00
.mocharc.json Merge pull request #14029 from overleaf/bg-csh-kustomize-spelling-2 2023-07-26 08:04:39 +00:00
.nvmrc Merge pull request #17870 from overleaf/bg-node-upgrade-18-20-2 2024-04-24 08:05:16 +00:00
buildscript.txt Merge pull request #17870 from overleaf/bg-node-upgrade-18-20-2 2024-04-24 08:05:16 +00:00
index.js Merge pull request #20058 from overleaf/mj-promisify-tpr 2024-09-02 08:04:55 +00:00
package.json Merge pull request #18289 from overleaf/ac-ar-eslint-return-await 2024-05-27 10:22:49 +00:00
tsconfig.json Merge pull request #18167 from overleaf/em-simpler-typescript-backend 2024-05-07 08:04:00 +00:00