Comments (18)
Starting from 0.11.0
, MSW will validate the Service Worker’s integrity on runtime to ensure that mockServiceWorker.js
file stays up-to-date.
This is necessary since the user is responsible for serving the Service Worker file, and it can get out of sync with the library’s logic, if the file is stale. To prevent extra actions from the user's side, we've introduced an algorithm that would invalidate the Service Worker only when its code has changed.
Please, if you are using MSW prior to 0.11.0
, when updated to that version your Service Worker’s integrity check will fail. You will see the error message in the browser’s console with the instructions on how to resolve it. Keep in mind that MSW does not enable mocking with Service Workers that don’t pass the integrity check.
@kentcdodds, I know you are an active user of MSW so I wanted to ping you directly regarding these changes. Sorry for possible inconvenience, I hope the update goes smoothly for you, as this is a crucial change for the library’s future. Thanks.
from msw.
Also, I think there may be a bug with 0.11.0. I don't think it's initializing the msw service worker anymore.
from msw.
Oh, I was confused. So it's not likely that there would be a problem because that file doesn't get updates very often.
I think that's ok. Sorry for my misunderstanding, thank you for taking the time to explain it to me.
from msw.
Excellent. Thank you!
from msw.
I just updated and I haven't gotten any console warnings yet. But I tried running npx msw init public
anyway and here's what I got:
$ npx msw init public
Cannot find module '../config/constants'
Require stack:
- /Users/kentcdodds/code/bookshelf/node_modules/msw/cli/init.js
- /Users/kentcdodds/code/bookshelf/node_modules/msw/cli/msw.js
from msw.
@kentcdodds, Thanks for getting back with this. Now I see I haven't whitelisted the config/
directory to be published, while client-side code relies on it. The fix should be published now, could you please update and let me know?
from msw.
I'm getting an integrity check failure even though I did re-init...
from msw.
Honestly, I see this integrity check as adding unnecessary complexity. I'd rather opt-into it.
from msw.
I just verified that the checksum that was created for me was different from the one that's inside msw... Not sure how that happened.
Correct me if I'm wrong, but this checksum basically means that every time I update msw, I'll need to update the service worker? That would be a pretty annoying workflow...
from msw.
@kentcdodds sorry to hear that. It mat look like a redundant step, but once we get it right it’ll be worth it. Your feedback is helpful and I’ll look into the issue you’re experiencing.
The integrity checksum is generated upon build before publishing the package. No matter what you do with MSW workflow, it must never change. You can see it in the mockServiceWorker.js
file source, but you shouldn’t edit the Service Worker directly (regardless, the checksum is not re-generated during the usage).
The latest release should contain the integrity 5f3682de8784af08f53b896cdfc3fb42
. Could you please verify this is the checksum you have in the mockServiceWorker.js
when it's copied via npx msw init
? I'll do so myself on a clean project to check.
from msw.
I understand that, but I really don't think it's worth the impact to everyone's workflow. Doing this would basically mean every time you upgrade packages you have to rerun the init. That would be super annoying. Totally not worth it. Please consider an opt-out at least.
from msw.
This basically protects me from myself by making me do extra work. But if I have the discipline to not change that file myself then I don't want to do the extra work.
from msw.
@kentcdodds the way checksum is generated is so it only updates if mockServiceWorker.js
changes on the library's side. So if between release A and release B there were no changes introduced by the library, you can safely keep using the Service Worker you have registered. For that, the checksum is derived from the minified and comment-free Service Worker file, to prevent false integrity bumps.
I'm not pushing for this kind of check and I'm open to discuss an alternative to keep the Service Worker and the library's logic in sync. I think what you are experiencing right now is a hiccup to get this check rolled out. I plan to make the process as painless as possible for the developer, so no extra actions are necessary, if there is no reason for it. Your feedback also helps a lot, and I'm once more sorry for the painful initial experience. Hope to polish this functionality to its best.
I've bumped the version and see the integrity check pass on 0.11.2
. The checksum published in the previous release was corrupted. I hope this won't happen again.
from msw.
Perhaps, as a middle-ground the integrity assertion failure could still allow SW to mock responses. I'd consider such behavior as opt-in.
from msw.
It’s perfectly fine. I’m glad I was able to explain it better :)
Please, does 0.11.2
fixes the integrity issue for you?
from msw.
It does fix the integrity warning, but the service worker is no longer handling requests. I'm afraid I don't have time to investigate why, but if you want to try it out feel free: https://github.com/kentcdodds/bookshelf
from msw.
@kentcdodds, thanks for reporting the status. I'll take a look in the nearest time.
from msw.
@kentcdodds, I've addressed the issue in kentcdodds/bookshelf#26. It turned out that your application didn't have the latest msw
version installed, which caused the integrity check failure. I'm not entirely sure why 0.10.0
prompted you to perform an integrity check in the first place, as the integrity check has been introduced in version 0.11.0
. I still suspect the upper caret range quirks that took place and resulted in that issue.
Could you please take a look at the pull request? Thanks.
from msw.
Related Issues (20)
- Mock a request that contains both query and path parameters
- TypeError: confirm is not a function HOT 7
- Failing to intercept an Axios request: Node 20.11 + Vitest 1.3.1 + MSW 2.2.1
- v2.2.2 does not intercept request in browser mode (CORS error) but v1.3.1 does HOT 3
- Infering the `boundary` callback arguments HOT 7
- support custom fetch option HOT 7
- support selecting interceptors HOT 1
- Set-Cookie responses containing commas are not handled correctly HOT 1
- HttpResponse.json() throwing TypeError: Right-hand side of 'instanceof' is not an object. HOT 1
- Request with FormData body makes Jest hang forever HOT 6
- TypeError: Right-hand side of 'instanceof' is not an object HOT 4
- Cannot read properties of undefined (reading 'url') HOT 5
- Mocked data getting empty string HOT 8
- "InvalidStateError: The object is in invalid state" when mocking rest api
- Unable to use msw/node for testing solid-js due to `resolve.conditions` set to `browser` HOT 5
- drop CommonJS support HOT 2
- quiet: true should supress RESPONSE LISTENER logs HOT 4
- Narrowing the response body type in `HttpResponse.json` HOT 16
- Error: No known conditions for "./browser" specifier in "msw" package HOT 2
- "Cannot read properties of undefined (reading 'get')" when using generators/async generators as resolvers 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 msw.