Skip to content

Commit 4f88959

Browse files
committed
fix(local-variables): Improve test for local variables in out of app frames
Move the creation/cleanup of the out-of-app frame module file into the test setup/teardown.
1 parent d9cd7be commit 4f88959

File tree

3 files changed

+42
-36
lines changed

3 files changed

+42
-36
lines changed

dev-packages/node-integration-tests/suites/public-api/LocalVariables/local-variables-out-of-app-default.js

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,34 +3,19 @@
33
const Sentry = require('@sentry/node');
44
const { loggingTransport } = require('@sentry-internal/node-integration-tests');
55

6-
// make sure to create the following file with the following content:
7-
// function out_of_app_function() {
8-
// const outOfAppVar = 'out of app value';
9-
// throw new Error('out-of-app error');
10-
// }
6+
const externalFunctionFile = require.resolve('./node_modules/out-of-app-function.js');
117

12-
// module.exports = { out_of_app_function };
13-
14-
const { out_of_app_function } = require('./node_modules/test-module/out-of-app-function.js');
8+
const { out_of_app_function } = require(externalFunctionFile);
159

1610
function in_app_function() {
1711
const inAppVar = 'in app value';
18-
out_of_app_function();
12+
out_of_app_function(`${inAppVar} modified value`);
1913
}
2014

2115
Sentry.init({
2216
dsn: 'https://public@dsn.ingest.sentry.io/1337',
2317
transport: loggingTransport,
2418
includeLocalVariables: true,
25-
// either set each frame's in_app flag manually or import the `out_of_app_function` from a node_module directory
26-
// beforeSend: (event) => {
27-
// event.exception?.values?.[0]?.stacktrace?.frames?.forEach(frame => {
28-
// if (frame.function === 'out_of_app_function') {
29-
// frame.in_app = false;
30-
// }
31-
// });
32-
// return event;
33-
// },
3419
});
3520

3621
setTimeout(async () => {
@@ -39,7 +24,5 @@ setTimeout(async () => {
3924
} catch (e) {
4025
Sentry.captureException(e);
4126
await Sentry.flush();
42-
43-
return null;
4427
}
45-
}, 1000);
28+
}, 500);

dev-packages/node-integration-tests/suites/public-api/LocalVariables/local-variables-out-of-app.js

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
const Sentry = require('@sentry/node');
44
const { loggingTransport } = require('@sentry-internal/node-integration-tests');
55

6-
const { out_of_app_function } = require('./node_modules/test-module/out-of-app-function.js');
6+
const externalFunctionFile = require.resolve('./node_modules/out-of-app-function.js');
7+
8+
const { out_of_app_function } = require(externalFunctionFile);
79

810
Sentry.init({
911
dsn: 'https://public@dsn.ingest.sentry.io/1337',
@@ -14,20 +16,11 @@ Sentry.init({
1416
includeOutOfAppFrames: true,
1517
}),
1618
],
17-
// either set each frame's in_app flag manually or import the `out_of_app_function` from a node_module directory
18-
// beforeSend: (event) => {
19-
// event.exception?.values?.[0]?.stacktrace?.frames?.forEach(frame => {
20-
// if (frame.function === 'out_of_app_function') {
21-
// frame.in_app = false;
22-
// }
23-
// });
24-
// return event;
25-
// },
2619
});
2720

2821
function in_app_function() {
2922
const inAppVar = 'in app value';
30-
out_of_app_function();
23+
out_of_app_function(`${inAppVar} modified value`);
3124
}
3225

3326
setTimeout(async () => {
@@ -36,6 +29,5 @@ setTimeout(async () => {
3629
} catch (e) {
3730
Sentry.captureException(e);
3831
await Sentry.flush();
39-
return null;
4032
}
41-
}, 1000);
33+
}, 500);

dev-packages/node-integration-tests/suites/public-api/LocalVariables/test.ts

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
import { mkdirSync, rmdirSync, unlinkSync, writeFileSync } from 'fs';
12
import * as path from 'path';
2-
import { afterAll, describe, expect, test } from 'vitest';
3+
import { afterAll, beforeAll, describe, expect, test } from 'vitest';
34
import { conditionalTest } from '../../../utils';
45
import { cleanupChildProcesses, createRunner } from '../../../utils/runner';
56

@@ -39,8 +40,35 @@ const EXPECTED_LOCAL_VARIABLES_EVENT = {
3940
};
4041

4142
describe('LocalVariables integration', () => {
43+
const nodeModules = `${__dirname}/node_modules`;
44+
const externalModule = `${nodeModules}//out-of-app-function.js`;
45+
function cleanupExternalModuleFile() {
46+
try {
47+
unlinkSync(externalModule);
48+
// eslint-disable-next-line no-empty
49+
} catch {}
50+
try {
51+
rmdirSync(nodeModules);
52+
// eslint-disable-next-line no-empty
53+
} catch {}
54+
}
55+
56+
beforeAll(() => {
57+
cleanupExternalModuleFile();
58+
mkdirSync(nodeModules);
59+
writeFileSync(
60+
externalModule,
61+
`
62+
function out_of_app_function(passedArg) {
63+
const outOfAppVar = "out of app value " + passedArg.substring(13);
64+
throw new Error("out-of-app error");
65+
}
66+
module.exports = { out_of_app_function };`,
67+
);
68+
});
4269
afterAll(() => {
4370
cleanupChildProcesses();
71+
cleanupExternalModuleFile();
4472
});
4573

4674
test('Should not include local variables by default', async () => {
@@ -140,7 +168,10 @@ describe('LocalVariables integration', () => {
140168
expect(inAppFrame?.vars).toEqual({ inAppVar: 'in app value' });
141169
expect(inAppFrame?.in_app).toEqual(true);
142170

143-
expect(outOfAppFrame?.vars).toEqual({ outOfAppVar: 'out of app value' });
171+
expect(outOfAppFrame?.vars).toEqual({
172+
outOfAppVar: 'out of app value modified value',
173+
passedArg: 'in app value modified value',
174+
});
144175
expect(outOfAppFrame?.in_app).toEqual(false);
145176
},
146177
})

0 commit comments

Comments
 (0)