Skip to content

Commit

Permalink
Merge branch 'main' into feat/ws-sync-handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
kettanaito committed Dec 18, 2024
2 parents e6fac6d + e3234fd commit 9d04f0a
Show file tree
Hide file tree
Showing 17 changed files with 323 additions and 118 deletions.
151 changes: 121 additions & 30 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,49 +7,86 @@ on:
workflow_dispatch:

jobs:
build:
build-18:
name: build (18)
runs-on: macos-latest
strategy:
fail-fast: false
matrix:
node-version: [18, 20]
steps:
- name: Checkout
uses: actions/checkout@v4

- uses: pnpm/action-setup@v4
- name: Set up pnpm
uses: pnpm/action-setup@v4
with:
version: 9.14.0

- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
node-version: 18
cache: 'pnpm'

- name: Install dependencies
run: pnpm install

- name: Lint
run: pnpm lint

- name: Build
run: pnpm build

- name: Cache build output
uses: actions/cache@v4
with:
path: ./lib
key: ${{ runner.os }}-node-${{ matrix.node-version }}-build-${{ github.sha }}
key: ${{ runner.os }}-node-18-build-${{ github.sha }}
restore-keys: |
${{ runner.os }}-build-${{ matrix.node-version }}
${{ runner.os }}-build-18
test_unit:
name: test (unit)
needs: build
build-20:
name: build (20)
runs-on: macos-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- uses: pnpm/action-setup@v4
- name: Set up pnpm
uses: pnpm/action-setup@v4
with:
version: 9.14.0

- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 20
cache: 'pnpm'

- name: Install dependencies
run: pnpm install

- name: Lint
run: pnpm lint

- name: Build
run: pnpm build

- name: Cache build output
uses: actions/cache@v4
with:
path: ./lib
key: ${{ runner.os }}-node-20-build-${{ github.sha }}
restore-keys: |
${{ runner.os }}-build-20
test-unit-18:
name: test (unit) (18)
needs: build-18
runs-on: macos-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Set up pnpm
uses: pnpm/action-setup@v4
with:
version: 9.14.0

Expand All @@ -73,39 +110,33 @@ jobs:
- name: Install Playwright browsers
run: pnpm exec playwright install

- name: Lint
run: pnpm lint

- name: Unit tests
run: pnpm test:unit

test-node:
name: test (node.js)
needs: build
test-node-18:
name: test (node.js) (18)
needs: build-18
runs-on: macos-latest
strategy:
fail-fast: false
matrix:
node-version: [18, 20]
steps:
- name: Checkout
uses: actions/checkout@v4

- uses: pnpm/action-setup@v4
- name: Set up pnpm
uses: pnpm/action-setup@v4
with:
version: 9.14.0

- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
node-version: 18
cache: 'pnpm'

- name: Restore build cache
uses: actions/cache@v4
with:
path: ./lib
key: ${{ runner.os }}-node-${{ matrix.node-version }}-build-${{ github.sha }}
key: ${{ runner.os }}-node-18-build-${{ github.sha }}
restore-keys: |
${{ runner.os }}-node-18-build-
Expand All @@ -115,15 +146,74 @@ jobs:
- name: Node.js tests
run: pnpm test:node

test-node-20:
name: test (node.js) (20)
needs: build-20
runs-on: macos-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Set up pnpm
uses: pnpm/action-setup@v4
with:
version: 9.14.0

- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 20
cache: 'pnpm'

- name: Restore build cache
uses: actions/cache@v4
with:
path: ./lib
key: ${{ runner.os }}-node-20-build-${{ github.sha }}
restore-keys: |
${{ runner.os }}-node-20-build-
- name: Install dependencies
run: pnpm install

- name: Node.js tests
run: pnpm test:node

test-e2e:
name: test (e2e) (18)
needs: build-18
runs-on: macos-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Set up pnpm
uses: pnpm/action-setup@v4
with:
version: 9.14.0

- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 18
cache: 'pnpm'

- name: Install dependencies
run: pnpm install

- name: E2E tests
run: pnpm test:e2e

test-browser:
name: test (browser)
needs: build
needs: build-18
runs-on: macos-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- uses: pnpm/action-setup@v4
- name: Set up pnpm
uses: pnpm/action-setup@v4
with:
version: 9.14.0

Expand Down Expand Up @@ -159,13 +249,14 @@ jobs:

test-native:
name: test (react-native)
needs: build
needs: build-18
runs-on: macos-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- uses: pnpm/action-setup@v4
- name: Set up pnpm
uses: pnpm/action-setup@v4
with:
version: 9.14.0

Expand Down
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v18.19.0
v18
18 changes: 9 additions & 9 deletions cli/init.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const fs = require('fs')
const path = require('path')
const chalk = require('chalk')
const colors = require('picocolors')
const confirm = require('@inquirer/confirm').default
const invariant = require('./invariant')
const { SERVICE_WORKER_BUILD_PATH } = require('../config/constants')
Expand Down Expand Up @@ -34,7 +34,7 @@ module.exports = async function init(args) {
// will equal to false.
else if (args.save == null) {
console.log(`\
${chalk.cyan(
${colors.cyan(
'INFO',
)} In order to ease the future updates to the worker script,
we recommend saving the path to the worker directory in your package.json.`)
Expand Down Expand Up @@ -141,20 +141,20 @@ async function copyWorkerScript(destination, cwd) {
*/
function printSuccessMessage(paths) {
console.log(`
${chalk.green('Worker script successfully copied!')}
${paths.map((path) => chalk.gray(` - ${path}\n`))}
${colors.green('Worker script successfully copied!')}
${paths.map((path) => colors.gray(` - ${path}\n`))}
Continue by describing the network in your application:
${chalk.cyan.bold('https://mswjs.io/docs/getting-started')}
${colors.red(colors.bold('https://mswjs.io/docs/getting-started'))}
`)
}

function printFailureMessage(pathsWithErrors) {
console.error(`\
${chalk.red('Copying the worker script failed at following paths:')}
${colors.red('Copying the worker script failed at following paths:')}
${pathsWithErrors
.map(([path, error]) => chalk.gray(` - ${path}`) + '\n' + ` ${error}`)
.map(([path, error]) => colors.gray(` - ${path}`) + '\n' + ` ${error}`)
.join('\n\n')}
`)
}
Expand All @@ -167,7 +167,7 @@ function saveWorkerDirectory(packageJsonPath, publicDir) {
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'))

console.log(
chalk.gray('Updating "msw.workerDirectory" at "%s"...'),
colors.gray('Updating "msw.workerDirectory" at "%s"...'),
packageJsonPath,
)

Expand Down Expand Up @@ -200,7 +200,7 @@ function saveWorkerDirectory(packageJsonPath, publicDir) {
function promptWorkerDirectoryUpdate(message, packageJsonPath, publicDir) {
return confirm({
theme: {
prefix: chalk.yellowBright('?'),
prefix: colors.yellowBright('?'),
},
message,
}).then((answer) => {
Expand Down
4 changes: 2 additions & 2 deletions cli/invariant.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const chalk = require('chalk')
const colors = require('picocolors')

module.exports = function invariant(predicate, message, ...args) {
if (!predicate) {
console.error(chalk.red(message), ...args)
console.error(colors.red(message), ...args)
process.exit(1)
}
}
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "msw",
"version": "2.6.8",
"version": "2.7.0",
"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 @@ -82,11 +82,12 @@
"check:exports": "node \"./config/scripts/validate-esm.js\"",
"test": "pnpm test:unit && pnpm test:node && pnpm test:browser && pnpm test:native",
"test:unit": "vitest",
"test:node": "vitest run --config=./test/node/vitest.config.mts",
"test:node": "vitest --config=./test/node/vitest.config.mts",
"test:native": "vitest --config=./test/native/vitest.config.mts",
"test:browser": "playwright test -c ./test/browser/playwright.config.ts",
"test:modules:node": "vitest --config=./test/modules/node/vitest.config.mts",
"test:modules:browser": "playwright test -c ./test/modules/browser/playwright.config.ts",
"test:e2e": "vitest run --config=./test/e2e/vitest.config.mts",
"test:ts": "vitest --typecheck --config=./test/typings/vitest.config.mts",
"prepare": "pnpm simple-git-hooks init",
"prepack": "pnpm build",
Expand Down Expand Up @@ -148,12 +149,12 @@
"@open-draft/until": "^2.1.0",
"@types/cookie": "^0.6.0",
"@types/statuses": "^2.0.4",
"chalk": "^4.1.2",
"graphql": "^16.8.1",
"headers-polyfill": "^4.0.2",
"is-node-process": "^1.2.0",
"outvariant": "^1.4.3",
"path-to-regexp": "^6.3.0",
"picocolors": "^1.1.1",
"strict-event-emitter": "^0.5.1",
"type-fest": "^4.26.1",
"yargs": "^17.7.2"
Expand Down
Loading

0 comments on commit 9d04f0a

Please sign in to comment.