From 09c5626a5f9966cd27881f8199c5e3c866bd75c4 Mon Sep 17 00:00:00 2001 From: Onur Temizkan Date: Wed, 21 Jun 2023 07:24:33 +0100 Subject: [PATCH 1/3] WIP --- packages/remix/src/utils/futureFlags.ts | 35 +++++++++++++++++++++++++ packages/remix/src/utils/types.ts | 29 ++++++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100644 packages/remix/src/utils/futureFlags.ts diff --git a/packages/remix/src/utils/futureFlags.ts b/packages/remix/src/utils/futureFlags.ts new file mode 100644 index 000000000000..b9200d100a0e --- /dev/null +++ b/packages/remix/src/utils/futureFlags.ts @@ -0,0 +1,35 @@ +import { GLOBAL_OBJ } from '@sentry/utils'; + +import type { FutureConfig, ServerBuild } from './types'; + +export type EnhancedGlobal = typeof GLOBAL_OBJ & { + __remixContext?: { + future?: FutureConfig; + }; +}; + +/** + * Get the future flags from the Remix browser context + * + * @returns The future flags + */ +export function getFutureFlagsBrowser(): FutureConfig | undefined { + const window = GLOBAL_OBJ as EnhancedGlobal; + + if (!window.__remixContext) { + return; + } + + return window.__remixContext.future; +} + +/** + * Get the future flags from the Remix server build + * + * @param build The Remix server build + * + * @returns The future flags + */ +export function getFutureFlagsServer(build: ServerBuild): FutureConfig | undefined { + return build.future; +} diff --git a/packages/remix/src/utils/types.ts b/packages/remix/src/utils/types.ts index 74dcf10215cc..16a26f7f4674 100644 --- a/packages/remix/src/utils/types.ts +++ b/packages/remix/src/utils/types.ts @@ -14,6 +14,34 @@ import type * as Express from 'express'; import type { Agent } from 'https'; import type { ComponentType } from 'react'; +type Dev = { + command?: string; + scheme?: string; + host?: string; + port?: number; + restart?: boolean; + tlsKey?: string; + tlsCert?: string; +}; + +export interface FutureConfig { + unstable_dev: boolean | Dev; + /** @deprecated Use the `postcss` config option instead */ + unstable_postcss: boolean; + /** @deprecated Use the `tailwind` config option instead */ + unstable_tailwind: boolean; + v2_errorBoundary: boolean; + v2_headers: boolean; + v2_meta: boolean; + v2_normalizeFormMethod: boolean; + v2_routeConvention: boolean; +} + +export interface RemixConfig { + [key: string]: any; + future: FutureConfig; +} + export type RemixRequestState = { method: string; redirect: RequestRedirect; @@ -133,6 +161,7 @@ export interface ServerBuild { assets: AssetsManifest; publicPath?: string; assetsBuildDirectory?: string; + future?: FutureConfig; } export interface HandleDocumentRequestFunction { From b16666497ebd30a12747b87722c1a94791505eb8 Mon Sep 17 00:00:00 2001 From: Onur Temizkan Date: Fri, 23 Jun 2023 15:31:56 +0100 Subject: [PATCH 2/3] Add integration tests for Remix v2 features. --- .github/workflows/build.yml | 2 + packages/remix/package.json | 4 +- .../{app => app_v1}/entry.client.tsx | 0 .../{app => app_v1}/entry.server.tsx | 0 .../test/integration/{app => app_v1}/root.tsx | 0 .../routes/action-json-response/$id.tsx | 2 + .../app_v1/routes/capture-exception.tsx | 2 + .../app_v1/routes/capture-message.tsx | 2 + .../routes/error-boundary-capture/$id.tsx | 2 + .../test/integration/app_v1/routes/index.tsx | 2 + .../routes/loader-defer-response/index.tsx | 2 + .../routes/loader-json-response/$id.tsx | 2 + .../app_v1/routes/manual-tracing/$id.tsx | 2 + .../app_v1/routes/scope-bleed/$id.tsx | 2 + .../test/integration/app_v2/entry.client.tsx | 16 +++++ .../test/integration/app_v2/entry.server.tsx | 27 +++++++++ .../remix/test/integration/app_v2/root.tsx | 60 +++++++++++++++++++ .../routes/action-json-response.$id.tsx | 2 + .../app_v2/routes/capture-exception.tsx | 2 + .../app_v2/routes/capture-message.tsx | 2 + .../routes/error-boundary-capture.$id.tsx | 2 + .../test/integration/app_v2/routes/index.tsx | 2 + .../app_v2/routes/loader-defer-response.tsx | 2 + .../routes/loader-json-response.$id.tsx | 2 + .../app_v2/routes/manual-tracing.$id.tsx | 2 + .../app_v2/routes/scope-bleed.$id.tsx | 2 + .../routes/action-json-response.$id.tsx} | 0 .../routes/capture-exception.tsx | 0 .../routes/capture-message.tsx | 2 +- .../routes/error-boundary-capture.$id.tsx} | 0 .../{app => common}/routes/index.tsx | 0 .../routes/loader-defer-response.tsx} | 0 .../routes/loader-json-response.$id.tsx} | 0 .../routes/manual-tracing.$id.tsx} | 2 +- .../routes/scope-bleed.$id.tsx} | 0 .../remix/test/integration/remix.config.js | 11 +++- .../test/client/errorboundary.test.ts | 6 +- .../test/client/manualtracing.test.ts | 4 +- .../integration/test/client/pageload.test.ts | 5 +- .../integration/test/server/action.test.ts | 24 ++++---- .../integration/test/server/loader.test.ts | 57 +++++++++++------- packages/remix/test/integration/tsconfig.json | 2 +- 42 files changed, 219 insertions(+), 39 deletions(-) rename packages/remix/test/integration/{app => app_v1}/entry.client.tsx (100%) rename packages/remix/test/integration/{app => app_v1}/entry.server.tsx (100%) rename packages/remix/test/integration/{app => app_v1}/root.tsx (100%) create mode 100644 packages/remix/test/integration/app_v1/routes/action-json-response/$id.tsx create mode 100644 packages/remix/test/integration/app_v1/routes/capture-exception.tsx create mode 100644 packages/remix/test/integration/app_v1/routes/capture-message.tsx create mode 100644 packages/remix/test/integration/app_v1/routes/error-boundary-capture/$id.tsx create mode 100644 packages/remix/test/integration/app_v1/routes/index.tsx create mode 100644 packages/remix/test/integration/app_v1/routes/loader-defer-response/index.tsx create mode 100644 packages/remix/test/integration/app_v1/routes/loader-json-response/$id.tsx create mode 100644 packages/remix/test/integration/app_v1/routes/manual-tracing/$id.tsx create mode 100644 packages/remix/test/integration/app_v1/routes/scope-bleed/$id.tsx create mode 100644 packages/remix/test/integration/app_v2/entry.client.tsx create mode 100644 packages/remix/test/integration/app_v2/entry.server.tsx create mode 100644 packages/remix/test/integration/app_v2/root.tsx create mode 100644 packages/remix/test/integration/app_v2/routes/action-json-response.$id.tsx create mode 100644 packages/remix/test/integration/app_v2/routes/capture-exception.tsx create mode 100644 packages/remix/test/integration/app_v2/routes/capture-message.tsx create mode 100644 packages/remix/test/integration/app_v2/routes/error-boundary-capture.$id.tsx create mode 100644 packages/remix/test/integration/app_v2/routes/index.tsx create mode 100644 packages/remix/test/integration/app_v2/routes/loader-defer-response.tsx create mode 100644 packages/remix/test/integration/app_v2/routes/loader-json-response.$id.tsx create mode 100644 packages/remix/test/integration/app_v2/routes/manual-tracing.$id.tsx create mode 100644 packages/remix/test/integration/app_v2/routes/scope-bleed.$id.tsx rename packages/remix/test/integration/{app/routes/action-json-response/$id.tsx => common/routes/action-json-response.$id.tsx} (100%) rename packages/remix/test/integration/{app => common}/routes/capture-exception.tsx (100%) rename packages/remix/test/integration/{app => common}/routes/capture-message.tsx (89%) rename packages/remix/test/integration/{app/routes/error-boundary-capture/$id.tsx => common/routes/error-boundary-capture.$id.tsx} (100%) rename packages/remix/test/integration/{app => common}/routes/index.tsx (100%) rename packages/remix/test/integration/{app/routes/loader-defer-response/index.tsx => common/routes/loader-defer-response.tsx} (100%) rename packages/remix/test/integration/{app/routes/loader-json-response/$id.tsx => common/routes/loader-json-response.$id.tsx} (100%) rename packages/remix/test/integration/{app/routes/manual-tracing/$id.tsx => common/routes/manual-tracing.$id.tsx} (91%) rename packages/remix/test/integration/{app/routes/scope-bleed/$id.tsx => common/routes/scope-bleed.$id.tsx} (100%) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index b8e3fcafcb34..f423c60ced83 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -694,6 +694,7 @@ jobs: fail-fast: false matrix: node: [14, 16, 18] + remix: [1, 2] steps: - name: Check out current commit (${{ needs.job_get_metadata.outputs.commit_label }}) uses: actions/checkout@v3 @@ -710,6 +711,7 @@ jobs: - name: Run integration tests env: NODE_VERSION: ${{ matrix.node }} + REMIX_VERSION: ${{ matrix.remix }} run: | cd packages/remix yarn test:integration:ci diff --git a/packages/remix/package.json b/packages/remix/package.json index e964b237149c..a9bf20778ea8 100644 --- a/packages/remix/package.json +++ b/packages/remix/package.json @@ -59,7 +59,9 @@ "lint:eslint": "eslint . --format stylish", "lint:prettier": "prettier --check \"{src,test,scripts}/**/**.ts\"", "test": "yarn test:unit", - "test:integration": "run-s test:integration:clean test:integration:prepare test:integration:client test:integration:server", + "test:integration": "run-s test:integration:v1 test:integration:v2", + "test:integration:v1": "run-s test:integration:clean test:integration:prepare test:integration:client test:integration:server", + "test:integration:v2": "export REMIX_VERSION=2 && run-s test:integration:v1", "test:integration:ci": "run-s test:integration:clean test:integration:prepare test:integration:client:ci test:integration:server", "test:integration:prepare": "(cd test/integration && yarn)", "test:integration:clean": "(cd test/integration && rimraf .cache node_modules build)", diff --git a/packages/remix/test/integration/app/entry.client.tsx b/packages/remix/test/integration/app_v1/entry.client.tsx similarity index 100% rename from packages/remix/test/integration/app/entry.client.tsx rename to packages/remix/test/integration/app_v1/entry.client.tsx diff --git a/packages/remix/test/integration/app/entry.server.tsx b/packages/remix/test/integration/app_v1/entry.server.tsx similarity index 100% rename from packages/remix/test/integration/app/entry.server.tsx rename to packages/remix/test/integration/app_v1/entry.server.tsx diff --git a/packages/remix/test/integration/app/root.tsx b/packages/remix/test/integration/app_v1/root.tsx similarity index 100% rename from packages/remix/test/integration/app/root.tsx rename to packages/remix/test/integration/app_v1/root.tsx diff --git a/packages/remix/test/integration/app_v1/routes/action-json-response/$id.tsx b/packages/remix/test/integration/app_v1/routes/action-json-response/$id.tsx new file mode 100644 index 000000000000..ed034a14c52a --- /dev/null +++ b/packages/remix/test/integration/app_v1/routes/action-json-response/$id.tsx @@ -0,0 +1,2 @@ +export * from '../../../common/routes/action-json-response.$id'; +export { default } from '../../../common/routes/action-json-response.$id'; diff --git a/packages/remix/test/integration/app_v1/routes/capture-exception.tsx b/packages/remix/test/integration/app_v1/routes/capture-exception.tsx new file mode 100644 index 000000000000..1ba745d2e63d --- /dev/null +++ b/packages/remix/test/integration/app_v1/routes/capture-exception.tsx @@ -0,0 +1,2 @@ +export * from '../../common/routes/capture-exception'; +export { default } from '../../common/routes/capture-exception'; diff --git a/packages/remix/test/integration/app_v1/routes/capture-message.tsx b/packages/remix/test/integration/app_v1/routes/capture-message.tsx new file mode 100644 index 000000000000..9dae2318cc14 --- /dev/null +++ b/packages/remix/test/integration/app_v1/routes/capture-message.tsx @@ -0,0 +1,2 @@ +export * from '../../common/routes/capture-message'; +export { default } from '../../common/routes/capture-message'; diff --git a/packages/remix/test/integration/app_v1/routes/error-boundary-capture/$id.tsx b/packages/remix/test/integration/app_v1/routes/error-boundary-capture/$id.tsx new file mode 100644 index 000000000000..2c287dfe9696 --- /dev/null +++ b/packages/remix/test/integration/app_v1/routes/error-boundary-capture/$id.tsx @@ -0,0 +1,2 @@ +export * from '../../../common/routes/error-boundary-capture.$id'; +export { default } from '../../../common/routes/error-boundary-capture.$id'; diff --git a/packages/remix/test/integration/app_v1/routes/index.tsx b/packages/remix/test/integration/app_v1/routes/index.tsx new file mode 100644 index 000000000000..22c086a4c2cf --- /dev/null +++ b/packages/remix/test/integration/app_v1/routes/index.tsx @@ -0,0 +1,2 @@ +export * from '../../common/routes/index'; +export { default } from '../../common/routes/index'; diff --git a/packages/remix/test/integration/app_v1/routes/loader-defer-response/index.tsx b/packages/remix/test/integration/app_v1/routes/loader-defer-response/index.tsx new file mode 100644 index 000000000000..fd3a7b3f898d --- /dev/null +++ b/packages/remix/test/integration/app_v1/routes/loader-defer-response/index.tsx @@ -0,0 +1,2 @@ +export * from '../../../common/routes/loader-defer-response'; +export { default } from '../../../common/routes/loader-defer-response'; diff --git a/packages/remix/test/integration/app_v1/routes/loader-json-response/$id.tsx b/packages/remix/test/integration/app_v1/routes/loader-json-response/$id.tsx new file mode 100644 index 000000000000..ddf33953d77d --- /dev/null +++ b/packages/remix/test/integration/app_v1/routes/loader-json-response/$id.tsx @@ -0,0 +1,2 @@ +export * from '../../../common/routes/loader-json-response.$id'; +export { default } from '../../../common/routes/loader-json-response.$id'; diff --git a/packages/remix/test/integration/app_v1/routes/manual-tracing/$id.tsx b/packages/remix/test/integration/app_v1/routes/manual-tracing/$id.tsx new file mode 100644 index 000000000000..9979714818ff --- /dev/null +++ b/packages/remix/test/integration/app_v1/routes/manual-tracing/$id.tsx @@ -0,0 +1,2 @@ +export * from '../../../common/routes/manual-tracing.$id'; +export { default } from '../../../common/routes/manual-tracing.$id'; diff --git a/packages/remix/test/integration/app_v1/routes/scope-bleed/$id.tsx b/packages/remix/test/integration/app_v1/routes/scope-bleed/$id.tsx new file mode 100644 index 000000000000..d86864dccb9b --- /dev/null +++ b/packages/remix/test/integration/app_v1/routes/scope-bleed/$id.tsx @@ -0,0 +1,2 @@ +export * from '../../../common/routes/scope-bleed.$id'; +export { default } from '../../../common/routes/scope-bleed.$id'; diff --git a/packages/remix/test/integration/app_v2/entry.client.tsx b/packages/remix/test/integration/app_v2/entry.client.tsx new file mode 100644 index 000000000000..f9cfc14f2507 --- /dev/null +++ b/packages/remix/test/integration/app_v2/entry.client.tsx @@ -0,0 +1,16 @@ +import { RemixBrowser, useLocation, useMatches } from '@remix-run/react'; +import { hydrate } from 'react-dom'; +import * as Sentry from '@sentry/remix'; +import { useEffect } from 'react'; + +Sentry.init({ + dsn: 'https://public@dsn.ingest.sentry.io/1337', + tracesSampleRate: 1, + integrations: [ + new Sentry.BrowserTracing({ + routingInstrumentation: Sentry.remixRouterInstrumentation(useEffect, useLocation, useMatches), + }), + ], +}); + +hydrate(, document); diff --git a/packages/remix/test/integration/app_v2/entry.server.tsx b/packages/remix/test/integration/app_v2/entry.server.tsx new file mode 100644 index 000000000000..ae879492e236 --- /dev/null +++ b/packages/remix/test/integration/app_v2/entry.server.tsx @@ -0,0 +1,27 @@ +import type { EntryContext } from '@remix-run/node'; +import { RemixServer } from '@remix-run/react'; +import { renderToString } from 'react-dom/server'; +import * as Sentry from '@sentry/remix'; + +Sentry.init({ + dsn: 'https://public@dsn.ingest.sentry.io/1337', + tracesSampleRate: 1, + // Disabling to test series of envelopes deterministically. + autoSessionTracking: false, +}); + +export default function handleRequest( + request: Request, + responseStatusCode: number, + responseHeaders: Headers, + remixContext: EntryContext, +) { + let markup = renderToString(); + + responseHeaders.set('Content-Type', 'text/html'); + + return new Response('' + markup, { + status: responseStatusCode, + headers: responseHeaders, + }); +} diff --git a/packages/remix/test/integration/app_v2/root.tsx b/packages/remix/test/integration/app_v2/root.tsx new file mode 100644 index 000000000000..faf075951d69 --- /dev/null +++ b/packages/remix/test/integration/app_v2/root.tsx @@ -0,0 +1,60 @@ +import { V2_MetaFunction, LoaderFunction, json, defer, redirect } from '@remix-run/node'; +import { Links, LiveReload, Meta, Outlet, Scripts, ScrollRestoration } from '@remix-run/react'; +import { withSentry } from '@sentry/remix'; + +export const meta: V2_MetaFunction = ({ data }) => [ + { charset: 'utf-8' }, + { title: 'New Remix App' }, + { name: 'viewport', content: 'width=device-width,initial-scale=1' }, + { name: 'sentry-trace', content: data.sentryTrace }, + { name: 'baggage', content: data.sentryBaggage }, +]; + +export const loader: LoaderFunction = async ({ request }) => { + const url = new URL(request.url); + const type = url.searchParams.get('type'); + + switch (type) { + case 'empty': + return {}; + case 'plain': + return { + data_one: [], + data_two: 'a string', + }; + case 'json': + return json({ data_one: [], data_two: 'a string' }, { headers: { 'Cache-Control': 'max-age=300' } }); + case 'defer': + return defer({ data_one: [], data_two: 'a string' }); + case 'null': + return null; + case 'undefined': + return undefined; + case 'throwRedirect': + throw redirect('/?type=plain'); + case 'returnRedirect': + return redirect('/?type=plain'); + default: { + return {}; + } + } +}; + +function App() { + return ( + + + + + + + + + + + + + ); +} + +export default withSentry(App); diff --git a/packages/remix/test/integration/app_v2/routes/action-json-response.$id.tsx b/packages/remix/test/integration/app_v2/routes/action-json-response.$id.tsx new file mode 100644 index 000000000000..7a00bfb2bfe7 --- /dev/null +++ b/packages/remix/test/integration/app_v2/routes/action-json-response.$id.tsx @@ -0,0 +1,2 @@ +export * from '../../common/routes/action-json-response.$id'; +export { default } from '../../common/routes/action-json-response.$id'; diff --git a/packages/remix/test/integration/app_v2/routes/capture-exception.tsx b/packages/remix/test/integration/app_v2/routes/capture-exception.tsx new file mode 100644 index 000000000000..1ba745d2e63d --- /dev/null +++ b/packages/remix/test/integration/app_v2/routes/capture-exception.tsx @@ -0,0 +1,2 @@ +export * from '../../common/routes/capture-exception'; +export { default } from '../../common/routes/capture-exception'; diff --git a/packages/remix/test/integration/app_v2/routes/capture-message.tsx b/packages/remix/test/integration/app_v2/routes/capture-message.tsx new file mode 100644 index 000000000000..9dae2318cc14 --- /dev/null +++ b/packages/remix/test/integration/app_v2/routes/capture-message.tsx @@ -0,0 +1,2 @@ +export * from '../../common/routes/capture-message'; +export { default } from '../../common/routes/capture-message'; diff --git a/packages/remix/test/integration/app_v2/routes/error-boundary-capture.$id.tsx b/packages/remix/test/integration/app_v2/routes/error-boundary-capture.$id.tsx new file mode 100644 index 000000000000..011f92462069 --- /dev/null +++ b/packages/remix/test/integration/app_v2/routes/error-boundary-capture.$id.tsx @@ -0,0 +1,2 @@ +export * from '../../common/routes/error-boundary-capture.$id'; +export { default } from '../../common/routes/error-boundary-capture.$id'; diff --git a/packages/remix/test/integration/app_v2/routes/index.tsx b/packages/remix/test/integration/app_v2/routes/index.tsx new file mode 100644 index 000000000000..22c086a4c2cf --- /dev/null +++ b/packages/remix/test/integration/app_v2/routes/index.tsx @@ -0,0 +1,2 @@ +export * from '../../common/routes/index'; +export { default } from '../../common/routes/index'; diff --git a/packages/remix/test/integration/app_v2/routes/loader-defer-response.tsx b/packages/remix/test/integration/app_v2/routes/loader-defer-response.tsx new file mode 100644 index 000000000000..38415a9a3781 --- /dev/null +++ b/packages/remix/test/integration/app_v2/routes/loader-defer-response.tsx @@ -0,0 +1,2 @@ +export * from '../../common/routes/loader-defer-response'; +export { default } from '../../common/routes/loader-defer-response'; diff --git a/packages/remix/test/integration/app_v2/routes/loader-json-response.$id.tsx b/packages/remix/test/integration/app_v2/routes/loader-json-response.$id.tsx new file mode 100644 index 000000000000..7761875bdb76 --- /dev/null +++ b/packages/remix/test/integration/app_v2/routes/loader-json-response.$id.tsx @@ -0,0 +1,2 @@ +export * from '../../common/routes/loader-json-response.$id'; +export { default } from '../../common/routes/loader-json-response.$id'; diff --git a/packages/remix/test/integration/app_v2/routes/manual-tracing.$id.tsx b/packages/remix/test/integration/app_v2/routes/manual-tracing.$id.tsx new file mode 100644 index 000000000000..a7cfebe4ed46 --- /dev/null +++ b/packages/remix/test/integration/app_v2/routes/manual-tracing.$id.tsx @@ -0,0 +1,2 @@ +export * from '../../common/routes/manual-tracing.$id'; +export { default } from '../../common/routes/manual-tracing.$id'; diff --git a/packages/remix/test/integration/app_v2/routes/scope-bleed.$id.tsx b/packages/remix/test/integration/app_v2/routes/scope-bleed.$id.tsx new file mode 100644 index 000000000000..5ba2376f0339 --- /dev/null +++ b/packages/remix/test/integration/app_v2/routes/scope-bleed.$id.tsx @@ -0,0 +1,2 @@ +export * from '../../common/routes/scope-bleed.$id'; +export { default } from '../../common/routes/scope-bleed.$id'; diff --git a/packages/remix/test/integration/app/routes/action-json-response/$id.tsx b/packages/remix/test/integration/common/routes/action-json-response.$id.tsx similarity index 100% rename from packages/remix/test/integration/app/routes/action-json-response/$id.tsx rename to packages/remix/test/integration/common/routes/action-json-response.$id.tsx diff --git a/packages/remix/test/integration/app/routes/capture-exception.tsx b/packages/remix/test/integration/common/routes/capture-exception.tsx similarity index 100% rename from packages/remix/test/integration/app/routes/capture-exception.tsx rename to packages/remix/test/integration/common/routes/capture-exception.tsx diff --git a/packages/remix/test/integration/app/routes/capture-message.tsx b/packages/remix/test/integration/common/routes/capture-message.tsx similarity index 89% rename from packages/remix/test/integration/app/routes/capture-message.tsx rename to packages/remix/test/integration/common/routes/capture-message.tsx index 459e25e1b4ee..06e92f79e931 100644 --- a/packages/remix/test/integration/app/routes/capture-message.tsx +++ b/packages/remix/test/integration/common/routes/capture-message.tsx @@ -3,5 +3,5 @@ import * as Sentry from '@sentry/remix'; export default function ErrorBoundaryCapture() { Sentry.captureMessage('Sentry Manually Captured Message'); - return
; + return
; } diff --git a/packages/remix/test/integration/app/routes/error-boundary-capture/$id.tsx b/packages/remix/test/integration/common/routes/error-boundary-capture.$id.tsx similarity index 100% rename from packages/remix/test/integration/app/routes/error-boundary-capture/$id.tsx rename to packages/remix/test/integration/common/routes/error-boundary-capture.$id.tsx diff --git a/packages/remix/test/integration/app/routes/index.tsx b/packages/remix/test/integration/common/routes/index.tsx similarity index 100% rename from packages/remix/test/integration/app/routes/index.tsx rename to packages/remix/test/integration/common/routes/index.tsx diff --git a/packages/remix/test/integration/app/routes/loader-defer-response/index.tsx b/packages/remix/test/integration/common/routes/loader-defer-response.tsx similarity index 100% rename from packages/remix/test/integration/app/routes/loader-defer-response/index.tsx rename to packages/remix/test/integration/common/routes/loader-defer-response.tsx diff --git a/packages/remix/test/integration/app/routes/loader-json-response/$id.tsx b/packages/remix/test/integration/common/routes/loader-json-response.$id.tsx similarity index 100% rename from packages/remix/test/integration/app/routes/loader-json-response/$id.tsx rename to packages/remix/test/integration/common/routes/loader-json-response.$id.tsx diff --git a/packages/remix/test/integration/app/routes/manual-tracing/$id.tsx b/packages/remix/test/integration/common/routes/manual-tracing.$id.tsx similarity index 91% rename from packages/remix/test/integration/app/routes/manual-tracing/$id.tsx rename to packages/remix/test/integration/common/routes/manual-tracing.$id.tsx index 75cf8574819a..2f925881b9cf 100644 --- a/packages/remix/test/integration/app/routes/manual-tracing/$id.tsx +++ b/packages/remix/test/integration/common/routes/manual-tracing.$id.tsx @@ -3,5 +3,5 @@ import * as Sentry from '@sentry/remix'; export default function ManualTracing() { const transaction = Sentry.startTransaction({ name: 'test_transaction_1' }); transaction.finish(); - return
; + return
; } diff --git a/packages/remix/test/integration/app/routes/scope-bleed/$id.tsx b/packages/remix/test/integration/common/routes/scope-bleed.$id.tsx similarity index 100% rename from packages/remix/test/integration/app/routes/scope-bleed/$id.tsx rename to packages/remix/test/integration/common/routes/scope-bleed.$id.tsx diff --git a/packages/remix/test/integration/remix.config.js b/packages/remix/test/integration/remix.config.js index 02f847cbf1ca..b4c7ac0837b8 100644 --- a/packages/remix/test/integration/remix.config.js +++ b/packages/remix/test/integration/remix.config.js @@ -1,7 +1,16 @@ /** @type {import('@remix-run/dev').AppConfig} */ +const useV2 = process.env.REMIX_VERSION === '2'; + module.exports = { - appDirectory: 'app', + appDirectory: useV2 ? 'app_v2' : 'app_v1', assetsBuildDirectory: 'public/build', serverBuildPath: 'build/index.js', publicPath: '/build/', + future: { + v2_errorBoundary: useV2, + v2_headers: useV2, + v2_meta: useV2, + v2_normalizeFormMethod: useV2, + v2_routeConvention: useV2, + }, }; diff --git a/packages/remix/test/integration/test/client/errorboundary.test.ts b/packages/remix/test/integration/test/client/errorboundary.test.ts index 6bf6314095fd..b90b3e8d3eaa 100644 --- a/packages/remix/test/integration/test/client/errorboundary.test.ts +++ b/packages/remix/test/integration/test/client/errorboundary.test.ts @@ -2,6 +2,8 @@ import { getMultipleSentryEnvelopeRequests } from './utils/helpers'; import { test, expect } from '@playwright/test'; import { Event } from '@sentry/types'; +const useV2 = process.env.REMIX_VERSION === '2'; + test('should capture React component errors.', async ({ page }) => { const envelopes = await getMultipleSentryEnvelopeRequests(page, 2, { url: '/error-boundary-capture/0', @@ -12,7 +14,9 @@ test('should capture React component errors.', async ({ page }) => { expect(pageloadEnvelope.contexts?.trace.op).toBe('pageload'); expect(pageloadEnvelope.tags?.['routing.instrumentation']).toBe('remix-router'); expect(pageloadEnvelope.type).toBe('transaction'); - expect(pageloadEnvelope.transaction).toBe('routes/error-boundary-capture/$id'); + expect(pageloadEnvelope.transaction).toBe( + useV2 ? 'routes/error-boundary-capture.$id' : 'routes/error-boundary-capture/$id', + ); expect(errorEnvelope.level).toBe('error'); expect(errorEnvelope.sdk?.name).toBe('sentry.javascript.remix'); diff --git a/packages/remix/test/integration/test/client/manualtracing.test.ts b/packages/remix/test/integration/test/client/manualtracing.test.ts index edc919d2d4a9..424408e7be9d 100644 --- a/packages/remix/test/integration/test/client/manualtracing.test.ts +++ b/packages/remix/test/integration/test/client/manualtracing.test.ts @@ -2,6 +2,8 @@ import { getMultipleSentryEnvelopeRequests } from './utils/helpers'; import { test, expect } from '@playwright/test'; import { Event } from '@sentry/types'; +const useV2 = process.env.REMIX_VERSION === '2'; + test('should report a manually created / finished transaction.', async ({ page }) => { const envelopes = await getMultipleSentryEnvelopeRequests(page, 2, { url: '/manual-tracing/0', @@ -17,5 +19,5 @@ test('should report a manually created / finished transaction.', async ({ page } expect(pageloadEnvelope.contexts?.trace?.op).toBe('pageload'); expect(pageloadEnvelope.tags?.['routing.instrumentation']).toBe('remix-router'); expect(pageloadEnvelope.type).toBe('transaction'); - expect(pageloadEnvelope.transaction).toBe('routes/manual-tracing/$id'); + expect(pageloadEnvelope.transaction).toBe(useV2 ? 'routes/manual-tracing.$id' : 'routes/manual-tracing/$id'); }); diff --git a/packages/remix/test/integration/test/client/pageload.test.ts b/packages/remix/test/integration/test/client/pageload.test.ts index 1543bd2a342c..7c49e4ac9c8c 100644 --- a/packages/remix/test/integration/test/client/pageload.test.ts +++ b/packages/remix/test/integration/test/client/pageload.test.ts @@ -1,3 +1,5 @@ +const useV2 = process.env.REMIX_VERSION === '2'; + import { getFirstSentryEnvelopeRequest } from './utils/helpers'; import { test, expect } from '@playwright/test'; import { Event } from '@sentry/types'; @@ -8,5 +10,6 @@ test('should add `pageload` transaction on load.', async ({ page }) => { expect(envelope.contexts?.trace.op).toBe('pageload'); expect(envelope.tags?.['routing.instrumentation']).toBe('remix-router'); expect(envelope.type).toBe('transaction'); - expect(envelope.transaction).toBe('routes/index'); + + expect(envelope.transaction).toBe(useV2 ? 'root' : 'routes/index'); }); diff --git a/packages/remix/test/integration/test/server/action.test.ts b/packages/remix/test/integration/test/server/action.test.ts index 6bb4b74d3540..664162f2076d 100644 --- a/packages/remix/test/integration/test/server/action.test.ts +++ b/packages/remix/test/integration/test/server/action.test.ts @@ -1,5 +1,7 @@ import { assertSentryTransaction, assertSentryEvent, RemixTestEnv } from './utils/helpers'; +const useV2 = process.env.REMIX_VERSION === '2'; + jest.spyOn(console, 'error').mockImplementation(); // Repeat tests for each adapter @@ -11,10 +13,10 @@ describe.each(['builtin', 'express'])('Remix API Actions with adapter = %s', ada const transaction = envelope[2]; assertSentryTransaction(transaction, { - transaction: 'routes/action-json-response/$id', + transaction: `routes/action-json-response${useV2 ? '.' : '/'}$id`, spans: [ { - description: 'routes/action-json-response/$id', + description: `routes/action-json-response${useV2 ? '.' : '/'}$id`, op: 'function.remix.action', }, { @@ -22,11 +24,11 @@ describe.each(['builtin', 'express'])('Remix API Actions with adapter = %s', ada op: 'function.remix.loader', }, { - description: 'routes/action-json-response/$id', + description: `routes/action-json-response${useV2 ? '.' : '/'}$id`, op: 'function.remix.loader', }, { - description: 'routes/action-json-response/$id', + description: `routes/action-json-response${useV2 ? '.' : '/'}$id`, op: 'function.remix.document_request', }, ], @@ -102,7 +104,7 @@ describe.each(['builtin', 'express'])('Remix API Actions with adapter = %s', ada const [event] = envelopes.filter(envelope => envelope[1].type === 'event'); assertSentryTransaction(transaction[2], { - transaction: 'routes/action-json-response/$id', + transaction: `routes/action-json-response${useV2 ? '.' : '/'}$id`, request: { method: 'POST', url, @@ -161,7 +163,7 @@ describe.each(['builtin', 'express'])('Remix API Actions with adapter = %s', ada }, }, tags: { - transaction: 'routes/action-json-response/$id', + transaction: `routes/action-json-response${useV2 ? '.' : '/'}$id`, }, }); @@ -177,7 +179,7 @@ describe.each(['builtin', 'express'])('Remix API Actions with adapter = %s', ada }, }, tags: { - transaction: 'routes/action-json-response/$id', + transaction: `routes/action-json-response${useV2 ? '.' : '/'}$id`, }, }); @@ -227,7 +229,7 @@ describe.each(['builtin', 'express'])('Remix API Actions with adapter = %s', ada }, }, tags: { - transaction: 'routes/action-json-response/$id', + transaction: `routes/action-json-response${useV2 ? '.' : '/'}$id`, }, }); @@ -277,7 +279,7 @@ describe.each(['builtin', 'express'])('Remix API Actions with adapter = %s', ada }, }, tags: { - transaction: 'routes/action-json-response/$id', + transaction: `routes/action-json-response${useV2 ? '.' : '/'}$id`, }, }); @@ -327,7 +329,7 @@ describe.each(['builtin', 'express'])('Remix API Actions with adapter = %s', ada }, }, tags: { - transaction: 'routes/action-json-response/$id', + transaction: `routes/action-json-response${useV2 ? '.' : '/'}$id`, }, }); @@ -377,7 +379,7 @@ describe.each(['builtin', 'express'])('Remix API Actions with adapter = %s', ada }, }, tags: { - transaction: 'routes/action-json-response/$id', + transaction: `routes/action-json-response${useV2 ? '.' : '/'}$id`, }, }); diff --git a/packages/remix/test/integration/test/server/loader.test.ts b/packages/remix/test/integration/test/server/loader.test.ts index 2545f63d6e92..9613d19fce42 100644 --- a/packages/remix/test/integration/test/server/loader.test.ts +++ b/packages/remix/test/integration/test/server/loader.test.ts @@ -1,6 +1,8 @@ import { assertSentryTransaction, RemixTestEnv, assertSentryEvent } from './utils/helpers'; import { Event } from '@sentry/types'; +const useV2 = process.env.REMIX_VERSION === '2'; + jest.spyOn(console, 'error').mockImplementation(); // Repeat tests for each adapter @@ -52,7 +54,7 @@ describe.each(['builtin', 'express'])('Remix API Loaders with adapter = %s', ada const transaction = envelope[2]; assertSentryTransaction(transaction, { - transaction: 'routes/loader-json-response/$id', + transaction: `routes/loader-json-response${useV2 ? '.' : '/'}$id`, transaction_info: { source: 'route', }, @@ -62,11 +64,11 @@ describe.each(['builtin', 'express'])('Remix API Loaders with adapter = %s', ada op: 'function.remix.loader', }, { - description: 'routes/loader-json-response/$id', + description: `routes/loader-json-response${useV2 ? '.' : '/'}$id`, op: 'function.remix.loader', }, { - description: 'routes/loader-json-response/$id', + description: `routes/loader-json-response${useV2 ? '.' : '/'}$id`, op: 'function.remix.document_request', }, ], @@ -98,7 +100,7 @@ describe.each(['builtin', 'express'])('Remix API Loaders with adapter = %s', ada }, }, tags: { - transaction: 'routes/loader-json-response/$id', + transaction: `routes/loader-json-response${useV2 ? '.' : '/'}$id`, }, }); @@ -114,7 +116,7 @@ describe.each(['builtin', 'express'])('Remix API Loaders with adapter = %s', ada }, }, tags: { - transaction: 'routes/loader-json-response/$id', + transaction: `routes/loader-json-response${useV2 ? '.' : '/'}$id`, }, }); @@ -195,24 +197,39 @@ describe.each(['builtin', 'express'])('Remix API Loaders with adapter = %s', ada const transaction = envelope[2]; assertSentryTransaction(transaction, { - transaction: 'root', + transaction: useV2 ? 'routes/loader-defer-response' : 'root', transaction_info: { source: 'route', }, - spans: [ - { - description: 'root', - op: 'function.remix.loader', - }, - { - description: 'routes/loader-defer-response/index', - op: 'function.remix.loader', - }, - { - description: 'root', - op: 'function.remix.document_request', - }, - ], + spans: useV2 + ? [ + { + description: 'root', + op: 'function.remix.loader', + }, + { + description: 'routes/loader-defer-response', + op: 'function.remix.loader', + }, + { + description: 'routes/loader-defer-response', + op: 'function.remix.document_request', + }, + ] + : [ + { + description: 'root', + op: 'function.remix.loader', + }, + { + description: 'routes/loader-defer-response/index', + op: 'function.remix.loader', + }, + { + description: 'root', + op: 'function.remix.document_request', + }, + ], }); }); }); diff --git a/packages/remix/test/integration/tsconfig.json b/packages/remix/test/integration/tsconfig.json index 2129c1a599f6..f190b5da307f 100644 --- a/packages/remix/test/integration/tsconfig.json +++ b/packages/remix/test/integration/tsconfig.json @@ -13,7 +13,7 @@ "forceConsistentCasingInFileNames": true, "baseUrl": ".", "paths": { - "~/*": ["./app/*"] + "~/*": ["app_v1/*", "app_v2/*"] }, "noEmit": true } From 048426fe5a9ff88c91daec000aab32fdb9467872 Mon Sep 17 00:00:00 2001 From: Onur Temizkan Date: Mon, 26 Jun 2023 10:38:37 +0100 Subject: [PATCH 3/3] Remove unused future-flag utilities / types. --- .github/workflows/build.yml | 2 +- packages/remix/src/utils/futureFlags.ts | 35 ------------------------- packages/remix/src/utils/types.ts | 29 -------------------- 3 files changed, 1 insertion(+), 65 deletions(-) delete mode 100644 packages/remix/src/utils/futureFlags.ts diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index f423c60ced83..e2ec7fdcf411 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -685,7 +685,7 @@ jobs: yarn test job_remix_integration_tests: - name: Remix (Node ${{ matrix.node }}) Tests + name: Remix v${{ matrix.remix }} (Node ${{ matrix.node }}) Tests needs: [job_get_metadata, job_build] if: needs.job_get_metadata.outputs.changed_remix == 'true' || github.event_name != 'pull_request' runs-on: ubuntu-20.04 diff --git a/packages/remix/src/utils/futureFlags.ts b/packages/remix/src/utils/futureFlags.ts deleted file mode 100644 index b9200d100a0e..000000000000 --- a/packages/remix/src/utils/futureFlags.ts +++ /dev/null @@ -1,35 +0,0 @@ -import { GLOBAL_OBJ } from '@sentry/utils'; - -import type { FutureConfig, ServerBuild } from './types'; - -export type EnhancedGlobal = typeof GLOBAL_OBJ & { - __remixContext?: { - future?: FutureConfig; - }; -}; - -/** - * Get the future flags from the Remix browser context - * - * @returns The future flags - */ -export function getFutureFlagsBrowser(): FutureConfig | undefined { - const window = GLOBAL_OBJ as EnhancedGlobal; - - if (!window.__remixContext) { - return; - } - - return window.__remixContext.future; -} - -/** - * Get the future flags from the Remix server build - * - * @param build The Remix server build - * - * @returns The future flags - */ -export function getFutureFlagsServer(build: ServerBuild): FutureConfig | undefined { - return build.future; -} diff --git a/packages/remix/src/utils/types.ts b/packages/remix/src/utils/types.ts index 16a26f7f4674..74dcf10215cc 100644 --- a/packages/remix/src/utils/types.ts +++ b/packages/remix/src/utils/types.ts @@ -14,34 +14,6 @@ import type * as Express from 'express'; import type { Agent } from 'https'; import type { ComponentType } from 'react'; -type Dev = { - command?: string; - scheme?: string; - host?: string; - port?: number; - restart?: boolean; - tlsKey?: string; - tlsCert?: string; -}; - -export interface FutureConfig { - unstable_dev: boolean | Dev; - /** @deprecated Use the `postcss` config option instead */ - unstable_postcss: boolean; - /** @deprecated Use the `tailwind` config option instead */ - unstable_tailwind: boolean; - v2_errorBoundary: boolean; - v2_headers: boolean; - v2_meta: boolean; - v2_normalizeFormMethod: boolean; - v2_routeConvention: boolean; -} - -export interface RemixConfig { - [key: string]: any; - future: FutureConfig; -} - export type RemixRequestState = { method: string; redirect: RequestRedirect; @@ -161,7 +133,6 @@ export interface ServerBuild { assets: AssetsManifest; publicPath?: string; assetsBuildDirectory?: string; - future?: FutureConfig; } export interface HandleDocumentRequestFunction {