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

chore: run tests on all supported versions of Node.js #77

Merged
merged 4 commits into from
Oct 25, 2023
Merged

Conversation

fasttime
Copy link
Member

@fasttime fasttime commented Oct 23, 2023

This PR fixes the unit tests on previous versions of Node.js (< 18). These tests are currently no longer working because of a breaking change in a dependency. See for example https://github.com/eslint/create-config/actions/runs/6609176505.

Unit tests in this package use esmock as a dev dependency.

  • esmock < 2.4 works only on Node.js < 19.
  • esmock >= 2.4 works only on Node.js >= 18.6.

(These is not officially specified information, I determined it by testing)

In order to run unit tests on all versions of Node.js that we need to support, I have created a postinstall script that checks the version of Node.js and replaces the esmock folder in node_modules with a legacy release on Node.js < 19.

@fasttime fasttime changed the title chore: pin esmock dependency to v2.3 chore: run tests on all supported versions of Node.js Oct 23, 2023

// esmock < 2.4 supports only Node.js < 19. esmock >= 2.4 supports only Node.js >= 18.6.
// If we are running Node.js < 19, replace the esmock dependency with the legacy release.
if (process.versions.modules < 111) {
Copy link
Member

Choose a reason for hiding this comment

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

out of curiosity: why not using process.versions.node? what's the 111? 🤔

Copy link
Member Author

Choose a reason for hiding this comment

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

111 is the ABI version number of Node.js 19, they're all listed at https://nodejs.org/en/download/releases.
process.versions.node seems more intuitive, and it should be fine to use it, although it's a string, so we'll need semver to do the comparison.

Copy link
Member

@aladdin-add aladdin-add left a comment

Choose a reason for hiding this comment

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

LGTM.

@fasttime
Copy link
Member Author

Thanks for the review @aladdin-add, I've added a commit to update the comments, including clarification about the 111. I'd be still open to switching to process.versions.node if that looks cleaner.

@fasttime fasttime marked this pull request as ready for review October 24, 2023 07:42
package.json Outdated
@@ -30,6 +30,7 @@
},
"scripts": {
"lint": "eslint . --report-unused-disable-directives",
"postinstall": "node tests/patch-esmock.js",
Copy link
Member

Choose a reason for hiding this comment

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

Does postinstall script also run when user installs this package?

Copy link
Member

Choose a reason for hiding this comment

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

good catch! 👍

I think we need to use prepare - it won't run in that case.

Copy link
Member Author

Choose a reason for hiding this comment

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

Does postinstall script also run when user installs this package?

I think you mean when a user runs npm install @eslint/create-config in a different package folder, or when they run npm install in a different package that includes @eslint/create-config as a dependency or devDependency. In either case: I don't know 🤷 and I don't trust the npm docs too much in this regard.

I have a package with some scripts I use for testing exactly for those cases: https://unpkg.com/@fasttime/[email protected]/package.json. Now if I run npm install @fasttime/npm-test in the directory of another package, none of the scripts seems to be run. I would assume this is the behavior we should expect from this change as well, but it's clearly possible that I'm missing something.

Copy link
Member

Choose a reason for hiding this comment

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

I believe the scripts are run in sort of silent mode. When I try with --loglevel verbose, it looks like some of the scripts (including postinstall) are run?

$ npm install --loglevel verbose @fasttime/npm-test
npm verb cli C:\Program Files\nodejs\node.exe C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js
npm info using [email protected]
npm info using [email protected]
npm verb title npm install @fasttime/npm-test
npm verb argv "install" "--loglevel" "verbose" "@fasttime/npm-test"
npm verb logfile logs-max:10 dir:C:\Users\milos\AppData\Local\npm-cache\_logs\2023-10-24T12_05_00_631Z-
npm verb logfile C:\Users\milos\AppData\Local\npm-cache\_logs\2023-10-24T12_05_00_631Z-debug-0.log
npm http fetch GET 200 https://registry.npmjs.org/@fasttime%2fnpm-test 1413ms (cache revalidated)
npm http fetch GET 200 https://registry.npmjs.org/inherits 5ms (cache hit)
npm info run @fasttime/[email protected] preinstall node_modules/@fasttime/npm-test echo *** preinstall ***
npm info run @fasttime/[email protected] preinstall { code: 0, signal: null }
npm info run @fasttime/[email protected] install node_modules/@fasttime/npm-test echo *** install ***
npm info run @fasttime/[email protected] install { code: 0, signal: null }
npm info run @fasttime/[email protected] postinstall node_modules/@fasttime/npm-test echo *** postinstall ***
npm info run @fasttime/[email protected] postinstall { code: 0, signal: null }
npm http fetch POST 200 https://registry.npmjs.org/-/npm/v1/security/advisories/bulk 222ms

added 2 packages, and audited 3 packages in 2s

found 0 vulnerabilities
npm verb exit 0
npm info ok

Copy link
Member Author

Choose a reason for hiding this comment

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

Interesting, I never noticed that npm was silencing the output. In this case, yes, we need to use the prepare script instead of postinstall. Now, prepare also runs on npm pack and npm publish when no dependencies are being installed, so we will also need a check to ensure that nothing happens if esmock_legacy is missing. I'll prepare an update.

Copy link
Member Author

Choose a reason for hiding this comment

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

Updated, please check again.

Copy link
Member

@mdjermanovic mdjermanovic left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@mdjermanovic mdjermanovic merged commit f7da13a into main Oct 25, 2023
14 checks passed
@mdjermanovic mdjermanovic deleted the pin-esmock branch October 25, 2023 20:33
@github-actions github-actions bot mentioned this pull request Oct 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants