Skip to content

tests: remove jest but keep expect - #3295

Open
sir-opti wants to merge 1 commit into
stackernews:masterfrom
sir-opti:test/nojest
Open

sir-opti wants to merge 1 commit into
stackernews:masterfrom
sir-opti:test/nojest

Conversation

@sir-opti

Copy link
Copy Markdown
Contributor

Description

Migrates to node:test to reduce devDependencies significantly while keeping expect for now, to not have to rewrite every test. less jesting, more testing

Changes:

  • uses describe, test and before/after from node:test
  • removes jest as devDependency and its config
  • adds expect=^30.5.2 as direct devDependency (from: 29.7.0)
  • adds scripts/register-alias.mjs to help node resolve the '@' alias in jsconfig.json
  • rewrites mocks to use node:test.mock
  • fixes stray require() in ots-mini tests
  • fixes stray __dirname into import.meta.dirname in ots-mini tests
  • rewrites test.each into a plain for loop in url tests
  • updates sndev to support both help and custom test insertion
  • removes and disables payIn tests as these were fully broken prior to this commit, and warrant a separate change

Additional Context

This removes 102 dependencies, which helps enormously with review pressure when dealing with 3rd party vulns that can only be fixed by bumping jest. We're keeping some of the jest packages due to expect being maintained by the jestjs org since a few years, and, because this is the easiest path for now, to not change every test body.

Dependencies that were bumped instead of removed with the bump of expect:
  • @jest/diff-sequences: none -> 30.5.0
  • @jest/expect-utils: 29.7.0 -> 30.5.2
  • @jest/get-type: none -> 30.5.0
  • @jest/schemas: 29.6.3 -> 30.5.0
  • @jest/types: 29.6.3 -> 30.5.1
  • @sinclair/typebox: 0.27.8 -> 0.34.52
  • @types/yargs: 17.0.32 -> 17.0.35
  • camelcase: 5.3.1 -> 6.3.0
  • ci-info: 3.9.0 -> 4.4.0
  • jest-diff: 29.7.0 -> 30.5.2
  • jest-matcher-utils: 29.7.0 -> 30.5.2
  • jest-message-util: 29.7.0 -> 30.5.1
  • jest-mock: 29.7.0 -> 30.5.2
  • jest-regex-util: 29.6.3 -> 30.5.0
  • jest-util: 29.7.0 -> 30.5.1

NOTE: api/payIn/__tests__/**/*.test.js is completely broken and requires its own PR to not grow this insanely large - it cannot be ran regardless of this PR, since a couple of months. I have disabled both the runner and the tests so that under no circumstance are we triggering these (they were explicitly ignored in ./jest.config.js)

Checklist

Are your changes backward compatible? Please answer below:

The arguments that ./sndev test takes are a breaking change, as they are the nodejs arguments, not the jest cli arguments. If anyone has custom test scripts, these will likely break. I'm open to suggestions as to if anything else is needed than the current bare minimum.

On a scale of 1-10 how well and how have you QA'd this change and any features it might affect? Please answer below:

8/10:

  1. Tested it multiple times through sndev, directly on debian and directly on alpine (.23 and .24), and multiple rounds of bot analysis
  2. Reviewed every dependency that isn't removed for regressions:
    • ci-info triggers terminal behavior based on opaque env variables (like export SOME_CI_ENV_VAR=1) but is not reachable for SN code today
    • jest-matcher-utils has an open behavioral bug, see jestjs/jest#16461, not reachable for SN code today

For frontend changes: Tested on mobile, light and dark mode? Please answer below:

N/A

Did you introduce any new environment variables? If so, call them out explicitly here:

No.

Did you use AI for this? If so, how much did it assist you?

  • scripts/register-alias.mjs was initially bot-written because I was stuck
  • every dependency change has been diffed through a bot to identify hot paths through many layers of transient deps

Migrates to node:test to reduce devDependencies significantly
while keeping expect for now, to not have to rewrite every test.

Changes:

- uses describe, test and before/after from node:test
- removes jest as devDependency and its config
- adds expect=^30.5.2 as direct devDependency (from: 29.7.0)
- adds scripts/register-alias.mjs to help node resolve the '@'
  alias in jsconfig.json
- rewrites mocks to use node:test.mock
- fixes stray require() in ots-mini tests
- fixes stray __dirname into import.meta.dirname in ots-mini tests
- rewrites test.each into a plain for loop in url tests
- updates sndev to support both help and custom test insertion
- removes and disables payIn tests as these were fully broken
  prior to this commit, and warrant a separate change
@socket-security

Copy link
Copy Markdown

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Updatedexpect@​29.7.0 ⏵ 30.5.21001007395 +3100

View full report

@huumn huumn left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You make this stuff look easy!

Comment thread sndev
fi

docker__exec -t -u apprunner app npm run test $args
docker__exec -t -u apprunner app node --import ./scripts/register-alias.mjs --experimental-test-module-mocks --test $args

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit (because we don't have enough tests for this to be relevant and there are similar problems in other commands in this script) but unless we append the glob something like sndev test --test-name-pattern=pollSchema doesn't work because the validation tests end in *.spec.js and node --test does not find it.

@sir-opti sir-opti Oct 18, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

We could just standardize towards what all frameworks accept (.test.js), also since the .spec.js is not consistently there; both ots and the disabled payIn tests are using test.js extensions. It probably would make things easier to just rename the 3 files that use spec; less friction?

I'll see what that does.

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