From c40713bd704fe95ab1e7ba8912b2a9297fa37f79 Mon Sep 17 00:00:00 2001 From: Daniel Lockyer Date: Thu, 18 Apr 2024 12:48:33 +0200 Subject: [PATCH 1/2] Fixed test on Node 20 refs https://github.com/TryGhost/gscan/commit/f39d1d3aa365329cf789fd37fc233628bb86b4c0 - similar to the commit above, the JSON parser changed between Node 18 and Node 20, so the error message changed too - we actually just want to check the error is forwarded to the user, so we can do that by getting the error message from JSON.parse and check against that --- .../services/custom-redirects/api.test.js | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/ghost/core/test/unit/server/services/custom-redirects/api.test.js b/ghost/core/test/unit/server/services/custom-redirects/api.test.js index 66754f3c82fb..d7836996cf5e 100644 --- a/ghost/core/test/unit/server/services/custom-redirects/api.test.js +++ b/ghost/core/test/unit/server/services/custom-redirects/api.test.js @@ -95,15 +95,29 @@ describe('UNIT: redirects CustomRedirectsAPI class', function () { describe('setFromFilePath', function () { it('throws a syntax error when setting invalid JSON redirects file', async function () { + const invalidJSON = '{invalid json'; const invalidFilePath = path.join(__dirname, '/invalid/redirects/path.json'); - fs.readFile.withArgs(invalidFilePath, 'utf-8').resolves('{invalid json'); + fs.readFile.withArgs(invalidFilePath, 'utf-8').resolves(invalidJSON); + + let expectedErrorMessage; + + try { + JSON.parse(invalidJSON); + } catch (err) { + expectedErrorMessage = err.message; + } + + if (!expectedErrorMessage) { + // This should never happen because the JSON is invalid + should.fail('expectedErrorMessage is not set'); + } try { await customRedirectsAPI.setFromFilePath(invalidFilePath, '.json'); should.fail('setFromFilePath did not throw'); } catch (err) { should.exist(err); - err.message.should.eql('Could not parse JSON: Unexpected token i in JSON at position 1.'); + err.message.should.eql(`Could not parse JSON: ${expectedErrorMessage}.`); } }); From 682a770bf92c4e1c22a2982f05bf0a31c1bc6a59 Mon Sep 17 00:00:00 2001 From: Daniel Lockyer Date: Tue, 19 Mar 2024 11:02:04 +0100 Subject: [PATCH 2/2] =?UTF-8?q?=E2=84=B9=EF=B8=8F=20Added=20support=20for?= =?UTF-8?q?=20Node=2020?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ref https://linear.app/tryghost/issue/ENG-765/add-support-for-node-20 - this adds support for Node 20 to Ghost and CI, as Node 20 is an LTS version and we should pick it up --- .github/workflows/ci.yml | 4 ++-- ghost/admin/package.json | 2 +- ghost/core/package.json | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 071978a776c7..ef450b50bf40 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -417,7 +417,7 @@ jobs: if: needs.job_get_metadata.outputs.changed_any_code == 'true' strategy: matrix: - node: [ '18.12.1' ] + node: [ '18.12.1', '20.11.1' ] name: Unit tests (Node ${{ matrix.node }}) steps: - uses: actions/checkout@v4 @@ -455,7 +455,7 @@ jobs: if: needs.job_get_metadata.outputs.changed_core == 'true' strategy: matrix: - node: [ '18.12.1' ] + node: [ '18.12.1', '20.11.1' ] env: - DB: mysql8 NODE_ENV: testing-mysql diff --git a/ghost/admin/package.json b/ghost/admin/package.json index a42fa0d49b82..7c66f4e95eed 100644 --- a/ghost/admin/package.json +++ b/ghost/admin/package.json @@ -26,7 +26,7 @@ "lint": "yarn lint:js && yarn lint:hbs" }, "engines": { - "node": "^18.12.1" + "node": "^18.12.1 || ^20.11.1" }, "devDependencies": { "@babel/eslint-parser": "7.23.3", diff --git a/ghost/core/package.json b/ghost/core/package.json index 1c51bf386b89..376faab25a54 100644 --- a/ghost/core/package.json +++ b/ghost/core/package.json @@ -53,8 +53,8 @@ "prepack": "node monobundle.js" }, "engines": { - "node": "^18.12.1", - "cli": "^1.25.0" + "node": "^18.12.1 || ^20.11.1", + "cli": "^1.26.0" }, "dependencies": { "@extractus/oembed-extractor": "3.2.1",