Skip to content

Commit e986194

Browse files
authored
fix tests and other tweaks related to node 20 (#2353)
* Update a test's expectation to align with a change in a Node exception The failing test was testing a failure caused by trying to parse an object as if it were a JSON string. It’s failing because the exception thrown by a JSON parse error changed between Node versions. Node 16.18.0 ============ ``` ==> node Welcome to Node.js v16.18.0. Type ".help" for more information. > JSON.parse("{") Uncaught SyntaxError: Unexpected end of JSON input > JSON.parse({}) Uncaught SyntaxError: Unexpected token o in JSON at position 1 ``` Node 20.11.1 ============ ``` ==> nvm use 20.11.1 Now using node v20.11.1 (npm v10.2.4) ==> node Welcome to Node.js v20.11.1. Type ".help" for more information. > JSON.parse({}) Uncaught SyntaxError: "[object Object]" is not valid JSON ``` * SQLite stores dates as an integer. You can get the integer from a javascript date with `.getTime()` * don't pin the version of -- fix github actions not working with node 20 specified in package.json * force CI * try v4 instead of no version specified * update cache to v4 to get node 20 support * use node version 20 * Try to pin strip-ansi * try without caching * caching is not the problem; let's force strip-ansi to use a non ESM version * make yarn.lock consistent with pinning strip-ansi
1 parent 93d72d0 commit e986194

5 files changed

Lines changed: 63 additions & 72 deletions

File tree

.github/workflows/jest-tests.yaml

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,14 @@ jobs:
2424
- 5432:5432
2525
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
2626
steps:
27-
- uses: actions/checkout@v3
27+
- uses: actions/checkout@v4
28+
- uses: actions/setup-node@v4
29+
with:
30+
node-version: 20
2831
- name: Get yarn cache directory path
2932
id: yarn-cache-dir-path
3033
run: echo "::set-output name=dir::$(yarn cache dir)"
31-
- uses: actions/cache@v1
34+
- uses: actions/cache@v4
3235
id: yarn-cache
3336
with:
3437
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
@@ -57,11 +60,14 @@ jobs:
5760
- 5432:5432
5861
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
5962
steps:
60-
- uses: actions/checkout@v3
63+
- uses: actions/checkout@v4
64+
- uses: actions/setup-node@v4
65+
with:
66+
node-version: 20
6167
- name: Get yarn cache directory path
6268
id: yarn-cache-dir-path
6369
run: echo "::set-output name=dir::$(yarn cache dir)"
64-
- uses: actions/cache@v1
70+
- uses: actions/cache@v4
6571
id: yarn-cache
6672
with:
6773
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
@@ -90,11 +96,14 @@ jobs:
9096
- 5432:5432
9197
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
9298
steps:
93-
- uses: actions/checkout@v3
99+
- uses: actions/checkout@v4
100+
- uses: actions/setup-node@v4
101+
with:
102+
node-version: 20
94103
- name: Get yarn cache directory path
95104
id: yarn-cache-dir-path
96105
run: echo "::set-output name=dir::$(yarn cache dir)"
97-
- uses: actions/cache@v1
106+
- uses: actions/cache@v4
98107
id: yarn-cache
99108
with:
100109
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
@@ -114,11 +123,15 @@ jobs:
114123
ports:
115124
- 6379:6379
116125
steps:
117-
- uses: actions/checkout@v3
126+
- uses: actions/checkout@v4
127+
- uses: actions/setup-node@v4
128+
with:
129+
node-version: 20
130+
118131
- name: Get yarn cache directory path
119132
id: yarn-cache-dir-path
120133
run: echo "::set-output name=dir::$(yarn cache dir)"
121-
- uses: actions/cache@v1
134+
- uses: actions/cache@v4
122135
id: yarn-cache
123136
with:
124137
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}

__test__/backend.test.js

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1+
import { graphql } from "graphql";
12
import { isSqlite } from "../src/server/models/";
23
import { resolvers } from "../src/server/api/schema";
34
import { schema as apiSchema } from "../src/api/schema";
4-
import { graphql } from "graphql";
55

66
console.log("This is an intentional error");
77

@@ -535,14 +535,18 @@ describe("graphql test suite", () => {
535535
organization_id: organization.id,
536536
role: "OWNER"
537537
}).save();
538+
539+
const now = new Date();
540+
const dueBy = isSqlite ? now.getTime() : now;
541+
538542
// creating campaign, interactions (two levels down), and canned responses
539543
campaign = await new Campaign({
540544
organization_id: organization.id,
541545
title: "My campaign",
542546
description: "This is my new campaign",
543547
is_started: false,
544548
is_archived: false,
545-
due_by: new Date(),
549+
due_by: dueBy,
546550
features: JSON.stringify({ MY_FEATURE: "value 1" }),
547551
intro_html: "<p>This is my intro HTML.</p>",
548552
primary_color: "#112233",
@@ -632,30 +636,19 @@ describe("graphql test suite", () => {
632636
typeof copiedCampaign.due_by === "number" ||
633637
typeof copiedCampaign.due_by === "string"
634638
) {
635-
let parsedDate = new Date(copiedCampaign.due_by);
639+
const parsedDate = new Date(copiedCampaign.due_by);
636640
expect(parsedDate).toEqual(campaign.due_by);
641+
} else if (isSqlite) {
642+
expect(copiedCampaign.due_by.getTime()).toEqual(campaign.due_by);
637643
} else {
638-
if (isSqlite) {
639-
// Currently an open issue w/ datetime being stored as a string in SQLite3
640-
// for Jest tests: https://github.com/TryGhost/node-sqlite3/issues/1355.
641-
// This results in milliseconds being truncated when getting campaign due_by
642-
643-
// 3.15.2024 => Fails in SQLite testing now, but passes in PG.
644-
// copiedCampaign.due_by is an Invalid Date, and at some point
645-
// uses Date.parse()
646-
const campaignDueBy = campaign.due_by;
647-
648-
campaignDueBy.setMilliseconds(0);
649-
expect(copiedCampaign.due_by).toEqual(campaignDueBy);
650-
} else {
651-
expect(copiedCampaign.due_by).toEqual(campaign.due_by);
652-
}
644+
expect(copiedCampaign.due_by).toEqual(campaign.due_by);
653645
}
646+
654647
if (
655648
typeof copiedCampaign.features === "object" &&
656649
copiedCampaign.features
657650
) {
658-
let jsonString = JSON.stringify(copiedCampaign.features);
651+
const jsonString = JSON.stringify(copiedCampaign.features);
659652
expect(jsonString).toEqual(campaign.features);
660653
} else {
661654
expect(copiedCampaign.features).toEqual(campaign.features);

__test__/extensions/action-handlers/ngpvan-action.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1071,7 +1071,7 @@ describe("ngpvn-action", () => {
10711071
}
10721072

10731073
expect(error.message).toEqual(
1074-
expect.stringMatching(/^unexpected token*/i)
1074+
expect.stringMatching(/^.*is not valid json.*$/i)
10751075
);
10761076

10771077
expect(postPeopleCanvassResponsesNock.isDone()).toEqual(false);

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,5 +237,8 @@
237237
"react-formal": "2.2.2",
238238
"react-router": "^3.2.0",
239239
"react-tooltip": "^4.2.13"
240+
},
241+
"resolutions": {
242+
"strip-ansi": "6.0.1"
240243
}
241244
}

yarn.lock

Lines changed: 26 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -4823,26 +4823,11 @@ ansi-regex@^2.0.0:
48234823
resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-2.1.1.tgz#c3b33ab5ee360d86e0e628f0468ae7ef27d654df"
48244824
integrity sha512-TIGnTpdo+E3+pCyAluZvtED5p5wCqLdezCyhPZzKPcxvFplEt4i+W7OONCKgeZFT3+y5NZZfOOS/Bdcanm1MYA==
48254825

4826-
ansi-regex@^3.0.0:
4827-
version "3.0.1"
4828-
resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-3.0.1.tgz#123d6479e92ad45ad897d4054e3c7ca7db4944e1"
4829-
integrity sha512-+O9Jct8wf++lXxxFc4hc8LsjaSq0HFzzL7cVsw8pRDIPdjKD2mT4ytDZlLuSBZ4cLKZFXIrMGO7DbQCtMJJMKw==
4830-
4831-
ansi-regex@^4.1.0:
4832-
version "4.1.1"
4833-
resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-4.1.1.tgz#164daac87ab2d6f6db3a29875e2d1766582dabed"
4834-
integrity sha512-ILlv4k/3f6vfQ4OoP2AGvirOktlQ98ZEL1k9FaQjxa3L1abBgbuTDAdPOpvbGncC0BTVQrl+OM8xZGK6tWXt7g==
4835-
48364826
ansi-regex@^5.0.1:
48374827
version "5.0.1"
48384828
resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-5.0.1.tgz#082cb2c89c9fe8659a311a53bd6a4dc5301db304"
48394829
integrity sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==
48404830

4841-
ansi-regex@^6.0.1:
4842-
version "6.0.1"
4843-
resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-6.0.1.tgz#3183e38fae9a65d7cb5e53945cd5897d0260a06a"
4844-
integrity sha512-n5M855fKb2SsfMIiFFoVrABHJC8QtHwVx+mHWP3QcEqBHYienj5dHSgjbxtC0WEZXYt4wcD6zrQElDPhFuZgfA==
4845-
48464831
ansi-styles@^2.2.1:
48474832
version "2.2.1"
48484833
resolved "https://registry.yarnpkg.com/ansi-styles/-/ansi-styles-2.2.1.tgz#b432dd3358b634cf75e1e4664368240533c1ddbe"
@@ -17015,7 +17000,7 @@ string-natural-compare@^3.0.1:
1701517000
resolved "https://registry.yarnpkg.com/string-natural-compare/-/string-natural-compare-3.0.1.tgz#7a42d58474454963759e8e8b7ae63d71c1e7fdf4"
1701617001
integrity sha512-n3sPwynL1nwKi3WJ6AIsClwBMa0zTi54fn2oLU6ndfTSIO05xaznjSf15PcBZU6FNWbmN5Q6cxT4V5hGvB4taw==
1701717002

17018-
"string-width-cjs@npm:string-width@^4.2.0", "string-width@^1.0.2 || 2 || 3 || 4", string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3:
17003+
"string-width-cjs@npm:string-width@^4.2.0":
1701917004
version "4.2.3"
1702017005
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
1702117006
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
@@ -17033,6 +17018,15 @@ string-width@^1.0.1:
1703317018
is-fullwidth-code-point "^1.0.0"
1703417019
strip-ansi "^3.0.0"
1703517020

17021+
"string-width@^1.0.2 || 2 || 3 || 4", string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3:
17022+
version "4.2.3"
17023+
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
17024+
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
17025+
dependencies:
17026+
emoji-regex "^8.0.0"
17027+
is-fullwidth-code-point "^3.0.0"
17028+
strip-ansi "^6.0.1"
17029+
1703617030
string-width@^2.1.1:
1703717031
version "2.1.1"
1703817032
resolved "https://registry.yarnpkg.com/string-width/-/string-width-2.1.1.tgz#ab93f27a8dc13d28cac815c462143a6d9012ae9e"
@@ -17133,40 +17127,19 @@ stringify-object@^3.3.0:
1713317127
is-obj "^1.0.1"
1713417128
is-regexp "^1.0.0"
1713517129

17136-
"strip-ansi-cjs@npm:strip-ansi@^6.0.1", strip-ansi@^6.0.0, strip-ansi@^6.0.1:
17130+
"strip-ansi-cjs@npm:strip-ansi@^6.0.1":
1713717131
version "6.0.1"
1713817132
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
1713917133
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
1714017134
dependencies:
1714117135
ansi-regex "^5.0.1"
1714217136

17143-
strip-ansi@^3.0.0, strip-ansi@^3.0.1:
17144-
version "3.0.1"
17145-
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-3.0.1.tgz#6a385fb8853d952d5ff05d0e8aaf94278dc63dcf"
17146-
integrity sha512-VhumSSbBqDTP8p2ZLKj40UjBCV4+v8bUSEpUb4KjRgWk9pbqGF4REFj6KEagidb2f/M6AzC0EmFyDNGaw9OCzg==
17147-
dependencies:
17148-
ansi-regex "^2.0.0"
17149-
17150-
strip-ansi@^4.0.0:
17151-
version "4.0.0"
17152-
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-4.0.0.tgz#a8479022eb1ac368a871389b635262c505ee368f"
17153-
integrity sha512-4XaJ2zQdCzROZDivEVIDPkcQn8LMFSa8kj8Gxb/Lnwzv9A8VctNZ+lfivC/sV3ivW8ElJTERXZoPBRrZKkNKow==
17154-
dependencies:
17155-
ansi-regex "^3.0.0"
17156-
17157-
strip-ansi@^5.0.0, strip-ansi@^5.1.0, strip-ansi@^5.2.0:
17158-
version "5.2.0"
17159-
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-5.2.0.tgz#8c9a536feb6afc962bdfa5b104a5091c1ad9c0ae"
17160-
integrity sha512-DuRs1gKbBqsMKIZlrffwlug8MHkcnpjs5VPmL1PAh+mA30U0DTotfDZ0d2UUsXpPmPmMMJ6W773MaA3J+lbiWA==
17161-
dependencies:
17162-
ansi-regex "^4.1.0"
17163-
17164-
strip-ansi@^7.0.1:
17165-
version "7.1.0"
17166-
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-7.1.0.tgz#d5b6568ca689d8561370b0707685d22434faff45"
17167-
integrity sha512-iq6eVVI64nQQTRYq2KtEg2d2uU7LElhTJwsH4YzIHZshxlgZms/wIc4VoDQTlG/IvVIrBKG06CrZnp0qv7hkcQ==
17137+
strip-ansi@6.0.1, strip-ansi@^3.0.0, strip-ansi@^3.0.1, strip-ansi@^4.0.0, strip-ansi@^5.0.0, strip-ansi@^5.1.0, strip-ansi@^5.2.0, strip-ansi@^6.0.0, strip-ansi@^6.0.1, strip-ansi@^7.0.1:
17138+
version "6.0.1"
17139+
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
17140+
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
1716817141
dependencies:
17169-
ansi-regex "^6.0.1"
17142+
ansi-regex "^5.0.1"
1717017143

1717117144
strip-bom@^2.0.0:
1717217145
version "2.0.0"
@@ -18942,7 +18915,7 @@ workbox-window@6.6.1:
1894218915
"@types/trusted-types" "^2.0.2"
1894318916
workbox-core "6.6.1"
1894418917

18945-
"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0", wrap-ansi@^7.0.0:
18918+
"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0":
1894618919
version "7.0.0"
1894718920
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43"
1894818921
integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==
@@ -18968,6 +18941,15 @@ wrap-ansi@^5.1.0:
1896818941
string-width "^3.0.0"
1896918942
strip-ansi "^5.0.0"
1897018943

18944+
wrap-ansi@^7.0.0:
18945+
version "7.0.0"
18946+
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43"
18947+
integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==
18948+
dependencies:
18949+
ansi-styles "^4.0.0"
18950+
string-width "^4.1.0"
18951+
strip-ansi "^6.0.0"
18952+
1897118953
wrap-ansi@^8.1.0:
1897218954
version "8.1.0"
1897318955
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-8.1.0.tgz#56dc22368ee570face1b49819975d9b9a5ead214"

0 commit comments

Comments
 (0)