-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(remix): Add a boilerplate for Remix SDK integration tests.
- Loading branch information
1 parent
f1cfc70
commit bcd82bd
Showing
18 changed files
with
7,310 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"extends": ["@remix-run/eslint-config", "@remix-run/eslint-config/node"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
node_modules | ||
|
||
/.cache | ||
/build | ||
/public/build | ||
.env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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://[email protected]/1337', | ||
tracesSampleRate: 1, | ||
integrations: [ | ||
new Sentry.BrowserTracing({ | ||
routingInstrumentation: Sentry.remixRouterInstrumentation(useEffect, useLocation, useMatches), | ||
}), | ||
], | ||
}); | ||
|
||
hydrate(<RemixBrowser />, document); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
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://[email protected]/1337', | ||
tracesSampleRate: 1, | ||
}); | ||
|
||
export default function handleRequest( | ||
request: Request, | ||
responseStatusCode: number, | ||
responseHeaders: Headers, | ||
remixContext: EntryContext, | ||
) { | ||
let markup = renderToString(<RemixServer context={remixContext} url={request.url} />); | ||
|
||
responseHeaders.set('Content-Type', 'text/html'); | ||
|
||
return new Response('<!DOCTYPE html>' + markup, { | ||
status: responseStatusCode, | ||
headers: responseHeaders, | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import type { MetaFunction } from '@remix-run/node'; | ||
import { Links, LiveReload, Meta, Outlet, Scripts, ScrollRestoration } from '@remix-run/react'; | ||
import { withSentry } from '@sentry/remix'; | ||
|
||
export const meta: MetaFunction = () => ({ | ||
charset: 'utf-8', | ||
title: 'New Remix App', | ||
viewport: 'width=device-width,initial-scale=1', | ||
}); | ||
|
||
function App() { | ||
return ( | ||
<html lang="en"> | ||
<head> | ||
<Meta /> | ||
<Links /> | ||
</head> | ||
<body> | ||
<Outlet /> | ||
<ScrollRestoration /> | ||
<Scripts /> | ||
<LiveReload /> | ||
</body> | ||
</html> | ||
); | ||
} | ||
|
||
export default withSentry(App); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export default function Index() { | ||
return ( | ||
<div> | ||
<h1>Remix Integration Tests Home</h1> | ||
</div> | ||
); | ||
} |
20 changes: 20 additions & 0 deletions
20
packages/remix/test/integration/app/routes/loader-json-response/$id.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { json, LoaderFunction } from '@remix-run/node'; | ||
import { useLoaderData } from '@remix-run/react'; | ||
|
||
type LoaderData = { id: string }; | ||
|
||
export const loader: LoaderFunction = async ({ params: { id } }) => { | ||
return json({ | ||
id, | ||
}); | ||
}; | ||
|
||
export default function LoaderJSONResponse() { | ||
const data = useLoaderData<LoaderData>(); | ||
|
||
return ( | ||
<div> | ||
<h1>{data.id}</h1> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
const baseConfig = require('../../jest.config.js'); | ||
|
||
module.exports = { | ||
globalSetup: '<rootDir>/test/server/utils/run-server.ts', | ||
...baseConfig, | ||
testMatch: ['**/*.test.ts'], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
{ | ||
"private": true, | ||
"sideEffects": false, | ||
"scripts": { | ||
"build": "remix build", | ||
"dev": "remix dev", | ||
"start": "remix-serve build", | ||
"test": "yarn build && yarn test:client && yarn test:server", | ||
"test:client": "echo \"TODO\"", | ||
"test:server": "jest" | ||
}, | ||
"dependencies": { | ||
"@remix-run/express": "^1.6.5", | ||
"@remix-run/node": "^1.6.5", | ||
"@remix-run/react": "^1.6.5", | ||
"@remix-run/serve": "^1.6.5", | ||
"@sentry/remix": "file:../..", | ||
"react": "^17.0.2", | ||
"react-dom": "^17.0.2" | ||
}, | ||
"devDependencies": { | ||
"@remix-run/dev": "^1.6.5", | ||
"@remix-run/eslint-config": "^1.6.5", | ||
"@types/react": "^17.0.47", | ||
"@types/react-dom": "^17.0.17", | ||
"eslint": "^8.20.0", | ||
"typescript": "^4.7.4" | ||
}, | ||
"resolutions": { | ||
"@sentry/browser": "file:../../../browser", | ||
"@sentry/core": "file:../../../core", | ||
"@sentry/hub": "file:../../../hub", | ||
"@sentry/integrations": "file:../../../integrations", | ||
"@sentry/node": "file:../../../node", | ||
"@sentry/react": "file:../../../react", | ||
"@sentry/tracing": "file:../../../tracing", | ||
"@sentry/types": "file:../../../types", | ||
"@sentry/utils": "file:../../../utils" | ||
}, | ||
"engines": { | ||
"node": ">=14" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
/** @type {import('@remix-run/dev').AppConfig} */ | ||
module.exports = { | ||
appDirectory: 'app', | ||
assetsBuildDirectory: 'public/build', | ||
serverBuildPath: 'build/index.js', | ||
publicPath: '/build/', | ||
}; |
22 changes: 22 additions & 0 deletions
22
packages/remix/test/integration/test/server/loader.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { assertSentryTransaction, getEnvelopeRequest } from '../../../../../node-integration-tests/utils'; | ||
|
||
describe('Remix API Loaders', () => { | ||
it('correctly instruments a Remix API loader', async () => { | ||
const url = 'http://localhost:3000/loader-json-response/123123'; | ||
const envelope = await getEnvelopeRequest(url); | ||
const transaction = envelope[2]; | ||
|
||
assertSentryTransaction(transaction, { | ||
spans: [ | ||
{ | ||
description: url, | ||
op: 'remix.server.loader', | ||
}, | ||
{ | ||
description: url, | ||
op: 'remix.server.documentRequest', | ||
}, | ||
], | ||
}); | ||
}); | ||
}); |
17 changes: 17 additions & 0 deletions
17
packages/remix/test/integration/test/server/utils/run-server.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import express, { Express } from 'express'; | ||
import { createRequestHandler } from '@remix-run/express'; | ||
|
||
/** | ||
* Runs a test server | ||
*/ | ||
function runServer(testDir: string): void { | ||
const app = express(); | ||
|
||
app.all('*', createRequestHandler({ build: require('../../../build') })); | ||
|
||
app.listen(3000); | ||
|
||
// TODO: Finish app after tests | ||
} | ||
|
||
export default runServer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"include": ["remix.env.d.ts", "**/*.ts", "**/*.tsx"], | ||
"compilerOptions": { | ||
"lib": ["DOM", "DOM.Iterable", "ES2019"], | ||
"isolatedModules": true, | ||
"esModuleInterop": true, | ||
"jsx": "react-jsx", | ||
"moduleResolution": "node", | ||
"resolveJsonModule": true, | ||
"target": "ES2019", | ||
"strict": true, | ||
"allowJs": true, | ||
"forceConsistentCasingInFileNames": true, | ||
"baseUrl": ".", | ||
"paths": { | ||
"~/*": ["./app/*"] | ||
}, | ||
"noEmit": true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"extends": "./tsconfig.json", | ||
|
||
"include": ["suites/**/*.ts"], | ||
|
||
"compilerOptions": { | ||
// should include all types from `./tsconfig.json` plus types for all test frameworks used | ||
"types": ["node", "jest"] | ||
|
||
// other package-specific, test-specific options | ||
} | ||
} |
Oops, something went wrong.