Skip to content

Commit

Permalink
test: correct unhandled error events
Browse files Browse the repository at this point in the history
build-request-file-object.test.js and get-content-type.test.js both make use of streams with non-existent paths to check errors. Possibly since upgrading jest these cause suites to fail with e.g.
```
Error: ENOENT: no such file or directory, open '/fake/path/custom-name.env'
Emitted 'error' event on ReadStream instance at:
    at emitErrorNT (node:internal/streams/destroy:157:8)
    at emitErrorCloseNT (node:internal/streams/destroy:122:3)
    at processTicksAndRejections (node:internal/process/task_queues:83:21) {
  errno: -2,
  code: 'ENOENT',
  syscall: 'open',
  path: '/fake/path/custom-name.env'
```

Since the errors are expected for these tests add a no-op handler to handle the error events.

Signed-off-by: Rich Ellis <[email protected]>
  • Loading branch information
ricellis authored and dpopp07 committed Dec 20, 2022
1 parent 1b90a2b commit 6979711
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
6 changes: 4 additions & 2 deletions test/unit/build-request-file-object.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ describe('buildRequestFileObject', () => {
});

it('should handle file object with a readable stream as its `value`', async () => {
const fileStream = fs.createReadStream(filepath);
// Note add an on error handler to avoid unhandled error events
const fileStream = fs.createReadStream(filepath).on('error', () => {});
fileStream.path = `/fake/path/${customName}`;

const fileParams = {
Expand All @@ -76,7 +77,8 @@ describe('buildRequestFileObject', () => {
});

it('should handle path property being a buffer', async () => {
const fileStream = fs.createReadStream(filepath);
// Note add an on error handler to avoid unhandled error events
const fileStream = fs.createReadStream(filepath).on('error', () => {});
fileStream.path = Buffer.from(`/fake/path/${customName}`);

const fileParams = {
Expand Down
3 changes: 2 additions & 1 deletion test/unit/get-content-type.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ describe('getContentType', () => {
});

it('should not get content type from read stream with corrupted path property', async () => {
const streamFile = fs.createReadStream(filepath);
// Note add an on error handler to avoid unhandled error events
const streamFile = fs.createReadStream(filepath).on('error', () => {});
streamFile.path = 'unrecognizeable-format';
expect(await getContentType(streamFile)).toBeNull();
});
Expand Down

0 comments on commit 6979711

Please sign in to comment.