Skip to content

Commit bcd82bd

Browse files
committed
test(remix): Add a boilerplate for Remix SDK integration tests.
1 parent f1cfc70 commit bcd82bd

File tree

18 files changed

+7310
-1
lines changed

18 files changed

+7310
-1
lines changed

.github/workflows/build.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -571,3 +571,38 @@ jobs:
571571
run: |
572572
cd packages/node-integration-tests
573573
yarn test
574+
575+
job_remix_integration_tests:
576+
name: Remix SDK Integration Tests (${{ matrix.node }})
577+
needs: [job_get_metadata, job_build]
578+
runs-on: ubuntu-latest
579+
timeout-minutes: 10
580+
continue-on-error: true
581+
strategy:
582+
matrix:
583+
node: [14, 16, 18]
584+
steps:
585+
- name: Check out current commit (${{ needs.job_get_metadata.outputs.commit_label }})
586+
uses: actions/checkout@v2
587+
with:
588+
ref: ${{ env.HEAD_COMMIT }}
589+
- name: Set up Node
590+
uses: actions/setup-node@v1
591+
with:
592+
node-version: ${{ matrix.node }}
593+
- name: Check dependency cache
594+
uses: actions/cache@v2
595+
with:
596+
path: ${{ env.CACHED_DEPENDENCY_PATHS }}
597+
key: ${{ needs.job_build.outputs.dependency_cache_key }}
598+
- name: Check build cache
599+
uses: actions/cache@v2
600+
with:
601+
path: ${{ env.CACHED_BUILD_PATHS }}
602+
key: ${{ env.BUILD_CACHE_KEY }}
603+
- name: Run integration tests
604+
env:
605+
NODE_VERSION: ${{ matrix.node }}
606+
run: |
607+
cd packages/remix
608+
yarn test:integration

packages/node-integration-tests/utils/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ export async function runServer(testDir: string, serverPath?: string, scenarioPa
161161
});
162162

163163
const server = app.listen(port, () => {
164-
resolve();
164+
resolve('');
165165
setTimeout(() => {
166166
server.close();
167167
}, 4000);

packages/remix/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
"lint:eslint": "eslint . --cache --cache-location '../../eslintcache/' --format stylish",
6161
"lint:prettier": "prettier --check \"{src,test,scripts}/**/*.ts\"",
6262
"test": "run-s test:unit",
63+
"test:integration": "cd test/integration && yarn test",
6364
"test:unit": "jest",
6465
"test:watch": "jest --watch"
6566
},
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"extends": ["@remix-run/eslint-config", "@remix-run/eslint-config/node"]
3+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
node_modules
2+
3+
/.cache
4+
/build
5+
/public/build
6+
.env
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { RemixBrowser, useLocation, useMatches } from '@remix-run/react';
2+
import { hydrate } from 'react-dom';
3+
import * as Sentry from '@sentry/remix';
4+
import { useEffect } from 'react';
5+
6+
Sentry.init({
7+
dsn: 'https://[email protected]/1337',
8+
tracesSampleRate: 1,
9+
integrations: [
10+
new Sentry.BrowserTracing({
11+
routingInstrumentation: Sentry.remixRouterInstrumentation(useEffect, useLocation, useMatches),
12+
}),
13+
],
14+
});
15+
16+
hydrate(<RemixBrowser />, document);
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import type { EntryContext } from '@remix-run/node';
2+
import { RemixServer } from '@remix-run/react';
3+
import { renderToString } from 'react-dom/server';
4+
import * as Sentry from '@sentry/remix';
5+
6+
Sentry.init({
7+
dsn: 'https://[email protected]/1337',
8+
tracesSampleRate: 1,
9+
});
10+
11+
export default function handleRequest(
12+
request: Request,
13+
responseStatusCode: number,
14+
responseHeaders: Headers,
15+
remixContext: EntryContext,
16+
) {
17+
let markup = renderToString(<RemixServer context={remixContext} url={request.url} />);
18+
19+
responseHeaders.set('Content-Type', 'text/html');
20+
21+
return new Response('<!DOCTYPE html>' + markup, {
22+
status: responseStatusCode,
23+
headers: responseHeaders,
24+
});
25+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import type { MetaFunction } from '@remix-run/node';
2+
import { Links, LiveReload, Meta, Outlet, Scripts, ScrollRestoration } from '@remix-run/react';
3+
import { withSentry } from '@sentry/remix';
4+
5+
export const meta: MetaFunction = () => ({
6+
charset: 'utf-8',
7+
title: 'New Remix App',
8+
viewport: 'width=device-width,initial-scale=1',
9+
});
10+
11+
function App() {
12+
return (
13+
<html lang="en">
14+
<head>
15+
<Meta />
16+
<Links />
17+
</head>
18+
<body>
19+
<Outlet />
20+
<ScrollRestoration />
21+
<Scripts />
22+
<LiveReload />
23+
</body>
24+
</html>
25+
);
26+
}
27+
28+
export default withSentry(App);
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export default function Index() {
2+
return (
3+
<div>
4+
<h1>Remix Integration Tests Home</h1>
5+
</div>
6+
);
7+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { json, LoaderFunction } from '@remix-run/node';
2+
import { useLoaderData } from '@remix-run/react';
3+
4+
type LoaderData = { id: string };
5+
6+
export const loader: LoaderFunction = async ({ params: { id } }) => {
7+
return json({
8+
id,
9+
});
10+
};
11+
12+
export default function LoaderJSONResponse() {
13+
const data = useLoaderData<LoaderData>();
14+
15+
return (
16+
<div>
17+
<h1>{data.id}</h1>
18+
</div>
19+
);
20+
}

0 commit comments

Comments
 (0)