Skip to content

Commit 280aee2

Browse files
committed
add test
1 parent 337935a commit 280aee2

File tree

17 files changed

+1535
-5
lines changed

17 files changed

+1535
-5
lines changed

packages/nextjs/.eslintrc.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,19 @@ module.exports = {
1818
project: ['../../tsconfig.dev.json'],
1919
},
2020
},
21+
{
22+
files: ['test/buildProcess/**'],
23+
parserOptions: {
24+
sourceType: 'module',
25+
},
26+
plugins: ['react'],
27+
extends: ['../../.eslintrc.js', 'plugin:react/recommended'],
28+
rules: {
29+
// Prop types validation is not useful in test environments
30+
'react/prop-types': 'off',
31+
// Nextjs takes care of including react, so we don't explicitly need to
32+
'react/react-in-jsx-scope': 'off',
33+
},
34+
},
2135
],
2236
};

packages/nextjs/jest.config.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,8 @@
1-
module.exports = require('../../jest/jest.config.js');
1+
const baseConfig = require('../../jest/jest.config.js');
2+
3+
module.exports = {
4+
...baseConfig,
5+
// This prevents the build tests from running when unit tests run. (If they do, they fail, because the build being
6+
// tested hasn't necessarily run yet.)
7+
testPathIgnorePatterns: ['<rootDir>/test/buildProcess/'],
8+
};

packages/nextjs/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
"devDependencies": {
3535
"@sentry/nextjs": "7.20.1",
3636
"@types/webpack": "^4.41.31",
37+
"eslint-plugin-react": "^7.31.11",
3738
"next": "10.1.3"
3839
},
3940
"peerDependencies": {
@@ -65,7 +66,8 @@
6566
"lint:eslint": "eslint . --cache --cache-location '../../eslintcache/' --format stylish",
6667
"lint:prettier": "prettier --check \"{src,test,scripts}/**/*.ts\"",
6768
"test": "run-s test:unit",
68-
"test:all": "run-s test:unit test:integration",
69+
"test:all": "run-s test:unit test:integration test:build",
70+
"test:build": "yarn ts-node test/buildProcess/runTest.ts",
6971
"test:unit": "jest",
7072
"test:integration": "test/run-integration-tests.sh && yarn test:types",
7173
"test:types": "cd test/types && yarn test",
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// In order to not have the build tests run as part of the unit test suite, we exclude them in
2+
// `packages/nextjs/jest.config.js`. The resets the test-matching regex so that when `runTest.ts` calls `yarn jest` with
3+
// ths config file, jest will find the tests in `tests`.
4+
module.exports = require('../../../../jest/jest.config.js');
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/* eslint-disable no-console */
2+
import * as childProcess from 'child_process';
3+
import * as path from 'path';
4+
import { sync as rimrafSync } from 'rimraf';
5+
6+
const TEST_APP_DIR = 'test/buildProcess/testApp';
7+
8+
/**
9+
* Run the given shell command, piping the shell process's `stdin`, `stdout`, and `stderr` to that of the current
10+
* process if this script is run with the `--debug` flag. Returns contents of `stdout`.
11+
*/
12+
function run(cmd: string, options?: childProcess.ExecSyncOptions): string {
13+
return String(
14+
childProcess.execSync(cmd, {
15+
stdio: process.argv.includes('--debug') ? 'inherit' : 'ignore',
16+
...options,
17+
}),
18+
);
19+
}
20+
21+
// Note: We use a file dependency for the SDK, rather than linking it, because if it's linked, nextjs rolls the entire
22+
// SDK and all of its dependencies into a bundle, making it impossible to tell (from the NFT file, at least) what's
23+
// being included.
24+
console.log('Installing dependencies...');
25+
process.chdir(TEST_APP_DIR);
26+
rimrafSync('node_modules');
27+
run('yarn');
28+
29+
console.log('Building app...');
30+
rimrafSync('.next');
31+
run('yarn build');
32+
33+
console.log('App built. Running tests...');
34+
process.chdir('..');
35+
const jestConfigFile = path.resolve(process.cwd(), 'jest.config.js');
36+
try {
37+
// We have to specify the config file explicitly because otherwise it'll use the one at the root level of
38+
// `packages/nextjs`, since that's where the closest `package.json` file is
39+
run(`yarn jest --config ${jestConfigFile} tests`, { stdio: 'inherit' });
40+
} catch (err) {
41+
console.log('\nNot all build process tests passed.');
42+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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+
.pnpm-debug.log*
27+
28+
# local env files
29+
.env*.local
30+
31+
# vercel
32+
.vercel
33+
34+
# typescript
35+
*.tsbuildinfo
36+
next-env.d.ts
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// const nextConfig = {
2+
// }
3+
//
4+
// module.exports = nextConfig
5+
6+
const { withSentryConfig } = require('@sentry/nextjs');
7+
8+
const moduleExports = {
9+
reactStrictMode: true,
10+
swcMinify: true,
11+
eslint: {
12+
ignoreDuringBuilds: true,
13+
},
14+
sentry: {
15+
// Suppress the warning message from `handleSourcemapHidingOptionWarning` in `src/config/webpack.ts`
16+
// TODO (v8): This can come out in v8, because this option will get a default value
17+
hideSourceMaps: false,
18+
},
19+
};
20+
const SentryWebpackPluginOptions = {
21+
dryRun: true,
22+
silent: true,
23+
};
24+
25+
module.exports = withSentryConfig(moduleExports, SentryWebpackPluginOptions);
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"name": "testapp",
3+
"version": "0.1.0",
4+
"private": true,
5+
"scripts": {
6+
"dev": "next dev",
7+
"build": "next build",
8+
"start": "next start",
9+
"lint": "next lint"
10+
},
11+
"dependencies": {
12+
"@sentry/nextjs": "file:../../../",
13+
"@vercel/nft": "latest",
14+
"next": "13.0.1",
15+
"react": "18.2.0",
16+
"react-dom": "18.2.0"
17+
}
18+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import * as Sentry from '@sentry/nextjs';
2+
3+
Sentry.init({
4+
dsn: 'https://[email protected]/1337',
5+
});
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import * as Sentry from '@sentry/nextjs';
2+
3+
Sentry.init({
4+
dsn: 'https://[email protected]/1337',
5+
});
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"dogs": "are great"
3+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
function MyApp({ Component, pageProps }) {
2+
return <Component {...pageProps} />;
3+
}
4+
5+
export default MyApp;
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import * as fs from 'fs';
2+
import * as path from 'path';
3+
4+
export default function handler(req, res) {
5+
const dogData = JSON.parse(fs.readFileSync(path.resolve('../../dogs.json')));
6+
dogData.test = 'something';
7+
res.status(200).json(dogData);
8+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export default function Home() {
2+
return <div>This is the homepage.</div>;
3+
}

0 commit comments

Comments
 (0)