Skip to content

Commit 2914be4

Browse files
committed
ref(node): Update Node manual tests and test for sessionCount
1 parent a3da68f commit 2914be4

File tree

4 files changed

+83
-93
lines changed

4 files changed

+83
-93
lines changed
Lines changed: 30 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,35 @@
11
const Sentry = require('../../../../dist');
2-
const { assertSessions, constructStrippedSessionObject, BaseDummyTransport } = require('../test-utils');
2+
const {
3+
assertSessions,
4+
constructStrippedSessionObject,
5+
BaseDummyTransport,
6+
validateSessionCountFunction,
7+
} = require('../test-utils');
38

4-
let sessionCounter = 0;
5-
process.on('exit', ()=> {
6-
if (process.exitCode !== 1) {
7-
console.log('SUCCESS: All application mode sessions were sent to node transport as expected');
8-
}
9-
})
9+
const sessionCounts = {
10+
sessionCounter: 0,
11+
expectedSessions: 2,
12+
};
13+
14+
validateSessionCountFunction(sessionCounts);
1015

1116
class DummyTransport extends BaseDummyTransport {
1217
sendSession(session) {
13-
sessionCounter++;
14-
if (sessionCounter === 1) {
15-
assertSessions(constructStrippedSessionObject(session),
16-
{
17-
init: true,
18-
status: 'ok',
19-
errors: 1,
20-
release: '1.1'
21-
}
22-
)
23-
}
24-
else if (sessionCounter === 2) {
25-
assertSessions(constructStrippedSessionObject(session),
26-
{
27-
init: false,
28-
status: 'exited',
29-
errors: 1,
30-
release: '1.1'
31-
}
32-
)
33-
}
34-
else {
35-
console.log('FAIL: Received way too many Sessions!');
36-
process.exit(1);
18+
sessionCounts.sessionCounter++;
19+
if (sessionCounts.sessionCounter === 1) {
20+
assertSessions(constructStrippedSessionObject(session), {
21+
init: true,
22+
status: 'ok',
23+
errors: 1,
24+
release: '1.1',
25+
});
26+
} else if (sessionCounts.sessionCounter === 2) {
27+
assertSessions(constructStrippedSessionObject(session), {
28+
init: false,
29+
status: 'exited',
30+
errors: 1,
31+
release: '1.1',
32+
});
3733
}
3834
return super.sendSession(session);
3935
}
@@ -43,7 +39,7 @@ Sentry.init({
4339
dsn: 'http://[email protected]/1337',
4440
release: '1.1',
4541
transport: DummyTransport,
46-
autoSessionTracking: true
42+
autoSessionTracking: true,
4743
});
4844

4945
/**
@@ -54,8 +50,7 @@ Sentry.init({
5450
* `beforeExit` event which happens right before the process exits.
5551
*/
5652
try {
57-
throw new Error('hey there')
58-
}
59-
catch(e) {
53+
throw new Error('hey there');
54+
} catch (e) {
6055
Sentry.captureException(e);
6156
}

packages/node/test/manual/release-health/single-session/healthy-session.js

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,28 @@
11
const Sentry = require('../../../../dist');
2-
const { assertSessions, constructStrippedSessionObject, BaseDummyTransport } = require('../test-utils');
2+
const {
3+
assertSessions,
4+
constructStrippedSessionObject,
5+
BaseDummyTransport,
6+
validateSessionCountFunction,
7+
} = require('../test-utils');
38

4-
let sessionCounter = 0;
5-
process.on('exit', ()=> {
6-
if (process.exitCode !== 1) {
7-
console.log('SUCCESS: All application mode sessions were sent to node transport as expected');
8-
}
9-
})
9+
const sessionCounts = {
10+
sessionCounter: 0,
11+
expectedSessions: 1,
12+
};
13+
14+
validateSessionCountFunction(sessionCounts);
1015

1116
class DummyTransport extends BaseDummyTransport {
1217
sendSession(session) {
13-
sessionCounter++;
14-
if (sessionCounter === 1) {
15-
assertSessions(constructStrippedSessionObject(session),
16-
{
17-
init: true,
18-
status: 'exited',
19-
errors: 0,
20-
release: '1.1'
21-
}
22-
)
23-
}
24-
else {
25-
console.log('FAIL: Received way too many Sessions!');
26-
process.exit(1);
18+
sessionCounts.sessionCounter++;
19+
if (sessionCounts.sessionCounter === 1) {
20+
assertSessions(constructStrippedSessionObject(session), {
21+
init: true,
22+
status: 'exited',
23+
errors: 0,
24+
release: '1.1',
25+
});
2726
}
2827
return super.sendSession(session);
2928
}
@@ -33,7 +32,7 @@ Sentry.init({
3332
dsn: 'http://[email protected]/1337',
3433
release: '1.1',
3534
transport: DummyTransport,
36-
autoSessionTracking: true
35+
autoSessionTracking: true,
3736
});
3837

3938
/**
Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,20 @@
11
const Sentry = require('../../../../dist');
22
const { assertSessions, constructStrippedSessionObject, BaseDummyTransport } = require('../test-utils');
33

4-
process.on('exit', ()=> {
5-
if (process.exitCode !== 1) {
4+
process.on('exit', () => {
5+
if (process.exitCode === 0) {
66
console.log('SUCCESS: All application mode sessions were sent to node transport as expected');
77
}
8-
})
8+
});
99

1010
class DummyTransport extends BaseDummyTransport {
1111
sendSession(session) {
12-
assertSessions(constructStrippedSessionObject(session),
13-
{
14-
init: true,
15-
status: 'crashed',
16-
errors: 1,
17-
release: '1.1'
18-
}
19-
)
12+
assertSessions(constructStrippedSessionObject(session), {
13+
init: true,
14+
status: 'crashed',
15+
errors: 1,
16+
release: '1.1',
17+
});
2018
process.exit(0);
2119
}
2220
}
@@ -25,7 +23,7 @@ Sentry.init({
2523
dsn: 'http://[email protected]/1337',
2624
release: '1.1',
2725
transport: DummyTransport,
28-
autoSessionTracking: true
26+
autoSessionTracking: true,
2927
});
3028
/**
3129
* The following code snippet will throw an exception of `mechanism.handled` equal to `false`, and so this session
@@ -34,4 +32,4 @@ Sentry.init({
3432
* extracts event data and uses it to update the Session and send it. No secondary session update in this case because
3533
* we explicitly exit the process in the onUncaughtException handler and so the `beforeExit` event is not fired.
3634
*/
37-
throw new Error('test error')
35+
throw new Error('test error');

packages/node/test/manual/release-health/single-session/unhandled-rejection-crashed-session.js

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,30 @@
11
const Sentry = require('../../../../dist');
2-
const { assertSessions, constructStrippedSessionObject, BaseDummyTransport } = require('../test-utils');
2+
const {
3+
assertSessions,
4+
constructStrippedSessionObject,
5+
BaseDummyTransport,
6+
validateSessionCountFunction,
7+
} = require('../test-utils');
38

4-
let sessionCounter = 0;
5-
process.on('exit', () => {
6-
if (process.exitCode !== 1) {
7-
console.log('SUCCESS: All application mode sessions were sent to node transport as expected');
8-
}
9-
})
9+
const sessionCounts = {
10+
sessionCounter: 0,
11+
expectedSessions: 1,
12+
};
13+
14+
validateSessionCountFunction(sessionCounts);
1015

1116
class DummyTransport extends BaseDummyTransport {
1217
sendSession(session) {
13-
sessionCounter++;
18+
sessionCounts.sessionCounter++;
1419

15-
if (sessionCounter === 1) {
16-
assertSessions(constructStrippedSessionObject(session),
17-
{
18-
init: true,
19-
status: 'crashed',
20-
errors: 1,
21-
release: '1.1'
22-
}
23-
)
20+
if (sessionCounts.sessionCounter === 1) {
21+
assertSessions(constructStrippedSessionObject(session), {
22+
init: true,
23+
status: 'crashed',
24+
errors: 1,
25+
release: '1.1',
26+
});
2427
}
25-
else {
26-
console.log('FAIL: Received way too many Sessions!');
27-
process.exit(1);
28-
}
29-
3028
return super.sendSession(session);
3129
}
3230
}
@@ -35,7 +33,7 @@ Sentry.init({
3533
dsn: 'http://[email protected]/1337',
3634
release: '1.1',
3735
transport: DummyTransport,
38-
autoSessionTracking: true
36+
autoSessionTracking: true,
3937
});
4038

4139
/**

0 commit comments

Comments
 (0)