Skip to content

Commit ee8a888

Browse files
committed
Drop usage of MSW in unit tests (internal-2014)
1 parent e3bc83d commit ee8a888

19 files changed

+746
-1376
lines changed

package-lock.json

-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@
8989
"mapbox-gl-styles": "^2.0.2",
9090
"minimist": "^1.2.6",
9191
"mock-geolocation": "^1.0.11",
92-
"msw": "^2.3.1",
9392
"node-notifier": "^10.0.1",
9493
"npm-font-open-sans": "^1.1.0",
9594
"npm-run-all": "^4.1.5",

test/README.md

+1-30
Original file line numberDiff line numberDiff line change
@@ -33,36 +33,7 @@ See [`test/integration/README.md`](./integration/README.md).
3333
- **You should not mock any internal domain objects.** Internal domain objects include `Style`, `Map`, `Transform`, and `Dispatcher`. If this is difficult because of some interface, refactor that interface. This ensures that tests accurately exercise the code paths used in production.
3434
- **You should test one return value or side effect per test case.** Feel free to pull shared logic into a function. This ensures that tests are easy to understand and modify.
3535
- **You should only test the return values and global side effects of methods.** You should not not test internal behavior, such as that another method is called with particular arguments. This ensures that method implementations may change without causing test failures.
36-
- **You must not make network requests in test cases.** This rule holds in cases when result isn't used or is expected to fail. You may use `getNetworkWorker` from `test/util/network.js` module, which uses [`mswj`](https://mswjs.io/docs/api/setup-worker/) to simulate network requests. This ensures that tests are reliable, able to be run in an isolated environment, and performant. In your test suite you can setup network worker in the following way:
37-
```js
38-
let networkWorker;
39-
40-
beforeAll(async () => {
41-
networkWorker = await getNetworkWorker(window);
42-
});
43-
44-
afterEach(() => {
45-
// Clear runtime mocks, which were added by `.use`
46-
networkWorker.resetHandlers();
47-
});
48-
49-
afterAll(() => {
50-
networkWorker.stop();
51-
});
52-
53-
test('should tests something', () => {
54-
networkWorker.use(
55-
http.get('/notfound.png', async () => {
56-
return new HttpResponse(null, {status: 404});
57-
}),
58-
http.get('/style.json', async () => {
59-
return HttpResponse.json({});
60-
})
61-
);
62-
63-
// Network mocks are ready: act and assert
64-
});
65-
```
36+
- **You must not make network requests in test cases.** This rule holds in cases when result isn't used or is expected to fail. You may use `mockFetch` from `test/util/network.js` module to mock requests if you need though. This ensures that tests are reliable, able to be run in an isolated environment, and performant
6637
- **You should use clear [input space partitioning](http://crystal.uta.edu/~ylei/cse4321/data/isp.pdf) schemes.** Look for edge cases! This ensures that tests suites are comprehensive and easy to understand.
6738

6839
If you want to debug your unit tests you can open UI for that with the following command:

test/unit/mock-worker/mockServiceWorker.js

-295
This file was deleted.

0 commit comments

Comments
 (0)