Skip to content

Commit db48074

Browse files
committed
Don't try to make WebSocket tests work in two environments
After struggling for a long while with trying to "shim" isomorphic-ws to work normally in a jest environment, it is easier to just run this test only in a Node environment. Here are the issues why this test fails in JSDOM: 1. Imports fail The statement `import WebSocket from 'isomorphic-ws';` is passed to the Jest module resolver, which utilises `ts-jest-resolver` (in our case) to find the right file to load. Sadly, it will always load the "main" module of a node package. 2. isomorphic-ws "browser" option is ESM for some reason If we use jest.config.cjs "resolver" field [1] to define a custom script, we will be able to modify the "main" field by patching package.json in memory. This works fine, however isomorphic-ws's browser version is an ES Module for some reason, even if the package.json > "type" is "commonjs". 3. Something inside jest doesn't want me to hack it to support ESM If I override the package.json even harder to also change the "type" to "module" just for isomorphic-ws, Jest doesn't respect it 4. ts-jest doesn't want to change the ESM imports to CJS imports Since... we told it to not change ESM imports to CJS imports, it will not. [1]: https://jestjs.io/docs/configuration#resolver-string
1 parent a1fc733 commit db48074

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

test/unit/GraphQLSubscriptions.test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
/* eslint-disable no-empty-function */
2+
/**
3+
* @jest-environment node
4+
*/
25

36
import { gql } from 'graphql-tag';
47
import { filter, firstValueFrom, Subscriber } from 'rxjs';

0 commit comments

Comments
 (0)