Giter VIP home page Giter VIP logo

msw-with-remix-example's Introduction

Remix + MSW

This repository introduces cases of integration between Remix v2 and MSW, contrasting with the original examples based on Remix v1 from mswjs/examples.

Mock Service Worker usage example with Remix.

Edit in CodeSandbox

General

Create ./mocks under ./app

Remix automatically watches the ./app directory for changes. If you want for your changes to API mocks to be picked up by Remix's dev server, place the ./mocks directory in the ./app.

mkdir ./app/mocks

If you don't wish or otherwise can't do this, modify remix.config.js appropriately to also watch the directory with your mocks.

Client-side integration

1. Copy the worker script

npx msw init ./public

2. Set up browser integration

touch mocks/browser.ts

See mocks/browser.ts module for reference.

3. Defer application rendering

  • entry.client.tsx create a prepareApp and defer the rendering.
  • tsconfig.json set the module to esnext to support dynamic import() statements.

Server-side integration

1. Set up server-side integration

touch mocks/node.ts

Unlike regular Node.js integrations, we will have to write a bit of custom setup logic so that Remix could digest the changes we make to our handlers while developing the app.

2. Enable mocking

In entry.server.tsx, import the handlers.ts and enable mocking by calling server.listen() from the node.ts setup.

msw-with-remix-example's People

Contributors

radiantbeing avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.