Skip to content

Commit 41e12c4

Browse files
kamilogorekHazAT
authored andcommitted
test: Express manual test (#1681)
1 parent 67f23cc commit 41e12c4

File tree

2 files changed

+93
-7
lines changed

2 files changed

+93
-7
lines changed

packages/node/package.json

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
"@types/cookie": "0.3.1",
2929
"@types/md5": "2.1.32",
3030
"@types/stack-trace": "0.0.29",
31+
"express": "^4.16.4",
3132
"jest": "^22.4.3",
3233
"npm-run-all": "^4.1.2",
3334
"prettier": "^1.14.0",
@@ -56,14 +57,9 @@
5657
"transform": {
5758
"^.+\\.ts$": "ts-jest"
5859
},
59-
"moduleFileExtensions": [
60-
"js",
61-
"ts"
62-
],
60+
"moduleFileExtensions": ["js", "ts"],
6361
"testEnvironment": "node",
64-
"testMatch": [
65-
"**/*.test.ts"
66-
],
62+
"testMatch": ["**/*.test.ts"],
6763
"globals": {
6864
"ts-jest": {
6965
"tsConfigFile": "./tsconfig.json"

packages/node/test/manual/express.js

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
const http = require('http');
2+
const express = require('express');
3+
const app = express();
4+
const Sentry = require('../../dist');
5+
6+
function assertTags(actual, expected) {
7+
if (JSON.stringify(actual) !== JSON.stringify(expected)) {
8+
console.error('FAILED: Scope contains incorrect tags');
9+
process.exit(1);
10+
}
11+
}
12+
13+
let remaining = 3;
14+
15+
class DummyTransport {
16+
captureEvent(event) {
17+
--remaining;
18+
19+
if (!remaining) {
20+
console.error('SUCCESS: All scopes contain correct tags');
21+
process.exit(0);
22+
}
23+
24+
return Promise.resolve({
25+
status: 'success',
26+
});
27+
}
28+
}
29+
30+
Sentry.init({
31+
dsn: 'http://[email protected]/1337',
32+
transport: DummyTransport,
33+
beforeSend(event) {
34+
if (event.message === 'Error: foo') {
35+
assertTags(event.tags, {
36+
global: 'wat',
37+
foo: 'wat',
38+
});
39+
} else if (event.message === 'Error: bar') {
40+
assertTags(event.tags, {
41+
global: 'wat',
42+
bar: 'wat',
43+
});
44+
} else if (event.message === 'Error: baz') {
45+
assertTags(event.tags, {
46+
global: 'wat',
47+
baz: 'wat',
48+
});
49+
}
50+
return event;
51+
},
52+
});
53+
54+
Sentry.configureScope(scope => {
55+
scope.setTag('global', 'wat');
56+
});
57+
58+
app.use(Sentry.Handlers.requestHandler());
59+
60+
app.get('/foo', req => {
61+
Sentry.configureScope(scope => {
62+
scope.setTag('foo', 'wat');
63+
});
64+
65+
throw new Error('foo');
66+
});
67+
68+
app.get('/bar', req => {
69+
Sentry.configureScope(scope => {
70+
scope.setTag('bar', 'wat');
71+
});
72+
73+
throw new Error('bar');
74+
});
75+
76+
app.get('/baz', req => {
77+
Sentry.configureScope(scope => {
78+
scope.setTag('baz', 'wat');
79+
});
80+
81+
throw new Error('baz');
82+
});
83+
84+
app.use(Sentry.Handlers.errorHandler());
85+
86+
app.listen(3000);
87+
88+
http.get('http://localhost:3000/foo');
89+
http.get('http://localhost:3000/bar');
90+
http.get('http://localhost:3000/baz');

0 commit comments

Comments
 (0)