Skip to content

test: Add browser based scenarios #4100

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
Dec 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,14 @@ module.exports = {
'jsdoc/require-jsdoc': 'off',
},
},
{
files: ["scenarios/**"],
parserOptions: {
sourceType: "module",
},
rules: {
"no-console": "off",
},
},
],
};
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ coverage/
scratch/
*.pyc
*.tsbuildinfo
scenarios/*/dist/

# logs
yarn-error.log
Expand Down
7 changes: 7 additions & 0 deletions packages/eslint-config-sdk/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,13 @@ module.exports = {
ecmaVersion: 2018,
},
},
{
// Configuration for jsx and tsx files
files: ['*.tsx', '*.jsx', '*.test.tsx', '*.test.jsx'],
parserOptions: {
jsx: true,
},
},
],

rules: {
Expand Down
7 changes: 7 additions & 0 deletions scenarios/browser/basic-capture-exception/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { init, captureException } from "@sentry/browser";

init({
dsn: "https://[email protected]/0000000",
});

captureException(new Error("error here!"));
5 changes: 5 additions & 0 deletions scenarios/browser/basic-capture-exception/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "basic-capture-exception",
"private": true,
"version": "0.0.0"
}
7 changes: 7 additions & 0 deletions scenarios/browser/basic-capture-message/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { init, captureMessage } from "@sentry/browser";

init({
dsn: "https://[email protected]/0000000",
});

captureMessage("this is a message");
5 changes: 5 additions & 0 deletions scenarios/browser/basic-capture-message/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "basic-capture-message",
"private": true,
"version": "0.0.0"
}
23 changes: 23 additions & 0 deletions scenarios/browser/basic-custom-integration/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { init } from "@sentry/browser";

class CustomIntegration {
static id = 'CustomIntegration';

name = CustomIntegration.id;
options = undefined;

constructor(options) {
this.options = options;
}

setupOnce(addGlobalEventProcessor, getCurrentHub) {
addGlobalEventProcessor(event => event);
const hub = getCurrentHub();
hub.captureMessage(options.name);
}
}

init({
dsn: "https://[email protected]/0000000",
integrations: [new CustomIntegration()],
});
5 changes: 5 additions & 0 deletions scenarios/browser/basic-custom-integration/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "basic-custom-integration",
"private": true,
"version": "0.0.0"
}
22 changes: 22 additions & 0 deletions scenarios/browser/basic-custom-transport/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { init, Transports } from "@sentry/browser";

class CustomTransport extends Transports.BaseTransport {
constructor(options) {
super(options);
}

sendEvent(event) {
console.log("Sending Event");
return super.sendEvent(event);
}

sendSession(session) {
console.log("Sending Session");
return super.sendSession(session);
}
}

init({
dsn: "https://[email protected]/0000000",
transport: CustomTransport
});
5 changes: 5 additions & 0 deletions scenarios/browser/basic-custom-transport/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "basic-custom-transport",
"private": true,
"version": "0.0.0"
}
6 changes: 6 additions & 0 deletions scenarios/browser/basic-no-client-reports/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { init } from "@sentry/browser";

init({
dsn: "https://[email protected]/0000000",
sendClientReports: false,
});
5 changes: 5 additions & 0 deletions scenarios/browser/basic-no-client-reports/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "basic-no-client-reports",
"private": true,
"version": "0.0.0"
}
6 changes: 6 additions & 0 deletions scenarios/browser/basic-no-default-integrations/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { init } from "@sentry/browser";

init({
dsn: "https://[email protected]/0000000",
defaultIntegrations: false,
});
5 changes: 5 additions & 0 deletions scenarios/browser/basic-no-default-integrations/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "basic-no-default-integrations",
"private": true,
"version": "0.0.0"
}
3 changes: 3 additions & 0 deletions scenarios/browser/basic-no-dsn/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { init } from "@sentry/browser";

init();
5 changes: 5 additions & 0 deletions scenarios/browser/basic-no-dsn/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "basic-no-dsn",
"private": true,
"version": "0.0.0"
}
7 changes: 7 additions & 0 deletions scenarios/browser/basic-no-sessions/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { init } from "@sentry/browser";

init({
dsn: "https://[email protected]/0000000",
release: "[email protected]",
autoSessionTracking: false,
});
5 changes: 5 additions & 0 deletions scenarios/browser/basic-no-sessions/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "basic-no-sessions",
"private": true,
"version": "0.0.0"
}
6 changes: 6 additions & 0 deletions scenarios/browser/basic-with-debug/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { init } from "@sentry/browser";

init({
dsn: "https://[email protected]/0000000",
debug: true,
});
5 changes: 5 additions & 0 deletions scenarios/browser/basic-with-debug/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "basic-with-debug",
"private": true,
"version": "0.0.0"
}
6 changes: 6 additions & 0 deletions scenarios/browser/basic-with-sessions/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { init } from "@sentry/browser";

init({
dsn: "https://[email protected]/0000000",
release: "[email protected]",
});
5 changes: 5 additions & 0 deletions scenarios/browser/basic-with-sessions/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "basic-with-sessions",
"private": true,
"version": "0.0.0"
}
6 changes: 6 additions & 0 deletions scenarios/browser/basic-with-tunnel/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { init } from "@sentry/browser";

init({
dsn: "https://[email protected]/0000000",
tunnel: "/errors",
});
5 changes: 5 additions & 0 deletions scenarios/browser/basic-with-tunnel/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "basic-with-tunnel",
"private": true,
"version": "0.0.0"
}
5 changes: 5 additions & 0 deletions scenarios/browser/basic/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { init } from "@sentry/browser";

init({
dsn: "https://[email protected]/0000000",
});
5 changes: 5 additions & 0 deletions scenarios/browser/basic/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "basic",
"private": true,
"version": "0.0.0"
}
5 changes: 5 additions & 0 deletions scenarios/browser/nextjs-client/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { init } from "@sentry/nextjs/esm/index.client";

init({
dsn: "https://[email protected]/0000000",
});
8 changes: 8 additions & 0 deletions scenarios/browser/nextjs-client/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "nextjs-client",
"private": true,
"version": "0.0.0",
"dependencies": {
"next": "12"
}
}
11 changes: 11 additions & 0 deletions scenarios/browser/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "scenarios-browser",
"main": "webpack.js",
"private": true,
"version": "0.0.0",
"devDependencies": {
"html-webpack-plugin": "^5.5.0",
"webpack": "^5.62.1",
"webpack-bundle-analyzer": "^4.5.0"
}
}
8 changes: 8 additions & 0 deletions scenarios/browser/perf-auto/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { init } from "@sentry/browser";
import { Integrations } from "@sentry/tracing";

init({
dsn: "https://[email protected]/0000000",
integrations: [new Integrations.BrowserTracing()],
tracesSampleRate: 1.0,
});
5 changes: 5 additions & 0 deletions scenarios/browser/perf-auto/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "perf-auto",
"private": true,
"version": "0.0.0"
}
13 changes: 13 additions & 0 deletions scenarios/browser/perf-manual/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { init, startTransaction } from "@sentry/browser";
import "@sentry/tracing";

init({
dsn: "https://[email protected]/0000000",
tracesSampleRate: 1.0,
});

const transaction = startTransaction({ op: "task", name: "Important Stuff" });

setTimeout(() => {
transaction.finish();
}, 1000);
5 changes: 5 additions & 0 deletions scenarios/browser/perf-manual/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "perf-manual",
"private": true,
"version": "0.0.0"
}
19 changes: 19 additions & 0 deletions scenarios/browser/react/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import React from "react";
import ReactDOM from "react-dom"
import { init } from "@sentry/react";

init({
dsn: "https://[email protected]/0000000",
});

class Hello extends React.Component {
render() {
return React.createElement('div', null, `Hello ${this.props.toWhat}`);
}
}

ReactDOM.render(
React.createElement(Hello, { toWhat: 'World' }, null),
// eslint-disable-next-line no-undef
document.getElementById('root')
);
9 changes: 9 additions & 0 deletions scenarios/browser/react/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "react",
"private": true,
"version": "0.0.0",
"dependencies": {
"react": "17",
"react-dom": "17"
}
}
69 changes: 69 additions & 0 deletions scenarios/browser/webpack.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
const path = require('path');
const { promises } = require('fs');

const webpack = require('webpack');
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
const HtmlWebpackPlugin = require('html-webpack-plugin');

async function init(scenario) {
if (!hasCurrentScenario(scenario)) {
throw new Error(`Scenario "${scenario}" does not exist`);
}

console.log(`Bundling scenario: ${scenario}`);

await runWebpack(scenario);
}

async function runWebpack(scenario) {
const alias = await generateAlias();

webpack(
{
mode: 'production',
entry: path.resolve(__dirname, scenario),
output: {
filename: 'main.js',
path: path.resolve(__dirname, 'dist', scenario),
},
plugins: [new BundleAnalyzerPlugin({ analyzerMode: 'static' }), new HtmlWebpackPlugin()],
resolve: {
alias,
},
},
(err, stats) => {
if (err || stats.hasErrors()) {
console.log(err);
}
console.log('DONE', stats);
},
);
}

const PACKAGE_PATH = '../../packages';

/**
* Generate webpack aliases based on packages in monorepo
* Example of an alias: '@sentry/serverless': 'path/to/sentry-javascript/packages/serverless',
*/
async function generateAlias() {
const dirents = await promises.readdir(PACKAGE_PATH);

return Object.fromEntries(
await Promise.all(
dirents.map(async d => {
const packageJSON = JSON.parse(await promises.readFile(path.resolve(PACKAGE_PATH, d, 'package.json')));
return [packageJSON['name'], path.resolve(PACKAGE_PATH, d)];
}),
),
);
}

async function hasCurrentScenario(scenario) {
const dirents = await promises.readdir(__dirname, { withFileTypes: true });
return dirents.filter(dir => dir.isDirectory()).find(dir => dir.name === scenario);
}

const CURRENT_SCENARIO = 'basic';

init(CURRENT_SCENARIO);
Loading