Skip to content

Commit 17b12e1

Browse files
authored
Next.js integration tests for Server and Browser (#3632)
1 parent d712e13 commit 17b12e1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+3977
-3
lines changed

packages/nextjs/.eslintrc.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ module.exports = {
99
ecmaVersion: 2018,
1010
},
1111
extends: ['@sentry-internal/sdk'],
12-
ignorePatterns: ['build/**', 'dist/**', 'esm/**', 'examples/**', 'scripts/**'],
12+
ignorePatterns: ['build/**', 'dist/**', 'esm/**', 'examples/**', 'scripts/**', 'test/integration/**'],
1313
overrides: [
1414
{
1515
files: ['*.ts', '*.tsx', '*.d.ts'],

packages/nextjs/package.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,13 @@
5252
"fix": "run-s fix:eslint fix:prettier",
5353
"fix:eslint": "eslint . --format stylish --fix",
5454
"fix:prettier": "prettier --write \"{src,test}/**/*.ts\"",
55-
"test": "jest",
55+
"test": "run-s test:unit test:integration",
5656
"test:watch": "jest --watch",
57+
"test:unit": "jest",
58+
"test:integration": "run-s test:integration:build test:integration:server test:integration:client",
59+
"test:integration:build": "cd test/integration && yarn && yarn build && cd ../..",
60+
"test:integration:server": "node test/integration/test/server.js --silent",
61+
"test:integration:client": "node test/integration/test/client.js --silent",
5762
"pack": "npm pack",
5863
"vercel:branch": "source vercel/set-up-branch-for-test-app-use.sh",
5964
"vercel:project": "source vercel/make-project-use-current-branch.sh"

packages/nextjs/src/performance/client.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
/* eslint-disable @typescript-eslint/no-explicit-any */
2+
13
import { Primitive, Transaction, TransactionContext } from '@sentry/types';
24
import { fill, getGlobalObject, stripUrlQueryAndFragment } from '@sentry/utils';
35
import { default as Router } from 'next/router';
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2+
3+
# dependencies
4+
/node_modules
5+
/.pnp
6+
.pnp.js
7+
8+
# testing
9+
/coverage
10+
11+
# next.js
12+
/.next/
13+
/out/
14+
15+
# production
16+
/build
17+
18+
# misc
19+
.DS_Store
20+
*.pem
21+
22+
# debug
23+
npm-debug.log*
24+
yarn-debug.log*
25+
yarn-error.log*
26+
27+
# local env files
28+
.env.local
29+
.env.development.local
30+
.env.test.local
31+
.env.production.local
32+
33+
# vercel
34+
.vercel
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import React, { ReactNode } from 'react';
2+
import Link from 'next/link';
3+
import Head from 'next/head';
4+
5+
type Props = {
6+
children?: ReactNode;
7+
title?: string;
8+
};
9+
10+
const Layout = ({ children, title = 'This is the default title' }: Props) => (
11+
<div>
12+
<Head>
13+
<title>{title}</title>
14+
<meta charSet="utf-8" />
15+
<meta name="viewport" content="initial-scale=1.0, width=device-width" />
16+
</Head>
17+
<header>
18+
<nav>
19+
<Link href="/">
20+
<a>Home</a>
21+
</Link>{' '}
22+
|{' '}
23+
<Link href="/about">
24+
<a>About</a>
25+
</Link>{' '}
26+
|{' '}
27+
<Link href="/users">
28+
<a>Users List</a>
29+
</Link>{' '}
30+
| <a href="/api/users">Users API</a>
31+
</nav>
32+
</header>
33+
{children}
34+
<footer>
35+
<hr />
36+
<span>I'm here to stay (Footer)</span>
37+
</footer>
38+
</div>
39+
);
40+
41+
export default Layout;
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import * as React from 'react';
2+
import ListItem from './ListItem';
3+
import { User } from '../interfaces';
4+
5+
type Props = {
6+
items: User[];
7+
};
8+
9+
const List = ({ items }: Props) => (
10+
<ul>
11+
{items.map(item => (
12+
<li key={item.id}>
13+
<ListItem data={item} />
14+
</li>
15+
))}
16+
</ul>
17+
);
18+
19+
export default List;
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import * as React from 'react';
2+
3+
import { User } from '../interfaces';
4+
5+
type ListDetailProps = {
6+
item: User;
7+
};
8+
9+
const ListDetail = ({ item: user }: ListDetailProps) => (
10+
<div>
11+
<h1>Detail for {user.name}</h1>
12+
<p>ID: {user.id}</p>
13+
</div>
14+
);
15+
16+
export default ListDetail;
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import React from 'react';
2+
import Link from 'next/link';
3+
4+
import { User } from '../interfaces';
5+
6+
type Props = {
7+
data: User;
8+
};
9+
10+
const ListItem = ({ data }: Props) => (
11+
<Link href="/users/[id]" as={`/users/${data.id}`}>
12+
<a>
13+
{data.id}: {data.name}
14+
</a>
15+
</Link>
16+
);
17+
18+
export default ListItem;
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// You can include shared interfaces/types in a separate file
2+
// and then use them in any component by importing them. For
3+
// example, to import the interface below do:
4+
//
5+
// import { User } from 'path/to/interfaces';
6+
7+
export type User = {
8+
id: number;
9+
name: string;
10+
};
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/// <reference types="next" />
2+
/// <reference types="next/types/global" />

0 commit comments

Comments
 (0)