Comments (7)
I just implemented a workaround...which I've had to do a few times for JSDOM now.
In your jest.config you'll need to point the testEnvironment
to local file.
Then you'll need to extends JSDOMEnvironment
and add the node implementation for structuredClone to the JSDOM environment in the constructor.
Something like this:
import JSDOMEnvironment from "jest-environment-jsdom"
export default class FixJSDOMEnvironment extends JSDOMEnvironment {
constructor(...args: ConstructorParameters<typeof JSDOMEnvironment>) {
super(...args)
this.global.structuredClone = structuredClone
}
}
For a real world example, you can see my implementation in my project OMA3.
FixJSDOMEnvironment.ts
jest.config.js
from fakeindexeddb.
Yep, this just broke tests for me (Jest, jsdom, 5.0). Nice workaround though, thanks! Guessing you'll probably get a few more reports of this though.
from fakeindexeddb.
I added the above workarounds to README.md, I think that is good enough to close this issue. Although feel free to comment if you think I'm wrong!
from fakeindexeddb.
Hm I didn't realize that about jsdom. I figured since it's in all the browsers and Node.js, then it'd be everywhere.
Annoying jsdom users is bad. But it's also nice to have no dependencies.
I wonder how many people are using this with jsdom vs without, that would make it more clear what the best decision is. Maybe for now I will leave this issue open and see if other people are affected.
And to save people the trouble of reading the jsdom issue for workarounds, seems that you can just add this above your fake-indexeddb import:
import 'core-js/stable/structured-clone';
from fakeindexeddb.
This broke tests for us
from fakeindexeddb.
By the way this now seems to mean that objects returned are null-prototyped, which I don't think the real IndexedDB objects technically are. No big deal unless (like me!) your isObject code wasn't smart enough to allow those.
from fakeindexeddb.
@jamesgpearce I tried this code:
import realisticStructuredClone from "realistic-structured-clone";
const x = {foo: 5};
const y = Object.create(null);
y.foo = 5;
console.log(Object.getPrototypeOf(x));
console.log(Object.getPrototypeOf(structuredClone(x)));
console.log(Object.getPrototypeOf(realisticStructuredClone(x)));
console.log(Object.getPrototypeOf(y));
console.log(Object.getPrototypeOf(structuredClone(y)));
console.log(Object.getPrototypeOf(realisticStructuredClone(y)));
And got this output:
[Object: null prototype] {}
[Object: null prototype] {}
[Object: null prototype] {}
null
[Object: null prototype] {}
[Object: null prototype] {}
So it seems the old (realisticStructuredClone) and new (structuredClone) are both doing the same thing to the prototype, which actually results in losing the null prototype when cloning.
If you think you're possibly seeing a bug, please create another issue with more info :)
from fakeindexeddb.
Related Issues (20)
- Add observation for Dexie users HOT 3
- [BUG] Context loosing for `FakeDOMStringList` members while wrapping IDB
- [BUG] Invalid behavior for concurrent insertion data HOT 1
- Ref of Observable from liveQuery is not reactive HOT 7
- fake-indexeddb fails when happy-dom is loaded prior to fake-indexeddb HOT 3
- Running this in Chrome throws "Cannot set property indexedDB of #<Window> which has only a getter" HOT 3
- Release new version to npm with latest types fix HOT 3
- DataCloneError: The data being stored could not be cloned by the internal structured cloning algorithm. HOT 2
- Problem storing and retrieving CryptoKeys HOT 2
- `Uint8Array` keys don't respect offsets from underlying ArrayBuffers HOT 3
- Serializing (and restoring) the state of Fake IDB HOT 2
- Unable to use in tests that mock timers (e.g. overriding `globalThis.setImmediate`) HOT 6
- `IDBObjectStore.count` is `O(n^2)` HOT 3
- Try using built-in Node.js Blob HOT 1
- How to read one of the chrome database HOT 1
- A value which is actually Date, but instanceOf Date equals false when use with jest+jsdom. HOT 5
- Index on Date type does not work HOT 7
- File support HOT 2
- Can I use this for a in memory only data view as a prod drop-in replacement? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fakeindexeddb.