Skip to content

test(remix): Run tsc before Remix E2E tests #16345

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

Open
wants to merge 14 commits into
base: develop
Choose a base branch
from
Open
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,16 @@ import * as Sentry from '@sentry/remix';
import { StrictMode, startTransition, useEffect } from 'react';
import { hydrateRoot } from 'react-dom/client';

// Extend the Window interface to include ENV
declare global {
interface Window {
ENV: {
SENTRY_DSN: string;
[key: string]: unknown;
};
}
}

Sentry.init({
environment: 'qa', // dynamic sampling bias to keep transactions
dsn: window.ENV.SENTRY_DSN,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,6 @@ function isBotRequest(userAgent: string | null) {
return isbotModule.isbot(userAgent);
}

// isbot < 3.8.0
if ('default' in isbotModule && typeof isbotModule.default === 'function') {
return isbotModule.default(userAgent);
}

return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export function ErrorBoundary() {
}

function App() {
const { ENV } = useLoaderData();
const { ENV } = useLoaderData() as { ENV: { SENTRY_DSN: string } };

return (
<html lang="en">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const loader: LoaderFunction = async ({ params: { id } }) => {
};

export default function LoaderError() {
const data = useLoaderData();
const data = useLoaderData() as { test?: string };

return (
<div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"private": true,
"sideEffects": false,
"scripts": {
"build": "remix vite:build",
"build": "remix vite:build && pnpm typecheck",
"dev": "node ./server.mjs",
"lint": "eslint --ignore-path .gitignore --cache --cache-location ./node_modules/.cache/eslint .",
"start": "cross-env NODE_ENV=production node ./server.mjs",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,16 @@ import * as Sentry from '@sentry/remix';
import { StrictMode, startTransition, useEffect } from 'react';
import { hydrateRoot } from 'react-dom/client';

// Extend the Window interface to include ENV
declare global {
interface Window {
ENV: {
SENTRY_DSN: string;
[key: string]: unknown;
};
}
}

Sentry.init({
environment: 'qa', // dynamic sampling bias to keep transactions
dsn: window.ENV.SENTRY_DSN,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,6 @@ function isBotRequest(userAgent: string | null) {
return isbotModule.isbot(userAgent);
}

// isbot < 3.8.0
if ('default' in isbotModule && typeof isbotModule.default === 'function') {
return isbotModule.default(userAgent);
}

return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export function ErrorBoundary() {
}

function App() {
const { ENV } = useLoaderData();
const { ENV } = useLoaderData() as { ENV: { SENTRY_DSN: string } };

return (
<html lang="en">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const loader: LoaderFunction = async ({ params: { id } }) => {
};

export default function LoaderError() {
const data = useLoaderData();
const data = useLoaderData() as { test?: string };

return (
<div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"sideEffects": false,
"type": "module",
"scripts": {
"build": "remix vite:build",
"build": "remix vite:build && pnpm typecheck",
"dev": "node ./server.mjs",
"lint": "eslint --ignore-path .gitignore --cache --cache-location ./node_modules/.cache/eslint .",
"start": "cross-env NODE_ENV=production node ./server.mjs",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { waitForError } from '@sentry-internal/test-utils';

test('Sends a loader error to Sentry', async ({ page }) => {
const loaderErrorPromise = waitForError('create-remix-app-express', errorEvent => {
return errorEvent.exception.values[0].value === 'Loader Error';
return errorEvent?.exception?.values?.[0]?.value === 'Loader Error';
});

await page.goto('/loader-error');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ test('Sends parameterized transaction name to Sentry', async ({ page }) => {

test('Sends form data with action span', async ({ page }) => {
const formdataActionTransaction = waitForTransaction('create-remix-app-express', transactionEvent => {
return transactionEvent?.spans?.some(span => span.data && span.data['code.function'] === 'action');
return transactionEvent?.spans?.some(span => span.data && span.data['code.function'] === 'action') || false;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

q: What does adding || false do here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

waitForTransaction expects a function returning a boolean, after adding optional chaining, it became boolean | undefined. So, making it false in such cases

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah... of course 😅 thanks

});

await page.goto('/action-formdata');
Expand All @@ -34,31 +34,31 @@ test('Sends form data with action span', async ({ page }) => {

await page.locator('button[type=submit]').click();

const actionSpan = (await formdataActionTransaction).spans.find(
const actionSpan = (await formdataActionTransaction)?.spans?.find(
span => span.data && span.data['code.function'] === 'action',
);

expect(actionSpan).toBeDefined();
expect(actionSpan.op).toBe('action.remix');
expect(actionSpan.data).toMatchObject({
expect(actionSpan?.op).toBe('action.remix');
expect(actionSpan?.data).toMatchObject({
'formData.text': 'test',
'formData.file': 'file.txt',
});
});

test('Sends a loader span to Sentry', async ({ page }) => {
const loaderTransactionPromise = waitForTransaction('create-remix-app-express', transactionEvent => {
return transactionEvent?.spans?.some(span => span.data && span.data['code.function'] === 'loader');
return transactionEvent?.spans?.some(span => span.data && span.data['code.function'] === 'loader') || false;
});

await page.goto('/');

const loaderSpan = (await loaderTransactionPromise).spans.find(
const loaderSpan = (await loaderTransactionPromise)?.spans?.find(
span => span.data && span.data['code.function'] === 'loader',
);

expect(loaderSpan).toBeDefined();
expect(loaderSpan.op).toBe('loader.remix');
expect(loaderSpan?.op).toBe('loader.remix');
});

test('Propagates trace when ErrorBoundary is triggered', async ({ page }) => {
Expand All @@ -83,9 +83,8 @@ test('Propagates trace when ErrorBoundary is triggered', async ({ page }) => {

const httpServerTraceId = httpServerTransaction.contexts?.trace?.trace_id;
const httpServerSpanId = httpServerTransaction.contexts?.trace?.span_id;
const loaderSpanId = httpServerTransaction.spans.find(
span => span.data && span.data['code.function'] === 'loader',
)?.span_id;
const loaderSpanId = httpServerTransaction?.spans?.find(span => span.data && span.data['code.function'] === 'loader')
?.span_id;

const pageLoadTraceId = pageloadTransaction.contexts?.trace?.trace_id;
const pageLoadSpanId = pageloadTransaction.contexts?.trace?.span_id;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"include": ["env.d.ts", "**/*.ts", "**/*.tsx"],
"include": ["env.d.ts", "./app/**/*.ts", "./app/**/*.tsx"],
"compilerOptions": {
"lib": ["DOM", "DOM.Iterable", "ES2022"],
"isolatedModules": true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@
* For more information, see https://remix.run/file-conventions/entry.client
*/

// Extend the Window interface to include ENV
declare global {
interface Window {
ENV: {
SENTRY_DSN: string;
[key: string]: unknown;
};
}
}

import { RemixBrowser, useLocation, useMatches } from '@remix-run/react';
import * as Sentry from '@sentry/remix';
import { StrictMode, startTransition, useEffect } from 'react';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export function ErrorBoundary() {
}

function App() {
const { ENV } = useLoaderData();
const { ENV } = useLoaderData() as { ENV: { SENTRY_DSN: string } };

return (
<html lang="en">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const loader: LoaderFunction = async ({ params: { id } }) => {
};

export default function LoaderError() {
const data = useLoaderData();
const data = useLoaderData() as { test?: string };

return (
<div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"private": true,
"sideEffects": false,
"scripts": {
"build": "remix build",
"build": "remix build && pnpm typecheck",
"dev": "remix dev",
"start": "NODE_OPTIONS='--require=./instrument.server.cjs' remix-serve build/index.js",
"typecheck": "tsc",
Expand All @@ -12,24 +12,28 @@
},
"dependencies": {
"@sentry/remix": "latest || *",
"@remix-run/css-bundle": "2.16.5",
"@remix-run/node": "2.16.5",
"@remix-run/react": "2.16.5",
"@remix-run/serve": "2.16.5",
"@remix-run/css-bundle": "2.16.7",
"@remix-run/node": "2.16.7",
"@remix-run/react": "2.16.7",
"@remix-run/serve": "2.16.7",
"isbot": "^3.6.8",
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
"devDependencies": {
"@playwright/test": "~1.50.0",
"@sentry-internal/test-utils": "link:../../../test-utils",
"@remix-run/dev": "2.16.5",
"@remix-run/eslint-config": "2.16.5",
"@remix-run/dev": "2.16.7",
"@remix-run/eslint-config": "2.16.7",
"@sentry/core": "latest || *",
"@types/react": "^18.0.35",
"@types/react-dom": "^18.0.11",
"@types/react": "^18.2.64",
"@types/react-dom": "^18.2.34",
"@types/prop-types": "15.7.7",
"eslint": "^8.38.0",
"typescript": "^5.0.4"
"typescript": "^5.1.6"
},
"resolutions": {
"@types/react": "18.2.22"
},
"volta": {
"extends": "../../package.json"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"include": ["remix.env.d.ts", "**/*.ts", "**/*.tsx"],
"include": ["remix.env.d.ts", "./app/**/*.ts", "./app/**/*.tsx"],
"exclude": ["node_modules", "build"],
"compilerOptions": {
"lib": ["DOM", "DOM.Iterable", "ES2019"],
"isolatedModules": true,
Expand All @@ -10,6 +11,7 @@
"target": "ES2019",
"strict": true,
"allowJs": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"baseUrl": ".",
"paths": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import { createPagesFunctionHandler } from '@remix-run/cloudflare-pages';
import { sentryPagesPlugin } from '@sentry/cloudflare';
import {createPagesFunctionHandler} from '@remix-run/cloudflare-pages';
import {sentryPagesPlugin} from '@sentry/cloudflare';

// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore - the server build file is generated by `remix vite:build`
// eslint-disable-next-line import/no-unresolved
import * as build from '../build/server';

export const onRequest = [
context => sentryPagesPlugin({ dsn: context.env.E2E_TEST_DSN, tracesSampleRate: 1.0 })(context),
createPagesFunctionHandler({ build }),
(context: EventPluginContext<any, any, any, any>) =>
sentryPagesPlugin({
dsn: context.env.E2E_TEST_DSN,
tracesSampleRate: 1.0,
})(context),
createPagesFunctionHandler({build}),
];

This file was deleted.

Loading
Loading