diff options
author | 2023-01-06 18:01:54 +0100 | |
---|---|---|
committer | 2023-01-06 12:01:54 -0500 | |
commit | 2f6745019ac25785032ac3659c2433b6e224f383 (patch) | |
tree | 4c104600c0450ad6fa1bdb7180bd97a2f7b60971 /packages/integrations/node/test/test-utils.js | |
parent | 23937fbbc9fc5647d155dbe418c7c2afd4814c06 (diff) | |
download | astro-2f6745019ac25785032ac3659c2433b6e224f383.tar.gz astro-2f6745019ac25785032ac3659c2433b6e224f383.tar.zst astro-2f6745019ac25785032ac3659c2433b6e224f383.zip |
Drop Node 14 in CI for Node 16 and add Node 18 to the matrix (#5768)
* ci(node): Move CI to Node 16 and add Node 18 to the matrix
* fix(netlify): Fix set-cookie not working on Node 18
* fix(netlify): Handle if `set-cookie` is already somehow an array (apparently it can?)
* test(node): Fix `toPromise` to match Astro's
* fix(tests): Use the actual underlying ArrayBuffer instance to create the buffer in toPromise
* chore: changeset
Diffstat (limited to 'packages/integrations/node/test/test-utils.js')
-rw-r--r-- | packages/integrations/node/test/test-utils.js | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/packages/integrations/node/test/test-utils.js b/packages/integrations/node/test/test-utils.js index 0859c6acd..d3d7c17be 100644 --- a/packages/integrations/node/test/test-utils.js +++ b/packages/integrations/node/test/test-utils.js @@ -1,6 +1,6 @@ -import { loadFixture as baseLoadFixture } from '../../../astro/test/test-utils.js'; -import httpMocks from 'node-mocks-http'; import { EventEmitter } from 'events'; +import httpMocks from 'node-mocks-http'; +import { loadFixture as baseLoadFixture } from '../../../astro/test/test-utils.js'; /** * @typedef {import('../../../astro/test/test-utils').Fixture} Fixture @@ -33,6 +33,15 @@ export function createRequestAndResponse(reqOptions) { export function toPromise(res) { return new Promise((resolve) => { + // node-mocks-http doesn't correctly handle non-Buffer typed arrays, + // so override the write method to fix it. + const write = res.write; + res.write = function (data, encoding) { + if (ArrayBuffer.isView(data) && !Buffer.isBuffer(data)) { + data = Buffer.from(data.buffer); + } + return write.call(this, data, encoding); + }; res.on('end', () => { let chunks = res._getChunks(); resolve(chunks); |