Upgrading Node.js from version 14 to version 18 in a Gatsby application can introduce several changes and potential issues, especially if your codebase and dependencies rely on specific Node.js versions or if there have been breaking changes in Node.js itself. When tests pass locally but fail in a production environment, it can be challenging to diagnose the issue because there are differences between the two environments.
The error seems to be originating from jsdom module, which could be caused by your test setup if it’s calling window.close().
A simple jest.spyOn(window, "close").mockImplementation(jest.fn()); in the test setup could possibly fix the issue.
Also, you may want to check if jsdom dependencies are up to date.