freshollie / jest-dynalite

Jest preset to run Dynalite (DynamoDB local) per test runner
https://www.npmjs.com/package/jest-dynalite
MIT License
151 stars 16 forks source link

setImmediate is not defined using jsdom and advanced setup #68

Closed Kullersj closed 3 years ago

Kullersj commented 3 years ago

Hi, I recently upgraded to jest 27 and am running into some issues setting up my tests.

Seems that this issue is similar to #54

I have a jest.setupBeforeEnv.js file containing

import { setup } from 'jest-dynalite';

setup(__dirname);

I also have a jest.setupAfterEnv.js containing

import 'jest-dynalite/withDb';

And finally my config has

testEnvironment: "jsdom",
setupFiles: ['./jest.setupBeforeEnv.js'],
setupFilesAfterEnv: ['./jest.setupAfterEnv.js'],

When tests run I immediately get this error

Test suite failed to run

ReferenceError: setImmediate is not defined

1 | import { setup } from 'jest-dynalite';
2 |
> 3 | setup(__dirname);
  |                     ^

at Object.<anonymous> (../../node_modules/.pnpm/memdown@5.1.0/node_modules/memdown/immediate.js:1:100)
at Object.<anonymous> (../../node_modules/.pnpm/memdown@5.1.0/node_modules/memdown/memdown.js:10:20)
at Object.<anonymous> (../../node_modules/.pnpm/dynalite@3.2.1/node_modules/dynalite/db/index.js:6:15)
at Object.<anonymous> (../../node_modules/.pnpm/dynalite@3.2.1/node_modules/dynalite/validations/index.js:2:10)
at Object.<anonymous> (../../node_modules/.pnpm/dynalite@3.2.1/node_modules/dynalite/index.js:8:19)
at Object.<anonymous> (jest.setupBeforeEnv.js:3:21)

I had no issues when I was using jest 26

Package Versions:

"aws-sdk": "^2.998.0",
"@testing-library/jest-dom": "^5.14.1",
"@testing-library/react": "^12.1.0",
"@testing-library/user-event": "^13.2.1",
"jest": "^27.2.1",
"jest-css-modules": "^2.1.0",
"jest-docblock": "^27.0.6",
"jest-dynalite": "^3.4.1",
"jest-emotion": "^11.0.0",
"jest-fetch-mock": "^3.0.3",
"jest-junit": "^12.3.0",

Using Node 14.17.1

Appreciate any help

freshollie commented 3 years ago

Thanks for reporting! Looks like jest removed setImmediate for DOM testing environments recently: https://github.com/facebook/jest/pull/11222

dynalite doesn't use the latest version of memdown which doesn't depend on setImmidiate so it might be that the only option is to patch setImmidate before importing dynalite? :/

freshollie commented 3 years ago

Is your testing environment set to js-dom? https://jestjs.io/docs/configuration#testenvironment-string, can you try using Node instead?

freshollie commented 3 years ago

Ok. Going to use a polyfill. PR incoming.

freshollie commented 3 years ago

Just pushed to master, but this was the solution https://github.com/freshollie/jest-dynalite/commit/043acba41892f20425c94d4ec4f1c8c40f7562e0

Kullersj commented 3 years ago

Thanks so much for the fast help! Patiently waiting on the next published version to use the update 😄

freshollie commented 3 years ago

Nice! Should be release as v3.4.2 very soon!

freshollie commented 3 years ago

This should now be released