|
| 1 | +import { mkdirSync, rmdirSync, unlinkSync, writeFileSync } from 'fs'; |
1 | 2 | import * as path from 'path'; |
2 | | -import { afterAll, describe, expect, test } from 'vitest'; |
| 3 | +import { afterAll, beforeAll, describe, expect, test } from 'vitest'; |
3 | 4 | import { conditionalTest } from '../../../utils'; |
4 | 5 | import { cleanupChildProcesses, createRunner } from '../../../utils/runner'; |
5 | 6 |
|
@@ -39,8 +40,35 @@ const EXPECTED_LOCAL_VARIABLES_EVENT = { |
39 | 40 | }; |
40 | 41 |
|
41 | 42 | 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, { recursive: true }); |
| 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 | + }); |
42 | 69 | afterAll(() => { |
43 | 70 | cleanupChildProcesses(); |
| 71 | + cleanupExternalModuleFile(); |
44 | 72 | }); |
45 | 73 |
|
46 | 74 | test('Should not include local variables by default', async () => { |
@@ -127,4 +155,47 @@ describe('LocalVariables integration', () => { |
127 | 155 | .start() |
128 | 156 | .completed(); |
129 | 157 | }); |
| 158 | + |
| 159 | + test('adds local variables to out of app frames when includeOutOfAppFrames is true', async () => { |
| 160 | + await createRunner(__dirname, 'local-variables-out-of-app.js') |
| 161 | + .expect({ |
| 162 | + event: event => { |
| 163 | + const frames = event.exception?.values?.[0]?.stacktrace?.frames || []; |
| 164 | + |
| 165 | + const inAppFrame = frames.find(frame => frame.function === 'in_app_function'); |
| 166 | + const outOfAppFrame = frames.find(frame => frame.function === 'out_of_app_function'); |
| 167 | + |
| 168 | + expect(inAppFrame?.vars).toEqual({ inAppVar: 'in app value' }); |
| 169 | + expect(inAppFrame?.in_app).toEqual(true); |
| 170 | + |
| 171 | + expect(outOfAppFrame?.vars).toEqual({ |
| 172 | + outOfAppVar: 'out of app value modified value', |
| 173 | + passedArg: 'in app value modified value', |
| 174 | + }); |
| 175 | + expect(outOfAppFrame?.in_app).toEqual(false); |
| 176 | + }, |
| 177 | + }) |
| 178 | + .start() |
| 179 | + .completed(); |
| 180 | + }); |
| 181 | + |
| 182 | + test('does not add local variables to out of app frames by default', async () => { |
| 183 | + await createRunner(__dirname, 'local-variables-out-of-app-default.js') |
| 184 | + .expect({ |
| 185 | + event: event => { |
| 186 | + const frames = event.exception?.values?.[0]?.stacktrace?.frames || []; |
| 187 | + |
| 188 | + const inAppFrame = frames.find(frame => frame.function === 'in_app_function'); |
| 189 | + const outOfAppFrame = frames.find(frame => frame.function === 'out_of_app_function'); |
| 190 | + |
| 191 | + expect(inAppFrame?.vars).toEqual({ inAppVar: 'in app value' }); |
| 192 | + expect(inAppFrame?.in_app).toEqual(true); |
| 193 | + |
| 194 | + expect(outOfAppFrame?.vars).toBeUndefined(); |
| 195 | + expect(outOfAppFrame?.in_app).toEqual(false); |
| 196 | + }, |
| 197 | + }) |
| 198 | + .start() |
| 199 | + .completed(); |
| 200 | + }); |
130 | 201 | }); |
0 commit comments