Skip to content

Commit

Permalink
Add react-router-v5-compat (#8110)
Browse files Browse the repository at this point in the history
  • Loading branch information
dylanjeffers authored Apr 16, 2024
1 parent 6cb5cbc commit bfe784b
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 25 deletions.
48 changes: 48 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@
"react-qr-code": "2.0.12",
"react-redux": "8.0.5",
"react-router-dom": "5.3.4",
"react-router-dom-v5-compat": "6.22.3",
"react-router-last-location": "2.0.1",
"react-scroll-parallax": "3.3.2",
"react-spring": "8.0.27",
Expand Down
49 changes: 26 additions & 23 deletions packages/web/src/app/AppProviders.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { ReactNode } from 'react'

import { ConnectedRouter } from 'connected-react-router'
import { CompatRouter } from 'react-router-dom-v5-compat'
import { LastLocationProvider } from 'react-router-last-location'

import { RouterContextProvider } from 'components/animated-switch/RouterContextProvider'
Expand Down Expand Up @@ -38,29 +39,31 @@ export const AppProviders = ({ children }: AppContextProps) => {
return (
<ReduxProvider initialStoreState={initialStoreState}>
<ConnectedRouter history={history}>
<LastLocationProvider>
<TrpcProvider>
<AudiusQueryProvider>
<AppContextProvider>
<ThemeProvider>
<NavProvider>
<ScrollProvider>
<RouterContextProvider>
<MainContentContextProvider>
<HeaderContextProvider>
<ToastContextProvider>
{children}
</ToastContextProvider>
</HeaderContextProvider>
</MainContentContextProvider>
</RouterContextProvider>
</ScrollProvider>
</NavProvider>
</ThemeProvider>
</AppContextProvider>
</AudiusQueryProvider>
</TrpcProvider>
</LastLocationProvider>
<CompatRouter>
<LastLocationProvider>
<TrpcProvider>
<AudiusQueryProvider>
<AppContextProvider>
<ThemeProvider>
<NavProvider>
<ScrollProvider>
<RouterContextProvider>
<MainContentContextProvider>
<HeaderContextProvider>
<ToastContextProvider>
{children}
</ToastContextProvider>
</HeaderContextProvider>
</MainContentContextProvider>
</RouterContextProvider>
</ScrollProvider>
</NavProvider>
</ThemeProvider>
</AppContextProvider>
</AudiusQueryProvider>
</TrpcProvider>
</LastLocationProvider>
</CompatRouter>
</ConnectedRouter>
</ReduxProvider>
)
Expand Down
10 changes: 9 additions & 1 deletion packages/web/src/test/test-utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import { ReactElement, ReactNode } from 'react'

import { ThemeProvider } from '@audius/harmony'
import { render, RenderOptions } from '@testing-library/react'
import { createMemoryHistory } from 'history'
import { Router } from 'react-router-dom'
import { CompatRouter } from 'react-router-dom-v5-compat'
import { PartialDeep } from 'type-fest'

import { ReduxProvider } from 'app/ReduxProvider'
Expand All @@ -21,11 +24,16 @@ const TestProviders =
(options?: TestOptions) => (props: TestProvidersProps) => {
const { children } = props
const { reduxState } = options ?? {}
const history = createMemoryHistory()
return (
<ThemeProvider theme='day'>
<ReduxProvider initialStoreState={reduxState}>
<RouterContextProvider>
<ToastContextProvider>{children} </ToastContextProvider>
<ToastContextProvider>
<Router history={history}>
<CompatRouter>{children}</CompatRouter>
</Router>
</ToastContextProvider>
</RouterContextProvider>
</ReduxProvider>
</ThemeProvider>
Expand Down
5 changes: 4 additions & 1 deletion packages/web/src/test/vitest-setup.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import '@testing-library/jest-dom/vitest'
import './vitest-canvas-mock'

import { vi } from 'vitest'
import { cleanup } from '@testing-library/react'
import { afterEach, vi } from 'vitest'

// Some global mocks that most tests will need.
// If you need to provide any form of mocked responses, you can replace them in your test with a hoisted implementation
Expand Down Expand Up @@ -33,3 +34,5 @@ window.matchMedia = vi.fn().mockReturnValue({
addListener: vi.fn(),
removeListener: vi.fn()
})

afterEach(cleanup)

0 comments on commit bfe784b

Please sign in to comment.