Replies: 4 comments 6 replies
-
I don't know Jest so I'm not sure this is the correct answer. It looks like you have to use See here for more info: jestjs/jest#11753 Edit: Otherwise importing |
Beta Was this translation helpful? Give feedback.
-
Looks like adding
Sample repo is updated with config change. I also tried importing |
Beta Was this translation helpful? Give feedback.
-
If I import Other than the obviuos, if we update and you rearrange files in the project, do you se any issues in that import? I should note, that even though i didn't disable web workers in the sample project, I have done so in our real project, and we only need to do unzipping in our project. |
Beta Was this translation helpful? Give feedback.
-
I was able to go a bit further (I guess?) by following the procedure described here: https://jestjs.io/docs/ecmascript-modules Here is my {
"name": "zipjs-sample",
"version": "0.1.0",
"private": true,
"type": "module",
"dependencies": {
"@testing-library/jest-dom": "^5.16.3",
"@testing-library/react": "^12.1.4",
"@testing-library/user-event": "^13.5.0",
"@zip.js/zip.js": "^2.4.7",
"react": "^18.0.0",
"react-dom": "^18.0.0",
"react-scripts": "5.0.0",
"web-vitals": "^2.1.4"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "node --experimental-vm-modules node_modules/.bin/jest",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
},
"jest": {
"transform": {}
},
"devDependencies": {
"jest": "^27.5.1"
}
} Now Jest can run the tests (but they fail). |
Beta Was this translation helpful? Give feedback.
-
Hi,
I have a project created with Create-React-App (CRA) in which I am trying to implement an unzip function.
I have gotten the unzip code itself to work, however I've got problems with getting it to work simultaneously in my Jest unit tests and in the browser. The issue is with the import of zip.js, I can't seem to find a way to import, that works simultaneously i both scenarios.
If I import it as written in the documentation,
I can get it to work in the browser, but it won't run in my unit tests with the following error:
If I import the build version from the
dist
-folder like this:It works in my tests, but then It get the following error in the browser:
I have made a small sample project. If you clone it and run
npm start
andnpm test
, it will work in the browser, but the tests will fail. If you then swap in the commented out imports in the files within thesrc/zip
, it will work in the unit tests, but not in the browser. For testing in the browser, just upload a random zip file, ie. the one located insrc/zip
, and the page will show you its contents.Can anyone point me in the direction of an import or a configuration change, that will work in both scenarios? 🙏
Beta Was this translation helpful? Give feedback.
All reactions