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

Updating to node v20 and fixing tests #186

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open

Conversation

gclhub
Copy link

@gclhub gclhub commented Oct 10, 2024

Upgraded nodeJS version to v20. pre-commit tests began breaking because nock is no longer compatible with the native fetch library. Switched to fetch-mock instead of nock and two pre-commit tests are still failing and need to debugged.

Sample error message:

  ● Demotion report › method: execute() › execute() - Check report generated with audit log entries

    fetch-mock: No fallback response defined for GET to https://api.github.com/orgs/test/audit-log?include=all&per_page=100&phrase=created%3A%3E%3DFri%20Mar%2019%202021%2004%3A08%3A03%20GMT-0700%20%28Pacific%20Daylight%20Time%29%20created%3A%3C%3DFri%20Mar%2019%202021%2004%3A05%3A50%20GMT-0700%20%28Pacific%20Daylight%20Time%29%20

@gclhub
Copy link
Author

gclhub commented Oct 11, 2024

@stebje Here is my latest effort trying to get nodeJS upgraded and the pre-commit tests working. I had to use git commit --no-verify to temporarily skip the pre-commit tests so I could push the branch and create the draft PR.

The error message above is probably referencing something pretty simple, and I hope to get it working tomorrow unless you have an idea in the meantime.

@@ -52,7 +52,7 @@ class DemotionReportAction extends Command {
org: this.params.targetOrg,
include: 'all',
per_page: 100,
phrase: `created:>=${report.promotionDate} created:<=${report.demotionDate} `
phrase: `created:${report.promotionDate}..${report.demotionDate}`
Copy link
Author

Choose a reason for hiding this comment

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

return { ...issueOpenedMock, status: 'closed' }
})
const action = new CheckAutoDemotionAction(apis, mockParams)
const result = await action.execute()
expect(result.status).toBe('success')
expect.assertions(2)
expect.assertions(1)
Copy link
Author

Choose a reason for hiding this comment

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

@stebje I don't know if I did this correctly, but the number of expected assertions seemed to fail when the first one was in a closure above? I wonder if something changed with scoping. I reduced the number expected here and then added a new expectation in the block above, but let me know what you think.

demotionDate: new Date(Date.parse('2021-02-08T10:20:00Z')),
promotionDate: new Date(Date.parse('2021-02-07T10:20:00Z')),
demotionDate: '2021-02-08T10:20:00Z',
promotionDate: '2021-02-07T10:20:00Z',
Copy link
Author

Choose a reason for hiding this comment

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

@stebje I changed these dates back to the ISO-8601 form since the previous version was creating a more human-readable date string that seemed to break the test. Could this be related to the shift from nock to fetch-mock? Not sure if this fix is correct but it seems to get things working again.

return demotionAuditLog
})
phrase: `created:${mockParams.promotionDate}..${mockParams.demotionDate}`
}, demotionAuditLog)
Copy link
Author

Choose a reason for hiding this comment

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

@stebje This was throwing a Javascript error that I didn't quite understand, and Copilot recommended this change. I'm thinking this might be related to the calling convention of nock vs. fetch-mock?

@gclhub gclhub marked this pull request as ready for review October 11, 2024 21:24
@gclhub gclhub requested a review from a team as a code owner October 11, 2024 21:24
@gclhub gclhub requested a review from stebje October 11, 2024 21:24
@gclhub gclhub changed the title Updating to node v20 and fixing tests (WIP) Updating to node v20 and fixing tests Oct 11, 2024
@gclhub
Copy link
Author

gclhub commented Oct 11, 2024

N.B. The migration from nock to fetch-mock was required by upgrading from Node 16 to Node 20 as mentioned here nock/nock#2397

@gclhub
Copy link
Author

gclhub commented Oct 11, 2024

I was able to update most of the dependencies but still need to chase this one down that was not solved by simply updating the indirect dependencies:

# npm audit report

path-to-regexp  2.0.0 - 3.2.0
Severity: high
path-to-regexp outputs backtracking regular expressions - https://github.com/advisories/GHSA-9wv6-86v2-598j
No fix available
node_modules/path-to-regexp
  fetch-mock  6.0.0-beta.2 - 10.0.8
  Depends on vulnerable versions of path-to-regexp
  node_modules/fetch-mock-jest/node_modules/fetch-mock
    fetch-mock-jest  *
    Depends on vulnerable versions of fetch-mock
    node_modules/fetch-mock-jest

3 high severity vulnerabilities

Some issues need review, and may require choosing
a different dependency.

@gclhub
Copy link
Author

gclhub commented Oct 12, 2024

I was able to update most of the dependencies but still need to chase this one down that was not solved by simply updating the indirect dependencies:

# npm audit report

path-to-regexp  2.0.0 - 3.2.0
Severity: high
path-to-regexp outputs backtracking regular expressions - https://github.com/advisories/GHSA-9wv6-86v2-598j
No fix available
node_modules/path-to-regexp
  fetch-mock  6.0.0-beta.2 - 10.0.8
  Depends on vulnerable versions of path-to-regexp
  node_modules/fetch-mock-jest/node_modules/fetch-mock
    fetch-mock-jest  *
    Depends on vulnerable versions of fetch-mock
    node_modules/fetch-mock-jest

3 high severity vulnerabilities

Some issues need review, and may require choosing
a different dependency.

Never mind, this was a red herring that was fixed after I ran npm prune. However, there are now a number of critical dependency fixes now required but the updated versions contain breaking changes, so that will take a little bit of effort to troubleshoot.

@stebje
Copy link
Contributor

stebje commented Oct 15, 2024

Thanks for opening the PR @gclhub ! Stretched on time today but will try to reserve some time later this afternoon/evening and get back to this asap 🙏

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.

2 participants