JsStore + Vite + Jest or Vitest #325
-
Hello, first of all - thanks for this great library. Currently i'm about switching from CRA scripts to Vite. Everything runs fine if client started
while trying to create a new export const connection: Connection = new Connection(
/test/i.test(NODE_ENV) ? undefined : new Worker('/jsstore.worker.js'),
); I also use Did anyone have this problem? (Works fine with CRA)
export default {
watchPathIgnorePatterns: [
'.*e2e\\.test\\.[t|j]s(x)*$',
],
transform: {
'^.+\\.ts?$': 'ts-jest',
'^.+\\.(js|jsx)$': 'babel-jest',
},
transformIgnorePatterns: [],
};
{
"compilerOptions": {
"target": "ESNext",
"lib": [
"dom",
"dom.iterable",
"ESNext",
"WebWorker"
],
"types": ["vite/client", "vite-plugin-svgr/client", "node"],
"allowJs": true,
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"noFallthroughCasesInSwitch": true,
"module": "ESNext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"noEmit": true,
"downlevelIteration": true,
"jsx": "react-jsx",
"strictPropertyInitialization": true
},
"include": [
"src",
"public/jsstore.worker.js",
"src/sqlite.wasm.worker.ts"
]
}
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
OK, got a solution If anyone faces this problem: First install /* eslint-disable import/no-extraneous-dependencies */
import 'fake-indexeddb/auto';
import 'jsdom-global/register';
// @ts-ignore
global.self = global; and finally add to your jest configs: ...
setupFilesAfterEnv: [
'./jest.setup.ts',
],
... |
Beta Was this translation helpful? Give feedback.
OK, got a solution
If anyone faces this problem:
First install
jest-worker
, e.g.npm i -D jest-worker
Then add a jest setup file, e.g.
jest.setup.ts
with the following content:and finally add to your jest configs: