StateVoicesNational / Spoke

mass-contact text/SMS distribution tool
Other
463 stars 403 forks source link

fix tests and other tweaks related to node 20 #2353

Closed lperson closed 6 months ago

lperson commented 6 months ago

This PR fixes a couple of failing tests.

Additional context in a slack thread.

Description

ERR_REQUIRE_ESM errors

Pinned strip-ansi to 6.0.1.

Failing actions

Failure in __test__/backend.test.js

Specify the campaign due date as milliseconds since the epoch when testing with SQLite.

I did a quick smoke test of copying a campaign in the UI when using SQLite and no additional special handling was necessary.

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

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

Checklist:

lperson commented 6 months ago

@mau11 I think it's worth reviewing this and merging it if you approve. It gets the tests a lot further than before.

I'll continue to work on the redis tests failing and make another PR.

engelhartrueben commented 6 months ago

This looks great!