Skip to content

Conversation

@MasterOdin
Copy link
Contributor

@MasterOdin MasterOdin commented Mar 6, 2025

Closes #155

PR moves the test suite over from vows (which is defunct and doesn't work properly on Node >= 10) to jest. I did have to use a somewhat older version of jest to run against older EOL versions of node. Based on #153 (comment), I chose the newest version that would still allow for testing and specifying node >= 6 in the engines field (once async is updated).

This does make npm audit complain about a number of vulnerabilities in installed packages, but given this is just within the test suite, I think that's fine. There's also the downside that adding jest does add quite a bit of dependency tree (whereas vows was relatively small), but I think using vitest or mocha would add similar amount of weight to the repo.

I did also have to update the test files names so that the suffix was .test.js instead of -test.js which allows jest to automatically pick up the files without having to modify the testMatch setting.

@MasterOdin MasterOdin marked this pull request as draft March 6, 2025 17:45
@MasterOdin MasterOdin force-pushed the chore-test-suite branch 4 times, most recently from b4a0aef to a4f99ec Compare March 7, 2025 00:14
@MasterOdin MasterOdin marked this pull request as ready for review March 7, 2025 00:23
Signed-off-by: Matthew Peveler <[email protected]>

- name: Update npm
if: matrix.node-version == '6.x'
run: npm install -g npm@^5
Copy link
Contributor Author

Choose a reason for hiding this comment

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

node 6.x installs npm@3 which had issues installing all dependencies of jest. Updating to npm@5 fixes the issue, and didn't think it worth spending time trying to figure out why it wasn't working.

run: npm install --save-dev typescript

- run: node_modules/.bin/tsc --strict lib/portfinder.d.ts
- run: node_modules/.bin/tsc --strict --lib es2015 lib/portfinder.d.ts
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Needed to add --lib es2015 here as some of the dependencies that jest brings in uses es2015 features (e.g. Set, Map, etc.) and without this would get an error. Node 6+ is largely es2015 complete, so not really a compatibility risk.

"types": "./lib/portfinder.d.ts",
"scripts": {
"test": "vows test/*-test.js --spec"
"test": "jest --runInBand"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Jest will try to run the test files in parallel via workers, which breaks the suite given that tests re-use the same ports. Given how quickly it runs (< 1s), I think the lack of parallelization doesn't matter.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Jest does not allow specifying an order for test files to run, and will run them randomly. In testing, I didn't find that it would matter when this particular test would run though.

@eriktrom
Copy link
Member

eriktrom commented Mar 7, 2025

👀 tomorrow am. Thanks again. This should help new people a lot.

Copy link
Member

@eriktrom eriktrom left a comment

Choose a reason for hiding this comment

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

Very good work. Thank you again.

@eriktrom eriktrom merged commit 64b49a5 into http-party:master Mar 7, 2025
23 checks passed
@eriktrom eriktrom mentioned this pull request Mar 7, 2025
@MasterOdin MasterOdin deleted the chore-test-suite branch March 11, 2025 00:06
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.

Replace vows test runner

2 participants