Skip to content

Migrate Jest test setup from CommonJS to ESM - #1977

Open
LanieOkorodudu wants to merge 2 commits into
UniversalViewer:devfrom
LanieOkorodudu:migrate-commonJS-to-esm
Open

LanieOkorodudu wants to merge 2 commits into
UniversalViewer:devfrom
LanieOkorodudu:migrate-commonJS-to-esm

Conversation

@LanieOkorodudu

Copy link
Copy Markdown
Contributor

Pull request description

This PR migrates the Jest test setup and Puppeteer tests from CommonJS to ESM.
Following the Puppeteer 25 upgrade, the tests were using a mixture of CommonJS and dynamic ESM imports. The aim of this migration was to remove the need for --experimental-vm-modules and make the test setup more consistent.
However, after further investigation, Jest 30 still requires --experimental-vm-modules to run native ESM tests, so the flag has been retained for now.
This is a draft PR to gather feedback from the team on whether the ESM conversion makes sense.

Summary of changes

  • Updated the AV, configuration, image, PDF, 3D model and dev server tests to use ESM.
  • Replaced the CommonJS require() statements and dynamic Puppeteer imports with ESM import statements.
  • Updated jest.globalSetup.js and jest.globalTeardown.js to use ESM.
  • Updated the shared test helpers, testBaseUrl.js and testViewer.js, to use ESM imports and exports.
  • Kept the existing test logic and assertions unchanged

Related issues

#1899

Contributor checklist

Accessibility & internationalisation

  • Accessibility: Changes have been checked against WCAG 2.2 Level AA, with no known accessibility failures introduced.
  • Keyboard accessibility: All new or modified interactive elements can be operated using a keyboard, with appropriate focus management and visible focus indicators.
  • Internationalisation: Contextual language switching works correctly and all new or modified interface strings have translations available in English, Welsh, Polish, French and Swedish.

Compatibility & interoperability

  • IIIF compatibility: Changes have been tested against relevant IIIF Presentation and Image API resources, with no known regressions in supported functionality.
  • Extension compatibility: Changes have been checked for compatibility with existing Universal Viewer extensions and extension points.
  • Backwards compatibility: Changes do not unintentionally break existing public APIs, integrations or configuration options.
  • Browser & device compatibility: Changes have been tested across relevant supported browsers, devices and screen sizes, including responsive layouts.

Code quality & testing

  • Automated testing: Relevant automated tests have been added or updated, and existing applicable tests pass.
  • Regression testing: Existing functionality affected by the changes has been tested to ensure no unintended regressions.
  • Code quality: Changes follow the project's coding conventions, and relevant linting, formatting and type checks pass.
  • Performance: Changes have been reviewed for potential performance impacts, with no known significant regressions.
  • Security: Changes have been checked for potential security vulnerabilities, including unsafe handling of external data, URLs and user input.

Configuration & documentation

  • Configuration: New or modified configuration options have been added to the appropriate configuration files and documented in 'manual/CONFIG.md`.
  • Documentation: The repository README and any other affected documentation have been reviewed and updated where necessary.
  • User experience: Changes have been reviewed for usability, consistency with existing interface patterns and clarity of user interactions.

Additional notes for reviewers:

The tests are passing on my local machine, but they're still failing in CI. I'm wondering if this might be because I'm using Node 24 locally, while CI runs on Node 22.
I'll look into this a bit more and see what's causing the failures.

@vercel

vercel Bot commented Nov 23, 2026

Copy link
Copy Markdown

@LanieOkorodudu is attempting to deploy a commit to the Universal Viewer Team on Vercel.

A member of the Team first needs to authorize it.

@vercel

vercel Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
universalviewer Ready Ready Preview Nov 24, 2026 10:33am UTC

Request Review

@demiankatz

Copy link
Copy Markdown
Contributor

Thanks, @LanieOkorodudu, this definitely is a bit more readable overall. I see some things aren't working yet; please let me know if you need any help with anything!

@LanieOkorodudu

Copy link
Copy Markdown
Contributor Author

I've added a package.json with "type: "module" inside the tests folder because Jest wasn't recognising the converted .js test files as ESM when running on Node 22 in CI. This allows the tests to use ESM without changing the root package.json, which could affect other parts of Universal Viewer that still use CommonJS. I've also converted the remaining Jest test files to ESM so they're consistent with this setup.

@demiankatz demiankatz left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks, @LanieOkorodudu, this all makes sense to me, and tests are passing... so the only remaining question is when we want to take it out of draft and merge it. Maybe a topic for a future Community Call. I'll put this on the community board "in testing" so we don't forget about it.

@LanieOkorodudu

LanieOkorodudu commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor Author

Thanks, @LanieOkorodudu, this all makes sense to me, and tests are passing... so the only remaining question is when we want to take it out of draft and merge it. Maybe a topic for a future Community Call. I'll put this on the community board "in testing" so we don't forget about it.

I can remove it from draft for now and wait for community call to discuss it if we want to merge it, I also requested @K8Sewell to review it as well. Thanks for your time looking into this @demiankatz

@LanieOkorodudu
LanieOkorodudu marked this pull request as ready for review November 24, 2026 13:31

This branch was successfully deployed

1 active deployment
Preview – universalviewer β€” b6dd4cd1 Deployed Nov 24, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: In testing

Development

Successfully merging this pull request may close these issues.

2 participants