1
1
import * as os from 'os' ;
2
2
import * as path from 'path' ;
3
3
import * as fs from 'fs-extra' ;
4
+ import { createTestEvent } from './util' ;
4
5
import { IoHelper } from '../../../../lib/api-private' ;
5
6
import { CliIoHost } from '../../../../lib/cli/io-host' ;
6
- import type { TelemetrySchema } from '../../../../lib/cli/telemetry/schema' ;
7
7
import { FileTelemetrySink } from '../../../../lib/cli/telemetry/sink/file-sink' ;
8
8
9
9
describe ( 'FileTelemetrySink' , ( ) => {
@@ -32,37 +32,7 @@ describe('FileTelemetrySink', () => {
32
32
33
33
test ( 'saves data to a file' , async ( ) => {
34
34
// GIVEN
35
- const testEvent : TelemetrySchema = {
36
- identifiers : {
37
- cdkCliVersion : '1.0.0' ,
38
- telemetryVersion : '1.0.0' ,
39
- sessionId : 'test-session' ,
40
- eventId : 'test-event' ,
41
- installationId : 'test-installation' ,
42
- timestamp : new Date ( ) . toISOString ( ) ,
43
- } ,
44
- event : {
45
- state : 'SUCCEEDED' ,
46
- eventType : 'INVOKE' ,
47
- command : {
48
- path : [ 'test' ] ,
49
- parameters : { } ,
50
- config : { context : { foo : true } } ,
51
- } ,
52
- } ,
53
- environment : {
54
- os : {
55
- platform : 'test' ,
56
- release : 'test' ,
57
- } ,
58
- ci : false ,
59
- nodeVersion : process . version ,
60
- } ,
61
- project : { } ,
62
- duration : {
63
- total : 0 ,
64
- } ,
65
- } ;
35
+ const testEvent = createTestEvent ( 'INVOKE' , { context : { foo : true } } ) ;
66
36
const client = new FileTelemetrySink ( { logFilePath, ioHost } ) ;
67
37
68
38
// WHEN
@@ -76,37 +46,7 @@ describe('FileTelemetrySink', () => {
76
46
77
47
test ( 'appends data to a file' , async ( ) => {
78
48
// GIVEN
79
- const testEvent : TelemetrySchema = {
80
- identifiers : {
81
- cdkCliVersion : '1.0.0' ,
82
- telemetryVersion : '1.0.0' ,
83
- sessionId : 'test-session' ,
84
- eventId : 'test-event' ,
85
- installationId : 'test-installation' ,
86
- timestamp : new Date ( ) . toISOString ( ) ,
87
- } ,
88
- event : {
89
- state : 'SUCCEEDED' ,
90
- eventType : 'INVOKE' ,
91
- command : {
92
- path : [ 'test' ] ,
93
- parameters : { } ,
94
- config : { context : { foo : true } } ,
95
- } ,
96
- } ,
97
- environment : {
98
- os : {
99
- platform : 'test' ,
100
- release : 'test' ,
101
- } ,
102
- ci : false ,
103
- nodeVersion : process . version ,
104
- } ,
105
- project : { } ,
106
- duration : {
107
- total : 0 ,
108
- } ,
109
- } ;
49
+ const testEvent = createTestEvent ( 'INVOKE' , { context : { foo : true } } ) ;
110
50
const client = new FileTelemetrySink ( { logFilePath, ioHost } ) ;
111
51
112
52
// WHEN
@@ -130,37 +70,7 @@ describe('FileTelemetrySink', () => {
130
70
131
71
test ( 'handles errors gracefully and logs to trace without throwing' , async ( ) => {
132
72
// GIVEN
133
- const testEvent : TelemetrySchema = {
134
- identifiers : {
135
- cdkCliVersion : '1.0.0' ,
136
- telemetryVersion : '1.0.0' ,
137
- sessionId : 'test-session' ,
138
- eventId : 'test-event' ,
139
- installationId : 'test-installation' ,
140
- timestamp : new Date ( ) . toISOString ( ) ,
141
- } ,
142
- event : {
143
- state : 'SUCCEEDED' ,
144
- eventType : 'INVOKE' ,
145
- command : {
146
- path : [ 'test' ] ,
147
- parameters : { } ,
148
- config : { context : { foo : true } } ,
149
- } ,
150
- } ,
151
- environment : {
152
- os : {
153
- platform : 'test' ,
154
- release : 'test' ,
155
- } ,
156
- ci : false ,
157
- nodeVersion : process . version ,
158
- } ,
159
- project : { } ,
160
- duration : {
161
- total : 0 ,
162
- } ,
163
- } ;
73
+ const testEvent = createTestEvent ( 'INVOKE' , { context : { foo : true } } ) ;
164
74
165
75
// Create a mock IoHelper with trace spy
166
76
const traceSpy = jest . fn ( ) ;
0 commit comments