@@ -11,7 +11,7 @@ import { Attributes } from '@opentelemetry/api';
1111
1212describe ( 'CompactConsoleLogRecordExporter' , ( ) => {
1313 let exporter : CompactConsoleLogRecordExporter ;
14- let consoleLogSpy : sinon . SinonSpy ;
14+ let stdoutWriteSpy : sinon . SinonSpy ;
1515
1616 const createMockLogRecord = ( body : string , attributes : Attributes = { } ) : ReadableLogRecord => ( {
1717 hrTime : [ 1640995200 , 0 ] ,
@@ -26,7 +26,7 @@ describe('CompactConsoleLogRecordExporter', () => {
2626
2727 beforeEach ( ( ) => {
2828 exporter = new CompactConsoleLogRecordExporter ( ) ;
29- consoleLogSpy = sinon . spy ( console , 'log ' ) ;
29+ stdoutWriteSpy = sinon . spy ( process . stdout , 'write ' ) ;
3030 } ) ;
3131
3232 afterEach ( ( ) => {
@@ -39,10 +39,13 @@ describe('CompactConsoleLogRecordExporter', () => {
3939
4040 exporter . export ( logs , result => {
4141 expect ( result . code ) . toBe ( ExportResultCode . SUCCESS ) ;
42- expect ( consoleLogSpy . calledOnce ) . toBeTruthy ( ) ;
42+ expect ( stdoutWriteSpy . calledOnce ) . toBeTruthy ( ) ;
4343
44- const loggedContent = consoleLogSpy . firstCall . args [ 0 ] ;
45- expect ( typeof loggedContent ) . toBe ( 'object' ) ;
44+ const writtenData = stdoutWriteSpy . firstCall . args [ 0 ] ;
45+ expect ( typeof writtenData ) . toBe ( 'string' ) ;
46+ expect ( writtenData . endsWith ( '\n' ) ) . toBeTruthy ( ) ;
47+
48+ const loggedContent = JSON . parse ( writtenData . trim ( ) ) ;
4649 expect ( loggedContent . body ) . toBe ( 'test log message' ) ;
4750 expect ( loggedContent . severityText ) . toBe ( 'INFO' ) ;
4851 expect ( loggedContent . instrumentationScope . name ) . toBe ( 'test' ) ;
@@ -57,10 +60,10 @@ describe('CompactConsoleLogRecordExporter', () => {
5760
5861 exporter . export ( mockLogRecords , result => {
5962 expect ( result . code ) . toBe ( ExportResultCode . SUCCESS ) ;
60- expect ( consoleLogSpy . callCount ) . toBe ( 2 ) ;
63+ expect ( stdoutWriteSpy . callCount ) . toBe ( 2 ) ;
6164
62- const firstLogContent = consoleLogSpy . firstCall . args [ 0 ] ;
63- const secondLogContent = consoleLogSpy . secondCall . args [ 0 ] ;
65+ const firstLogContent = JSON . parse ( stdoutWriteSpy . firstCall . args [ 0 ] . trim ( ) ) ;
66+ const secondLogContent = JSON . parse ( stdoutWriteSpy . secondCall . args [ 0 ] . trim ( ) ) ;
6467
6568 expect ( firstLogContent . body ) . toBe ( 'log 1' ) ;
6669 expect ( secondLogContent . body ) . toBe ( 'log 2' ) ;
@@ -72,7 +75,7 @@ describe('CompactConsoleLogRecordExporter', () => {
7275 it ( 'should handle empty logs array' , done => {
7376 exporter . export ( [ ] , result => {
7477 expect ( result . code ) . toBe ( ExportResultCode . SUCCESS ) ;
75- expect ( consoleLogSpy . called ) . toBeFalsy ( ) ;
78+ expect ( stdoutWriteSpy . called ) . toBeFalsy ( ) ;
7679 done ( ) ;
7780 } ) ;
7881 } ) ;
@@ -83,9 +86,9 @@ describe('CompactConsoleLogRecordExporter', () => {
8386 expect ( ( ) => {
8487 exporter . export ( [ mockLogRecord ] , ( ) => { } ) ;
8588 } ) . not . toThrow ( ) ;
86- expect ( consoleLogSpy . calledOnce ) . toBeTruthy ( ) ;
89+ expect ( stdoutWriteSpy . calledOnce ) . toBeTruthy ( ) ;
8790
88- const loggedContent = consoleLogSpy . firstCall . args [ 0 ] ;
91+ const loggedContent = JSON . parse ( stdoutWriteSpy . firstCall . args [ 0 ] . trim ( ) ) ;
8992 expect ( loggedContent . body ) . toBe ( 'test log message' ) ;
9093 } ) ;
9194
@@ -95,9 +98,9 @@ describe('CompactConsoleLogRecordExporter', () => {
9598 expect ( ( ) => {
9699 exporter [ '_sendLogRecordsToLambdaConsole' ] ( [ mockLogRecord ] ) ;
97100 } ) . not . toThrow ( ) ;
98- expect ( consoleLogSpy . calledOnce ) . toBeTruthy ( ) ;
101+ expect ( stdoutWriteSpy . calledOnce ) . toBeTruthy ( ) ;
99102
100- const loggedContent = consoleLogSpy . firstCall . args [ 0 ] ;
103+ const loggedContent = JSON . parse ( stdoutWriteSpy . firstCall . args [ 0 ] . trim ( ) ) ;
101104 expect ( loggedContent . body ) . toBe ( 'test log message' ) ;
102105 } ) ;
103106
@@ -110,8 +113,8 @@ describe('CompactConsoleLogRecordExporter', () => {
110113 exporter . export ( [ mockLogRecord ] , result => {
111114 expect ( result . code ) . toBe ( ExportResultCode . SUCCESS ) ;
112115
113- const loggedContent = consoleLogSpy . firstCall . args [ 0 ] ;
114- expect ( typeof loggedContent ) . toBe ( 'object' ) ;
116+ const writtenData = stdoutWriteSpy . firstCall . args [ 0 ] ;
117+ const loggedContent = JSON . parse ( writtenData . trim ( ) ) ;
115118 expect ( loggedContent . body ) . toBe ( 'detailed test message' ) ;
116119 expect ( loggedContent . severityText ) . toBe ( 'INFO' ) ;
117120 expect ( loggedContent . instrumentationScope . name ) . toBe ( 'test' ) ;
0 commit comments