Skip to content

Commit a6c384c

Browse files
authored
test: Add browser based scenarios (#4100)
1 parent af0e436 commit a6c384c

File tree

38 files changed

+1150
-0
lines changed

38 files changed

+1150
-0
lines changed

.eslintrc.js

+9
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,14 @@ module.exports = {
3131
'jsdoc/require-jsdoc': 'off',
3232
},
3333
},
34+
{
35+
files: ["scenarios/**"],
36+
parserOptions: {
37+
sourceType: "module",
38+
},
39+
rules: {
40+
"no-console": "off",
41+
},
42+
},
3443
],
3544
};

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ coverage/
1111
scratch/
1212
*.pyc
1313
*.tsbuildinfo
14+
scenarios/*/dist/
1415

1516
# logs
1617
yarn-error.log

packages/eslint-config-sdk/src/index.js

+7
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,13 @@ module.exports = {
186186
ecmaVersion: 2018,
187187
},
188188
},
189+
{
190+
// Configuration for jsx and tsx files
191+
files: ['*.tsx', '*.jsx', '*.test.tsx', '*.test.jsx'],
192+
parserOptions: {
193+
jsx: true,
194+
},
195+
},
189196
],
190197

191198
rules: {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { init, captureException } from "@sentry/browser";
2+
3+
init({
4+
dsn: "https://[email protected]/0000000",
5+
});
6+
7+
captureException(new Error("error here!"));
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"name": "basic-capture-exception",
3+
"private": true,
4+
"version": "0.0.0"
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { init, captureMessage } from "@sentry/browser";
2+
3+
init({
4+
dsn: "https://[email protected]/0000000",
5+
});
6+
7+
captureMessage("this is a message");
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"name": "basic-capture-message",
3+
"private": true,
4+
"version": "0.0.0"
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { init } from "@sentry/browser";
2+
3+
class CustomIntegration {
4+
static id = 'CustomIntegration';
5+
6+
name = CustomIntegration.id;
7+
options = undefined;
8+
9+
constructor(options) {
10+
this.options = options;
11+
}
12+
13+
setupOnce(addGlobalEventProcessor, getCurrentHub) {
14+
addGlobalEventProcessor(event => event);
15+
const hub = getCurrentHub();
16+
hub.captureMessage(options.name);
17+
}
18+
}
19+
20+
init({
21+
dsn: "https://[email protected]/0000000",
22+
integrations: [new CustomIntegration()],
23+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"name": "basic-custom-integration",
3+
"private": true,
4+
"version": "0.0.0"
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { init, Transports } from "@sentry/browser";
2+
3+
class CustomTransport extends Transports.BaseTransport {
4+
constructor(options) {
5+
super(options);
6+
}
7+
8+
sendEvent(event) {
9+
console.log("Sending Event");
10+
return super.sendEvent(event);
11+
}
12+
13+
sendSession(session) {
14+
console.log("Sending Session");
15+
return super.sendSession(session);
16+
}
17+
}
18+
19+
init({
20+
dsn: "https://[email protected]/0000000",
21+
transport: CustomTransport
22+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"name": "basic-custom-transport",
3+
"private": true,
4+
"version": "0.0.0"
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { init } from "@sentry/browser";
2+
3+
init({
4+
dsn: "https://[email protected]/0000000",
5+
sendClientReports: false,
6+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"name": "basic-no-client-reports",
3+
"private": true,
4+
"version": "0.0.0"
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { init } from "@sentry/browser";
2+
3+
init({
4+
dsn: "https://[email protected]/0000000",
5+
defaultIntegrations: false,
6+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"name": "basic-no-default-integrations",
3+
"private": true,
4+
"version": "0.0.0"
5+
}
+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { init } from "@sentry/browser";
2+
3+
init();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"name": "basic-no-dsn",
3+
"private": true,
4+
"version": "0.0.0"
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { init } from "@sentry/browser";
2+
3+
init({
4+
dsn: "https://[email protected]/0000000",
5+
release: "[email protected]",
6+
autoSessionTracking: false,
7+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"name": "basic-no-sessions",
3+
"private": true,
4+
"version": "0.0.0"
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { init } from "@sentry/browser";
2+
3+
init({
4+
dsn: "https://[email protected]/0000000",
5+
debug: true,
6+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"name": "basic-with-debug",
3+
"private": true,
4+
"version": "0.0.0"
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { init } from "@sentry/browser";
2+
3+
init({
4+
dsn: "https://[email protected]/0000000",
5+
release: "[email protected]",
6+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"name": "basic-with-sessions",
3+
"private": true,
4+
"version": "0.0.0"
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { init } from "@sentry/browser";
2+
3+
init({
4+
dsn: "https://[email protected]/0000000",
5+
tunnel: "/errors",
6+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"name": "basic-with-tunnel",
3+
"private": true,
4+
"version": "0.0.0"
5+
}

scenarios/browser/basic/index.js

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { init } from "@sentry/browser";
2+
3+
init({
4+
dsn: "https://[email protected]/0000000",
5+
});

scenarios/browser/basic/package.json

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"name": "basic",
3+
"private": true,
4+
"version": "0.0.0"
5+
}
+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { init } from "@sentry/nextjs/esm/index.client";
2+
3+
init({
4+
dsn: "https://[email protected]/0000000",
5+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"name": "nextjs-client",
3+
"private": true,
4+
"version": "0.0.0",
5+
"dependencies": {
6+
"next": "12"
7+
}
8+
}

scenarios/browser/package.json

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"name": "scenarios-browser",
3+
"main": "webpack.js",
4+
"private": true,
5+
"version": "0.0.0",
6+
"devDependencies": {
7+
"html-webpack-plugin": "^5.5.0",
8+
"webpack": "^5.62.1",
9+
"webpack-bundle-analyzer": "^4.5.0"
10+
}
11+
}

scenarios/browser/perf-auto/index.js

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { init } from "@sentry/browser";
2+
import { Integrations } from "@sentry/tracing";
3+
4+
init({
5+
dsn: "https://[email protected]/0000000",
6+
integrations: [new Integrations.BrowserTracing()],
7+
tracesSampleRate: 1.0,
8+
});
+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"name": "perf-auto",
3+
"private": true,
4+
"version": "0.0.0"
5+
}
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { init, startTransaction } from "@sentry/browser";
2+
import "@sentry/tracing";
3+
4+
init({
5+
dsn: "https://[email protected]/0000000",
6+
tracesSampleRate: 1.0,
7+
});
8+
9+
const transaction = startTransaction({ op: "task", name: "Important Stuff" });
10+
11+
setTimeout(() => {
12+
transaction.finish();
13+
}, 1000);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"name": "perf-manual",
3+
"private": true,
4+
"version": "0.0.0"
5+
}

scenarios/browser/react/index.js

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import React from "react";
2+
import ReactDOM from "react-dom"
3+
import { init } from "@sentry/react";
4+
5+
init({
6+
dsn: "https://[email protected]/0000000",
7+
});
8+
9+
class Hello extends React.Component {
10+
render() {
11+
return React.createElement('div', null, `Hello ${this.props.toWhat}`);
12+
}
13+
}
14+
15+
ReactDOM.render(
16+
React.createElement(Hello, { toWhat: 'World' }, null),
17+
// eslint-disable-next-line no-undef
18+
document.getElementById('root')
19+
);

scenarios/browser/react/package.json

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"name": "react",
3+
"private": true,
4+
"version": "0.0.0",
5+
"dependencies": {
6+
"react": "17",
7+
"react-dom": "17"
8+
}
9+
}

scenarios/browser/webpack.js

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
const path = require('path');
2+
const { promises } = require('fs');
3+
4+
const webpack = require('webpack');
5+
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
6+
const HtmlWebpackPlugin = require('html-webpack-plugin');
7+
8+
async function init(scenario) {
9+
if (!hasCurrentScenario(scenario)) {
10+
throw new Error(`Scenario "${scenario}" does not exist`);
11+
}
12+
13+
console.log(`Bundling scenario: ${scenario}`);
14+
15+
await runWebpack(scenario);
16+
}
17+
18+
async function runWebpack(scenario) {
19+
const alias = await generateAlias();
20+
21+
webpack(
22+
{
23+
mode: 'production',
24+
entry: path.resolve(__dirname, scenario),
25+
output: {
26+
filename: 'main.js',
27+
path: path.resolve(__dirname, 'dist', scenario),
28+
},
29+
plugins: [new BundleAnalyzerPlugin({ analyzerMode: 'static' }), new HtmlWebpackPlugin()],
30+
resolve: {
31+
alias,
32+
},
33+
},
34+
(err, stats) => {
35+
if (err || stats.hasErrors()) {
36+
console.log(err);
37+
}
38+
console.log('DONE', stats);
39+
},
40+
);
41+
}
42+
43+
const PACKAGE_PATH = '../../packages';
44+
45+
/**
46+
* Generate webpack aliases based on packages in monorepo
47+
* Example of an alias: '@sentry/serverless': 'path/to/sentry-javascript/packages/serverless',
48+
*/
49+
async function generateAlias() {
50+
const dirents = await promises.readdir(PACKAGE_PATH);
51+
52+
return Object.fromEntries(
53+
await Promise.all(
54+
dirents.map(async d => {
55+
const packageJSON = JSON.parse(await promises.readFile(path.resolve(PACKAGE_PATH, d, 'package.json')));
56+
return [packageJSON['name'], path.resolve(PACKAGE_PATH, d)];
57+
}),
58+
),
59+
);
60+
}
61+
62+
async function hasCurrentScenario(scenario) {
63+
const dirents = await promises.readdir(__dirname, { withFileTypes: true });
64+
return dirents.filter(dir => dir.isDirectory()).find(dir => dir.name === scenario);
65+
}
66+
67+
const CURRENT_SCENARIO = 'basic';
68+
69+
init(CURRENT_SCENARIO);

0 commit comments

Comments
 (0)