Skip to content

Commit

Permalink
Merge branch 'main' into dangerously-run-in-production
Browse files Browse the repository at this point in the history
  • Loading branch information
kettanaito committed Nov 21, 2023
2 parents 53b7e2c + 657edd8 commit 6e632b7
Show file tree
Hide file tree
Showing 145 changed files with 2,382 additions and 1,771 deletions.
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/02-issue-nodejs.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: 'Bug report (Node.js)'
description: I experience unexpected behavior using the library in Node.js (Jest/React Native/Express/etc.).
description: I experience unexpected behavior using the library in Node.js (Vitest/React Native/Express/etc.).
labels: ['bug', 'scope:node', 'needs:triage']
body:
- type: markdown
Expand Down
34 changes: 34 additions & 0 deletions .github/workflows/smoke-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: smoke-test

on:
# Always run smoke tests upon a successful
# "ci" job completion on "main".
workflow_run:
workflows: ['ci']
branches: [main]
types: [completed]
workflow_dispatch:

jobs:
examples:
if: ${{ (github.event_name == 'workflow_run' && github.event.workflow_run.conclusion == 'success') || github.event_name == 'workflow_dispatch' }}
runs-on: macos-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: 18

- name: Set up PNPM
uses: pnpm/action-setup@v2
with:
version: 7.12

- name: Install dependencies
run: pnpm install

- name: Test examples
run: ./config/scripts/smoke-test.sh
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,8 @@ stats.html
msw-*.tgz
.husky/_
.env
**/test-results
**/test-results

# Smoke test temporary files.
/package.json.copy
/examples
6 changes: 1 addition & 5 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Hey! Thank you for deciding to contribute to Mock Service Worker! This page will
Getting yourself familiar with the tools below will substantially ease your contribution experience.

- [TypeScript](https://www.typescriptlang.org/)
- [Jest](https://jestjs.io/)
- [Vitest](https://vitest.dev/)
- [Playwright](https://playwright.dev/)

## Dependencies
Expand Down Expand Up @@ -74,8 +74,6 @@ Build the library with the following command:
$ pnpm build
```

[jest-url]: https://jestjs.io

## Tests

### Testing levels
Expand Down Expand Up @@ -215,7 +213,6 @@ Let's replicate the same `GET /books` integration test in Node.js.

```ts
// test/node/example.test.ts
import fetch from 'node-fetch'
import { http, HttpResponse } from 'msw'
import { setupServer } from 'msw/node'

Expand Down Expand Up @@ -269,6 +266,5 @@ $ pnpm build
```

[pnpm-url]: https://pnpm.io/
[jest-url]: https://jestjs.io
[page-with-url]: https://github.com/kettanaito/page-with
[pnpm-install-guide-url]: https://pnpm.io/7.x/installation#installing-a-specific-version
19 changes: 16 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
> [!IMPORTANT]\
> **MSW 2.0 is finally here! 🎉** Read the [Release notes](https://github.com/mswjs/msw/releases/tag/v2.0.0) and please follow the [**Migration guidelines**](https://mswjs.io/docs/migrations/1.x-to-2.x) to upgrade. If you're having any questions while upgrading, please reach out in our [Discord server](https://kettanaito.com/discord).
>
> We've also recorded the most comprehensive introduction to MSW ever. Learn how to mock APIs like a pro in our official video course:
<a href="https://egghead.io/courses/mock-rest-and-graphql-apis-with-mock-service-worker-8d471ece?af=8mci9b" target="_blank">
<img src="media/egghead-banner.png" alt="Mock REST and GraphQL APIs with Mock Service Worker" />
</a>

<br />
<br />

<p align="center">
Expand All @@ -17,13 +23,15 @@
<a href="https://www.npmjs.com/package/msw" target="_blank">
<img src="https://img.shields.io/npm/dm/msw?style=for-the-badge&color=black" alt="Downloads per month" />
</a>
<a href="https://kcd.im/discord" target="_blank">
<a href="https://kettanaito.com/discord" target="_blank">
<img src="https://img.shields.io/badge/chat-online-green?style=for-the-badge&color=black" alt="Discord server" />
</a>
</p>

<br />

<br />

## Features

- **Seamless**. A dedicated layer of requests interception at your disposal. Keep your application's code and tests unaware of whether something is mocked or not.
Expand Down Expand Up @@ -117,7 +125,7 @@ There's no such thing as Service Workers in Node.js. Instead, MSW implements a [

### Usage example

Take a look at the example of an integration test in Jest that uses [React Testing Library](https://github.com/testing-library/react-testing-library) and Mock Service Worker:
Take a look at the example of an integration test in Vitest that uses [React Testing Library](https://github.com/testing-library/react-testing-library) and Mock Service Worker:

```js
// test/Dashboard.test.js
Expand Down Expand Up @@ -205,6 +213,11 @@ Mock Service Worker is trusted by hundreds of thousands of engineers around the
</picture>
</a>
</td>
<td>
<a href="https://www.codacy.com/" target="_blank">
<img src="media/sponsors/codacy.svg" alt="Codacy" height="64" />
</a>
</td>
</tr>
</table>

Expand Down
41 changes: 41 additions & 0 deletions config/scripts/smoke-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/bin/bash
set -e

COMMIT_HASH=$(git rev-parse HEAD)
MSW_VERSION="0.0.0-$COMMIT_HASH"
echo "Latest commit: $COMMIT_HASH"
echo "In-progress MSW version: $MSW_VERSION"

PKG_JSON_COPY="package.json.copy"
cp package.json $PKG_JSON_COPY

pnpm version $MSW_VERSION --no-git-tag-version --allow-same-version

echo ""
echo "Packing MSW..."
pnpm pack

EXAMPLES_REPO=https://github.com/mswjs/examples.git
EXAMPLES_DIR=./examples
echo ""
echo "Cloning the examples from "$EXAMPLES_REPO"..."

if [[ -d "$EXAMPLES_DIR" ]]; then
echo "Examples already cloned, skipping..."
else
git clone $EXAMPLES_REPO $EXAMPLES_DIR
fi

echo ""
echo "Installing dependencies..."
cd $EXAMPLES_DIR
pnpm install

echo ""
echo "Linking MSW..."
pnpm add msw --filter="with-*" file:../../../msw-$MSW_VERSION.tgz
pnpm ls msw

echo ""
echo "Running tests..."
CI=1 pnpm test ; (cd ../ && mv $PKG_JSON_COPY ./package.json)
2 changes: 0 additions & 2 deletions global.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
declare const SERVICE_WORKER_CHECKSUM: string

declare module '@bundled-es-modules/cookie' {
export * as default from 'cookie'
}
Expand Down
13 changes: 0 additions & 13 deletions jest.config.js

This file was deleted.

31 changes: 0 additions & 31 deletions jest.setup.js

This file was deleted.

Binary file added media/egghead-banner.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
45 changes: 45 additions & 0 deletions media/sponsors/codacy.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions media/sponsors/github.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 changes: 10 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "msw",
"version": "2.0.0",
"version": "2.0.8",
"description": "Seamless REST/GraphQL API mocking library for browser and Node.js.",
"main": "./lib/core/index.js",
"module": "./lib/core/index.mjs",
Expand Down Expand Up @@ -46,15 +46,14 @@
"start": "tsup --watch",
"clean": "rimraf ./lib",
"lint": "eslint \"{cli,config,src,test}/**/*.ts\"",
"prebuild": "rimraf ./lib",
"build": "pnpm clean && cross-env NODE_ENV=production tsup && pnpm patch:dts",
"patch:dts": "node \"./config/scripts/patch-ts.js\"",
"check:exports": "node \"./config/scripts/validate-esm.js\"",
"test": "pnpm test:unit && pnpm test:node && pnpm test:browser",
"test:unit": "cross-env BABEL_ENV=test jest --maxWorkers=3",
"test:node": "jest --config=./test/jest.config.js --forceExit",
"test:unit": "vitest",
"test:node": "vitest run --config=./test/node/vitest.config.ts",
"test:browser": "playwright test -c ./test/browser/playwright.config.ts",
"test:modules:node": "jest --config=./test/modules/node/jest.config.js",
"test:modules:node": "vitest run --config=./test/modules/node/vitest.config.ts",
"test:modules:browser": "playwright test -c ./test/modules/browser/playwright.config.ts",
"test:ts": "ts-node test/typings/run.ts",
"prepare": "pnpm simple-git-hooks init",
Expand Down Expand Up @@ -113,21 +112,19 @@
"@bundled-es-modules/cookie": "^2.0.0",
"@bundled-es-modules/js-levenshtein": "^2.0.1",
"@bundled-es-modules/statuses": "^1.0.1",
"@mswjs/cookies": "^1.0.0",
"@mswjs/interceptors": "^0.25.1",
"@mswjs/cookies": "^1.1.0",
"@mswjs/interceptors": "^0.25.11",
"@open-draft/until": "^2.1.0",
"@types/cookie": "^0.4.1",
"@types/js-levenshtein": "^1.1.1",
"@types/statuses": "^2.0.1",
"chalk": "^4.1.2",
"chokidar": "^3.4.2",
"formdata-node": "4.4.1",
"graphql": "^16.8.1",
"headers-polyfill": "^4.0.1",
"inquirer": "^8.2.0",
"is-node-process": "^1.2.0",
"js-levenshtein": "^1.1.6",
"node-fetch": "^2.6.7",
"outvariant": "^1.4.0",
"path-to-regexp": "^6.2.0",
"strict-event-emitter": "^0.5.0",
Expand All @@ -143,18 +140,16 @@
"@ossjs/release": "^0.8.0",
"@playwright/test": "^1.30.0",
"@swc/core": "^1.3.35",
"@swc/jest": "^0.2.24",
"@types/express": "^4.17.17",
"@types/fs-extra": "^9.0.13",
"@types/glob": "^8.1.0",
"@types/jest": "^29.4.0",
"@types/json-bigint": "^1.0.1",
"@types/node": "18.x",
"@types/node-fetch": "^2.5.11",
"@types/puppeteer": "^5.4.4",
"@typescript-eslint/eslint-plugin": "^5.11.0",
"@typescript-eslint/parser": "^5.11.0",
"@web/dev-server": "^0.1.38",
"axios": "^1.6.1",
"babel-loader": "^8.2.3",
"babel-minify": "^0.5.1",
"commitizen": "^4.2.4",
Expand All @@ -170,8 +165,7 @@
"fs-extra": "^10.0.0",
"fs-teardown": "^0.3.0",
"glob": "^9.3.4",
"jest": "^29.4.3",
"jest-environment-jsdom": "^29.4.3",
"jsdom": "^22.1.0",
"json-bigint": "^1.0.0",
"lint-staged": "^13.0.3",
"page-with": "^0.6.1",
Expand All @@ -184,6 +178,8 @@
"typescript": "^5.0.2",
"undici": "^5.20.0",
"url-loader": "^4.1.1",
"vitest": "^0.34.6",
"vitest-environment-miniflare": "^2.14.1",
"webpack": "^5.68.0",
"webpack-dev-server": "^3.11.2",
"webpack-http-server": "^0.5.0"
Expand Down
Loading

0 comments on commit 6e632b7

Please sign in to comment.