Skip to content

test(react): Ensure react router 3 tests always have correct types #14949

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions packages/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,8 @@
"@types/hoist-non-react-statics": "^3.3.5",
"@types/node-fetch": "^2.6.11",
"@types/react": "17.0.3",
"@types/react-router-3": "npm:@types/[email protected]",
"@types/react-router-4": "npm:@types/[email protected]",
"@types/react-router-5": "npm:@types/[email protected]",
"@types/react-router-4": "npm:@types/[email protected]",
"@types/react-router-5": "npm:@types/[email protected]",
"eslint-plugin-react": "^7.20.5",
"eslint-plugin-react-hooks": "^4.0.8",
"history-4": "npm:[email protected]",
Expand Down
16 changes: 16 additions & 0 deletions packages/react/test/global.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Have to manually set types because we are using package-alias
// Note that using e.g. ` "@types/react-router-3": "npm:@types/[email protected]",` in package.json does not work,
// because the react-router v3 types re-export types from react-router/lib which ends up being the react router v6 types
// So instead, we provide the types manually here
declare module 'react-router-3' {
import type * as React from 'react';
import type { Match, Route as RouteType } from '../src/reactrouterv3';

type History = { replace: (s: string) => void; push: (s: string) => void };
export function createMemoryHistory(): History;
export const Router: React.ComponentType<{ history: History }>;
export const Route: React.ComponentType<{ path: string; component?: React.ComponentType<any> }>;
export const IndexRoute: React.ComponentType<{ component: React.ComponentType<any> }>;
export const match: Match;
export const createRoutes: (routes: any) => RouteType[];
}
14 changes: 1 addition & 13 deletions packages/react/test/reactrouterv3.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,11 @@ import {
setCurrentClient,
} from '@sentry/core';
import { act, render } from '@testing-library/react';
// biome-ignore lint/nursery/noUnusedImports: <explanation>
import * as React from 'react';
import { IndexRoute, Route, Router, createMemoryHistory, createRoutes, match } from 'react-router-3';

import type { Match, Route as RouteType } from '../src/reactrouterv3';
import { reactRouterV3BrowserTracingIntegration } from '../src/reactrouterv3';

// Have to manually set types because we are using package-alias
declare module 'react-router-3' {
type History = { replace: (s: string) => void; push: (s: string) => void };
export function createMemoryHistory(): History;
export const Router: React.ComponentType<{ history: History }>;
export const Route: React.ComponentType<{ path: string; component?: React.ComponentType<any> }>;
export const IndexRoute: React.ComponentType<{ component: React.ComponentType<any> }>;
export const match: Match;
export const createRoutes: (routes: any) => RouteType[];
}

const mockStartBrowserTracingPageLoadSpan = jest.fn();
const mockStartBrowserTracingNavigationSpan = jest.fn();

Expand Down
34 changes: 13 additions & 21 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -10128,10 +10128,10 @@
resolved "https://registry.yarnpkg.com/@types/history/-/history-4.7.8.tgz#49348387983075705fe8f4e02fb67f7daaec4934"
integrity sha512-S78QIYirQcUoo6UJZx9CSP0O2ix9IaeAXwQi26Rhr/+mg7qqPy8TzaxHSUut7eGjL8WmLccT7/MXf304WjqHcA==

"@types/history@^3":
version "3.2.4"
resolved "https://registry.yarnpkg.com/@types/history/-/history-3.2.4.tgz#0b6c62240d1fac020853aa5608758991d9f6ef3d"
integrity sha512-q7x8QeCRk2T6DR2UznwYW//mpN5uNlyajkewH2xd1s1ozCS4oHFRg2WMusxwLFlE57EkUYsd/gCapLBYzV3ffg==
"@types/history@^4.7.11":
version "4.7.11"
resolved "https://registry.yarnpkg.com/@types/history/-/history-4.7.11.tgz#56588b17ae8f50c53983a524fc3cc47437969d64"
integrity sha512-qjDJRrmvBMiTx+jyLxvLfJU7UznFuokDv4f3WRuriHKERccVpFU+8XMQUAbDzoiJCsmexxRExQeMwwCdamSKDA==

"@types/hoist-non-react-statics@^3.3.5":
version "3.3.5"
Expand Down Expand Up @@ -10427,28 +10427,20 @@
dependencies:
"@types/react" "*"

"@types/react-router-3@npm:@types/[email protected]":
version "3.0.24"
resolved "https://registry.yarnpkg.com/@types/react-router/-/react-router-3.0.24.tgz#f924569538ea78a0b0d70892900a0d99ed6d7354"
integrity sha512-cSpMXzI0WocB5/UmySAtGlvG5w3m2mNvU6FgYFFWGqt6KywI7Ez+4Z9mEkglcAAGaP+voZjVg+BJP86bkVrSxQ==
dependencies:
"@types/history" "^3"
"@types/react" "*"

"@types/react-router-4@npm:@types/[email protected]":
version "5.1.14"
resolved "https://registry.yarnpkg.com/@types/react-router/-/react-router-5.1.14.tgz#e0442f4eb4c446541ad7435d44a97f8fe6df40da"
integrity sha512-LAJpqYUaCTMT2anZheoidiIymt8MuX286zoVFPM3DVb23aQBH0mAkFvzpd4LKqiolV8bBtZWT5Qp7hClCNDENw==
"@types/react-router-4@npm:@types/[email protected]":
version "4.0.25"
resolved "https://registry.yarnpkg.com/@types/react-router/-/react-router-4.0.25.tgz#1e25490780b80e0d8f96bf649379cca8638c1e5a"
integrity sha512-IsFvDwQy2X08g+tRMvugH1l7e0kkR+o5qEUkFfYLmjw2jGCPogY2bBuRAgZCZ5CSUswdNTkKtPUmNo+f6afyfg==
dependencies:
"@types/history" "*"
"@types/react" "*"

"@types/react-router-5@npm:@types/[email protected].14":
version "5.1.14"
resolved "https://registry.yarnpkg.com/@types/react-router/-/react-router-5.1.14.tgz#e0442f4eb4c446541ad7435d44a97f8fe6df40da"
integrity sha512-LAJpqYUaCTMT2anZheoidiIymt8MuX286zoVFPM3DVb23aQBH0mAkFvzpd4LKqiolV8bBtZWT5Qp7hClCNDENw==
"@types/react-router-5@npm:@types/[email protected].20":
version "5.1.20"
resolved "https://registry.yarnpkg.com/@types/react-router/-/react-router-5.1.20.tgz#88eccaa122a82405ef3efbcaaa5dcdd9f021387c"
integrity sha512-jGjmu/ZqS7FjSH6owMcD5qpq19+1RS9DeVRqfl1FeBMxTDQAGwlMWOcs52NDoXaNKyG3d1cYQFMs9rCrb88o9Q==
dependencies:
"@types/history" "*"
"@types/history" "^4.7.11"
"@types/react" "*"

"@types/react-test-renderer@>=16.9.0":
Expand Down
Loading