Skip to content

Commit

Permalink
use tsup for building, migrate to vite, add default handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
yannbf committed May 3, 2023
1 parent d18629c commit fc53085
Show file tree
Hide file tree
Showing 16 changed files with 1,051 additions and 663 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/demo-tests.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: 'Tests for Demos'
on: push
jobs:
jest:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
Expand All @@ -10,4 +10,4 @@ jobs:
- name: Build addon
run: yarn workspace msw-storybook-addon build
- name: Test Demos
run: yarn workspace msw-storybook-docs test --colors
run: yarn workspace msw-storybook-docs test
3 changes: 1 addition & 2 deletions packages/docs/.storybook/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ const config = {
'@storybook/addon-links',
'@storybook/addon-essentials',
'@storybook/addon-a11y',
'@storybook/preset-create-react-app',
'@storybook/addon-storysource',
],
staticDirs: ['../public'],
Expand All @@ -20,7 +19,7 @@ const config = {
return config
},
framework: {
name: '@storybook/react-webpack5',
name: '@storybook/react-vite',
options: {},
},
docs: {
Expand Down
12 changes: 12 additions & 0 deletions packages/docs/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>MSW Example</title>
</head>
<body>
<div id="root"></div>
</body>
</html>
32 changes: 16 additions & 16 deletions packages/docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
"version": "0.1.0",
"private": true,
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject",
"dev": "vite",
"build": "tsc && vite build",
"preview": "vite preview",
"test": "vitest run",
"test:watch": "vitest watch",
"storybook": "storybook dev -p 6006",
"storybook-build": "storybook build",
"msw:update": "msw init public"
Expand Down Expand Up @@ -41,34 +42,33 @@
},
"dependencies": {
"@apollo/client": "^3.3.6",
"@testing-library/jest-dom": "^5.11.4",
"@testing-library/react": "^11.1.0",
"@testing-library/user-event": "^12.1.10",
"axios": "^0.21.1",
"graphql": "^15.4.0",
"react": "^17.0.1",
"react-dom": "^17.0.1",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-query": "^3.5.5",
"react-router": "^5.2.0",
"react-router-dom": "^5.2.0",
"react-scripts": "^5.0.1",
"urql": "^1.11.4",
"web-vitals": "^0.2.4"
"urql": "^1.11.4"
},
"devDependencies": {
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^14.0.0",
"@testing-library/user-event": "^14.4.3",
"@storybook/addon-a11y": "^7.0.7",
"@storybook/addon-actions": "^7.0.7",
"@storybook/addon-essentials": "^7.0.7",
"@storybook/addon-links": "^7.0.7",
"@storybook/addon-storysource": "^7.0.7",
"@storybook/node-logger": "^7.0.7",
"@storybook/preset-create-react-app": "^7.0.7",
"@storybook/react": "^7.0.7",
"@storybook/react-webpack5": "^7.0.7",
"@storybook/react-vite": "^7.0.7",
"chromatic": "^5.5.0",
"msw": "^1.2.1",
"jsdom": "^21.1.0",
"storybook": "^7.0.7",
"webpack": "5"
"typescript": "^4.9.3",
"vite": "^4.1.0",
"vitest": "^0.29.2"
},
"msw": {
"workerDirectory": "public"
Expand Down
5 changes: 5 additions & 0 deletions packages/docs/src/demos/apollo/App.test.jsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
import React from 'react'
import { render, screen } from '@testing-library/react'
import { composeStories } from '@storybook/react'
import { vi } from 'vitest'

import { getServer } from '../../test-utils'
import * as stories from './App.stories'

const { MockedSuccess, MockedError } = composeStories(stories)
const server = getServer()

afterAll(() => {
vi.restoreAllMocks()
})

it('renders film cards for each film', async () => {
server.use(...MockedSuccess.parameters.msw.handlers)
render(<MockedSuccess />)
Expand Down
47 changes: 0 additions & 47 deletions packages/docs/src/demos/fetch/AddonOnNode.test.jsx

This file was deleted.

2 changes: 0 additions & 2 deletions packages/docs/src/demos/fetch/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ function useFetchFilms() {
})
.then((res) => res.json())
.then((data) => {
console.log({ data })
setStatus('success');
setData(data.results);
})
Expand All @@ -36,7 +35,6 @@ function useFetchFilms() {
export function App() {
const { status, data: films } = useFetchFilms();

console.log({ status, films })
if (status === 'loading') {
return <p>Fetching Star Wars data...</p>;
}
Expand Down
1 change: 1 addition & 0 deletions packages/docs/src/demos/fetch/App.stories.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { rest } from 'msw';
import { App } from './App';

// eslint-disable-next-line import/no-anonymous-default-export
export default {
title: 'Demos/Fetch',
component: App,
Expand Down
5 changes: 3 additions & 2 deletions packages/docs/src/demos/react-query/App.test.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react'
import { render, screen } from '@testing-library/react'
import { composeStories } from '@storybook/react'
import { vi } from 'vitest'

import { getServer } from '../../test-utils'
import * as stories from './App.stories'
Expand All @@ -10,7 +11,7 @@ const { MockedSuccess, MockedError } = composeStories(stories)
const server = getServer()

afterAll(() => {
jest.restoreAllMocks()
vi.restoreAllMocks()
})

it('renders film cards for each film', async () => {
Expand All @@ -32,7 +33,7 @@ it('renders film cards for each film', async () => {

it('renders error message if it cannot load the films', async () => {
// get rid of the console.error for this test which adds clutter to the logs
jest.spyOn(console, 'error').mockImplementationOnce(() => {})
vi.spyOn(console, 'error').mockImplementationOnce(() => {})

server.use(...MockedError.parameters.msw.handlers)
render(<MockedError />)
Expand Down
13 changes: 13 additions & 0 deletions packages/docs/vite.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'

// https://vitejs.dev/config/
export default defineConfig({
plugins: [react()],
test: {
globals: true,
environment: 'jsdom',
clearMocks: true,
setupFiles: './src/setupTests.js',
},
})
20 changes: 16 additions & 4 deletions packages/msw-addon/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,27 @@
"description": "Mock API requests in Storybook with Mock Service Worker.",
"version": "1.6.0",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
"module": "dist/index.mjs",
"types": "dist/index.d.ts",
"scripts": {
"build": "tsup",
"dev": "yarn build --watch",
"build": "tsc",
"prepublishOnly": "yarn build",
"release": "auto shipit"
},
"files": [
"dist/"
"dist/**/*",
"README.md",
"*.js",
"*.d.ts"
],
"exports": {
".": {
"require": "./dist/index.js",
"import": "./dist/index.mjs",
"types": "./dist/index.d.ts"
}
},
"repository": {
"type": "git",
"url": "git+https://github.com/mswjs/msw-storybook-addon.git",
Expand All @@ -39,7 +50,8 @@
"devDependencies": {
"@auto-it/released": "^10.32.2",
"auto": "^10.32.2",
"typescript": "^4.5.2"
"tsup": "^6.6.3",
"typescript": "^5.0.4"
},
"peerDependencies": {
"msw": ">=0.35.0 <2.0.0"
Expand Down

0 comments on commit fc53085

Please sign in to comment.