Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix tests and other tweaks related to node 20 #2353

Merged

Conversation

lperson
Copy link
Collaborator

@lperson lperson commented Mar 24, 2024

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

  • Updated actions/checkout@v3 to actions/checkout@v4 so it doesn't complain about node 20.
  • Updated actions/cache@v3 to actions/cache@v4 so it doesn't complain about node 20.

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:

  • I have manually tested my changes on desktop and mobile
  • The test suite passes locally with my changes
  • If my change is a UI change, I have attached a screenshot to the description section of this pull request
  • My change is 300 lines of code or less, or has a documented reason in the description why it’s longer
  • I have made any necessary changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works
  • My PR is labeled [WIP] if it is in progress

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

```
@lperson lperson marked this pull request as draft March 24, 2024 19:46
@lperson lperson requested a review from mau11 March 24, 2024 19:56
You can get the integer from a javascript date with `.getTime()`
@lperson lperson marked this pull request as ready for review March 24, 2024 22:00
@@ -632,30 +636,19 @@ describe("graphql test suite", () => {
typeof copiedCampaign.due_by === "number" ||
typeof copiedCampaign.due_by === "string"
) {
let parsedDate = new Date(copiedCampaign.due_by);
const parsedDate = new Date(copiedCampaign.due_by);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To silence the linter.

if (
typeof copiedCampaign.features === "object" &&
copiedCampaign.features
) {
let jsonString = JSON.stringify(copiedCampaign.features);
const jsonString = JSON.stringify(copiedCampaign.features);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To silence the linter.

@lperson lperson changed the title Update a test's expectation to align with a change in a Node exception fix a couple of tests Mar 24, 2024
@lperson lperson changed the base branch from new-node-20-branch to main March 24, 2024 23:09
@lperson lperson changed the base branch from main to new-node-20-branch March 24, 2024 23:32
@lperson lperson changed the title fix a couple of tests fix tests and other tweaks related to node 20 Mar 25, 2024
@lperson
Copy link
Collaborator Author

lperson commented Mar 25, 2024

@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.

Copy link
Member

@mau11 mau11 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks Larry 🎉 great fixes!

@engelhartrueben
Copy link
Collaborator

This looks great!

@mau11 mau11 merged commit e986194 into StateVoicesNational:new-node-20-branch Mar 25, 2024
6 of 8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants