@@ -44,6 +44,19 @@ describe("captureException", () => {
4444 expect ( result . message ) . toBe ( "Custom error message" ) ;
4545 expect ( result . type ) . toBe ( "CustomError" ) ;
4646 } ) ;
47+
48+ it ( "should always set platform to 'javascript'" , ( ) => {
49+ const error = new Error ( "Test error" ) ;
50+ const result = captureException ( error ) ;
51+
52+ expect ( result . platform ) . toBe ( "javascript" ) ;
53+ } ) ;
54+
55+ it ( "should set platform to 'javascript' for non-Error objects" , ( ) => {
56+ const result = captureException ( "string error" ) ;
57+
58+ expect ( result . platform ) . toBe ( "javascript" ) ;
59+ } ) ;
4760 } ) ;
4861
4962 describe ( "stack trace parsing" , ( ) => {
@@ -161,6 +174,54 @@ describe("captureException", () => {
161174 expect ( result . frames ) . toBeDefined ( ) ;
162175 expect ( result . frames ! . length ) . toBeLessThanOrEqual ( 50 ) ;
163176 } ) ;
177+
178+ it ( "should capture context_line for in_app frames" , ( ) => {
179+ // This test throws a real error, so context_line should be captured
180+ const error = new Error ( "Test error" ) ;
181+ const result = captureException ( error ) ;
182+
183+ expect ( result . frames ) . toBeDefined ( ) ;
184+ const inAppFrames = result . frames ! . filter ( ( frame ) => frame . in_app ) ;
185+ expect ( inAppFrames . length ) . toBeGreaterThan ( 0 ) ;
186+
187+ // At least one in_app frame should have context_line
188+ const hasContextLine = inAppFrames . some (
189+ ( frame ) => frame . context_line !== undefined ,
190+ ) ;
191+ expect ( hasContextLine ) . toBe ( true ) ;
192+ } ) ;
193+
194+ it ( "should NOT capture context_line for library code (in_app: false)" , ( ) => {
195+ // Create a mock stack trace with node_modules
196+ const error = new Error ( "Test" ) ;
197+ error . stack = `Error: Test
198+ at libFunction (/app/node_modules/some-lib/index.js:42:10)
199+ at internal (node:internal/process:123:45)` ;
200+
201+ const result = captureException ( error ) ;
202+
203+ expect ( result . frames ) . toBeDefined ( ) ;
204+ // All frames should be library code and should NOT have context_line
205+ result . frames ! . forEach ( ( frame ) => {
206+ expect ( frame . in_app ) . toBe ( false ) ;
207+ expect ( frame . context_line ) . toBeUndefined ( ) ;
208+ } ) ;
209+ } ) ;
210+
211+ it ( "should handle missing files gracefully when extracting context_line" , ( ) => {
212+ // Create a mock stack trace with a non-existent file
213+ const error = new Error ( "Test" ) ;
214+ error . stack = `Error: Test
215+ at testFunction (/nonexistent/file/path.ts:10:5)` ;
216+
217+ const result = captureException ( error ) ;
218+
219+ expect ( result . frames ) . toBeDefined ( ) ;
220+ expect ( result . frames ! . length ) . toBe ( 1 ) ;
221+ // Frame should be in_app but context_line should be undefined (file not found)
222+ expect ( result . frames ! [ 0 ] . in_app ) . toBe ( true ) ;
223+ expect ( result . frames ! [ 0 ] . context_line ) . toBeUndefined ( ) ;
224+ } ) ;
164225 } ) ;
165226
166227 describe ( "Error.cause chain" , ( ) => {
0 commit comments