From 21ecd9c2af94059ca3e169735266d73b09ec4a62 Mon Sep 17 00:00:00 2001 From: Kevin Ansfield Date: Thu, 26 Sep 2024 15:32:16 +0100 Subject: [PATCH] Fixed tests failing with native stack traces due to blob.slice() calls no issue Either a node or macOS update resulted in our broken image upload tests causing native stack traces: ``` # /Users/kevin/.nvm/versions/node/v20.16.0/bin/node[8841]: static void node::Blob::ToSlice(const FunctionCallbackInfo &) at ../src/node_blob.cc:248 # Assertion failed: args[1]->IsUint32() ``` - updated our `blob.slice()` calls to ensure the second argument is always an integer rather than possibly a float --- ghost/core/test/e2e-api/admin/images.test.js | 4 ++-- ghost/core/test/e2e-api/admin/media.test.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/ghost/core/test/e2e-api/admin/images.test.js b/ghost/core/test/e2e-api/admin/images.test.js index ee882b35cb..8d4aad72ea 100644 --- a/ghost/core/test/e2e-api/admin/images.test.js +++ b/ghost/core/test/e2e-api/admin/images.test.js @@ -342,7 +342,7 @@ describe('Images API', function () { const brokenPayload = '--boundary\r\nContent-Disposition: form-data; name=\"image\"; filename=\"example.png\"\r\nContent-Type: image/png\r\n\r\n'; // eslint-disable-next-line no-undef - const brokenDataBlob = await (new Blob([brokenPayload, blob.slice(0, blob.size / 2)], { + const brokenDataBlob = await (new Blob([brokenPayload, blob.slice(0, Math.floor(blob.size / 2))], { type: 'multipart/form-data; boundary=boundary' })).text(); @@ -367,7 +367,7 @@ describe('Images API', function () { const brokenPayload = '--boundary\r\nContent-Disposition: form-data; name=\"image\"; filename=\"example.png\"\r\nContent-Type: image/png\r\n'; // eslint-disable-next-line no-undef - const brokenDataBlob = await (new Blob([brokenPayload, blob.slice(0, blob.size / 2)], { + const brokenDataBlob = await (new Blob([brokenPayload, blob.slice(0, Math.floor(blob.size / 2))], { type: 'multipart/form-data; boundary=boundary' })).text(); diff --git a/ghost/core/test/e2e-api/admin/media.test.js b/ghost/core/test/e2e-api/admin/media.test.js index 0baaef3e5a..5f88cb489e 100644 --- a/ghost/core/test/e2e-api/admin/media.test.js +++ b/ghost/core/test/e2e-api/admin/media.test.js @@ -140,7 +140,7 @@ describe('Media API', function () { const brokenPayload = '--boundary\r\nContent-Disposition: form-data; name=\"image\"; filename=\"example.png\"\r\nContent-Type: image/png\r\n\r\n'; // eslint-disable-next-line no-undef - const brokenDataBlob = await (new Blob([brokenPayload, blob.slice(0, blob.size / 2)], { + const brokenDataBlob = await (new Blob([brokenPayload, blob.slice(0, Math.floor(blob.size / 2))], { type: 'multipart/form-data; boundary=boundary' })).text(); @@ -164,7 +164,7 @@ describe('Media API', function () { const brokenPayload = '--boundary\r\nContent-Disposition: form-data; name=\"image\"; filename=\"example.png\"\r\nContent-Type: image/png\r\n'; // eslint-disable-next-line no-undef - const brokenDataBlob = await (new Blob([brokenPayload, blob.slice(0, blob.size / 2)], { + const brokenDataBlob = await (new Blob([brokenPayload, blob.slice(0, Math.floor(blob.size / 2))], { type: 'multipart/form-data; boundary=boundary' })).text();