@react-native-windows/telemetry 0.0.0-canary.22 → 0.0.0-canary.26

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/lib-commonjs/index.d.ts +4 -2
  2. package/lib-commonjs/index.js +12 -5
  3. package/lib-commonjs/index.js.map +1 -1
  4. package/lib-commonjs/telemetry.d.ts +71 -20
  5. package/lib-commonjs/telemetry.js +267 -171
  6. package/lib-commonjs/telemetry.js.map +1 -1
  7. package/lib-commonjs/test/{sanitize.test.d.ts → basePropUtils.test.d.ts} +0 -0
  8. package/lib-commonjs/test/basePropUtils.test.js +116 -0
  9. package/lib-commonjs/test/basePropUtils.test.js.map +1 -0
  10. package/lib-commonjs/test/errorUtils.test.d.ts +7 -0
  11. package/lib-commonjs/test/errorUtils.test.js +161 -0
  12. package/lib-commonjs/test/errorUtils.test.js.map +1 -0
  13. package/lib-commonjs/test/projectUtils.test.d.ts +7 -0
  14. package/lib-commonjs/test/projectUtils.test.js +84 -0
  15. package/lib-commonjs/test/projectUtils.test.js.map +1 -0
  16. package/lib-commonjs/test/sanitizeUtils.test.d.ts +7 -0
  17. package/lib-commonjs/test/sanitizeUtils.test.js +88 -0
  18. package/lib-commonjs/test/sanitizeUtils.test.js.map +1 -0
  19. package/lib-commonjs/test/telemetry.test.d.ts +26 -0
  20. package/lib-commonjs/test/telemetry.test.js +469 -0
  21. package/lib-commonjs/test/telemetry.test.js.map +1 -0
  22. package/lib-commonjs/test/versionUtils.test.d.ts +7 -0
  23. package/lib-commonjs/test/versionUtils.test.js +122 -0
  24. package/lib-commonjs/test/versionUtils.test.js.map +1 -0
  25. package/lib-commonjs/utils/basePropUtils.d.ts +66 -0
  26. package/lib-commonjs/utils/basePropUtils.js +133 -0
  27. package/lib-commonjs/utils/basePropUtils.js.map +1 -0
  28. package/lib-commonjs/{CodedError.d.ts → utils/errorUtils.d.ts} +27 -8
  29. package/lib-commonjs/utils/errorUtils.js +164 -0
  30. package/lib-commonjs/utils/errorUtils.js.map +1 -0
  31. package/lib-commonjs/utils/optionUtils.d.ts +45 -0
  32. package/lib-commonjs/utils/optionUtils.js +96 -0
  33. package/lib-commonjs/utils/optionUtils.js.map +1 -0
  34. package/lib-commonjs/utils/projectUtils.d.ts +50 -0
  35. package/lib-commonjs/utils/projectUtils.js +187 -0
  36. package/lib-commonjs/utils/projectUtils.js.map +1 -0
  37. package/lib-commonjs/utils/sanitizeUtils.d.ts +12 -0
  38. package/lib-commonjs/utils/sanitizeUtils.js +80 -0
  39. package/lib-commonjs/utils/sanitizeUtils.js.map +1 -0
  40. package/lib-commonjs/utils/versionUtils.d.ts +38 -0
  41. package/lib-commonjs/utils/versionUtils.js +159 -0
  42. package/lib-commonjs/utils/versionUtils.js.map +1 -0
  43. package/package.json +22 -8
  44. package/CHANGELOG.json +0 -457
  45. package/CHANGELOG.md +0 -197
  46. package/lib-commonjs/CodedError.js +0 -77
  47. package/lib-commonjs/CodedError.js.map +0 -1
  48. package/lib-commonjs/test/sanitize.test.js +0 -258
  49. package/lib-commonjs/test/sanitize.test.js.map +0 -1
@@ -1,77 +0,0 @@
1
- "use strict";
2
- /**
3
- * Copyright (c) Microsoft Corporation.
4
- * Licensed under the MIT License.
5
- * @format
6
- */
7
- Object.defineProperty(exports, "__esModule", { value: true });
8
- exports.CodedError = exports.CodedErrors = void 0;
9
- exports.CodedErrors = {
10
- Success: 0,
11
- // init
12
- UnsupportedReactNativeVersion: 1,
13
- UserCancel: 2,
14
- NoReactNativeFound: 3,
15
- NoPackageJSon: 4,
16
- NoLatestReactNativeWindows: 5,
17
- NoAutoMatchingReactNativeWindows: 6,
18
- IncompatibleOptions: 7,
19
- NoReactNativeDependencies: 8,
20
- NoMatchingPackageVersion: 9,
21
- // run-windows
22
- NoSolution: 100,
23
- // Project generation
24
- NoPropertyInProject: 200,
25
- CopyProjectTemplateNoSourcePath: 201,
26
- CopyProjectTemplateNoDestPath: 202,
27
- CopyProjectTemplateNoProjectName: 203,
28
- // Config and Autolinking
29
- NoWindowsConfig: 300,
30
- IncompleteConfig: 301,
31
- InvalidConfig: 302,
32
- NeedAutolinking: 303,
33
- AddProjectToSolution: 304,
34
- Autolinking: 305,
35
- // SDK requirements
36
- MinSDKVersionNotMet: 400,
37
- BadSDKVersionFormat: 401,
38
- NoSDK: 402,
39
- // Build
40
- NoMSBuild: 500,
41
- NoVSWhere: 501,
42
- MSBuildError: 502,
43
- // Deploy
44
- NoAppPackage: 600,
45
- NoAppxManifest: 601,
46
- NoDevice: 602,
47
- AppDidNotDeploy: 603,
48
- InvalidDevicesOutput: 604,
49
- RemoveOldAppVersionFailure: 605,
50
- EnableDevModeFailure: 606,
51
- InstallAppFailure: 607,
52
- InstallAppDependenciesFailure: 608,
53
- CheckNetIsolationFailure: 709,
54
- InstallAppToDeviceFailure: 710,
55
- UninstallAppOnDeviceFailure: 711,
56
- DeployRecipeFailure: 712,
57
- // Others
58
- AppStartupFailure: 700,
59
- //
60
- Unknown: -1,
61
- };
62
- /**
63
- * Represents an error whose message might contain user-originating content,
64
- * therefore when transmitting telemetry, only the type should be sent.
65
- * @param type a stable ID identifying the type of error.
66
- * @param message the error text. This should only be used for display to the user.
67
- * @param data any additional metadata that is safe to collect for telemetry purposes.
68
- */
69
- class CodedError extends Error {
70
- constructor(type, message, data) {
71
- super(message);
72
- this.data = data;
73
- this.name = type;
74
- }
75
- }
76
- exports.CodedError = CodedError;
77
- //# sourceMappingURL=CodedError.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"CodedError.js","sourceRoot":"","sources":["../src/CodedError.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;AAEU,QAAA,WAAW,GAAG;IACzB,OAAO,EAAE,CAAC;IACV,OAAO;IACP,6BAA6B,EAAE,CAAC;IAChC,UAAU,EAAE,CAAC;IACb,kBAAkB,EAAE,CAAC;IACrB,aAAa,EAAE,CAAC;IAChB,0BAA0B,EAAE,CAAC;IAC7B,gCAAgC,EAAE,CA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ACF;AATD,gCASC","sourcesContent":["/**\n * Copyright (c) Microsoft Corporation.\n * Licensed under the MIT License.\n * @format\n */\n\nexport const CodedErrors = {\n Success: 0,\n // init\n UnsupportedReactNativeVersion: 1,\n UserCancel: 2,\n NoReactNativeFound: 3,\n NoPackageJSon: 4,\n NoLatestReactNativeWindows: 5,\n NoAutoMatchingReactNativeWindows: 6,\n IncompatibleOptions: 7,\n NoReactNativeDependencies: 8,\n NoMatchingPackageVersion: 9,\n // run-windows\n NoSolution: 100,\n // Project generation\n NoPropertyInProject: 200,\n CopyProjectTemplateNoSourcePath: 201,\n CopyProjectTemplateNoDestPath: 202,\n CopyProjectTemplateNoProjectName: 203,\n // Config and Autolinking\n NoWindowsConfig: 300,\n IncompleteConfig: 301,\n InvalidConfig: 302,\n NeedAutolinking: 303,\n AddProjectToSolution: 304,\n Autolinking: 305,\n // SDK requirements\n MinSDKVersionNotMet: 400,\n BadSDKVersionFormat: 401,\n NoSDK: 402,\n // Build\n NoMSBuild: 500,\n NoVSWhere: 501,\n MSBuildError: 502,\n // Deploy\n NoAppPackage: 600,\n NoAppxManifest: 601,\n NoDevice: 602,\n AppDidNotDeploy: 603,\n InvalidDevicesOutput: 604,\n RemoveOldAppVersionFailure: 605,\n EnableDevModeFailure: 606,\n InstallAppFailure: 607,\n InstallAppDependenciesFailure: 608,\n CheckNetIsolationFailure: 709,\n InstallAppToDeviceFailure: 710,\n UninstallAppOnDeviceFailure: 711,\n DeployRecipeFailure: 712,\n\n // Others\n AppStartupFailure: 700,\n\n //\n Unknown: -1,\n};\n\nexport type CodedErrorType = keyof typeof CodedErrors;\n\n/**\n * Represents an error whose message might contain user-originating content,\n * therefore when transmitting telemetry, only the type should be sent.\n * @param type a stable ID identifying the type of error.\n * @param message the error text. This should only be used for display to the user.\n * @param data any additional metadata that is safe to collect for telemetry purposes.\n */\nexport class CodedError extends Error {\n constructor(\n type: CodedErrorType,\n message: string,\n public readonly data?: Record<string, any>,\n ) {\n super(message);\n this.name = type;\n }\n}\n"]}
@@ -1,258 +0,0 @@
1
- "use strict";
2
- /**
3
- * Copyright (c) Microsoft Corporation.
4
- * Licensed under the MIT License.
5
- *
6
- * @format
7
- */
8
- Object.defineProperty(exports, "__esModule", { value: true });
9
- const telemetry_1 = require("../telemetry");
10
- const path_1 = require("path");
11
- const CodedError_1 = require("../CodedError");
12
- delete process.env.AGENT_NAME; // allow this test to run in Azure DevOps / GHA
13
- telemetry_1.Telemetry.setup(true);
14
- telemetry_1.Telemetry.client.config.disableAppInsights = true;
15
- test('Sanitize message, no-op', () => {
16
- // do stuff
17
- expect(telemetry_1.sanitizeMessage('')).toEqual('');
18
- expect(telemetry_1.sanitizeMessage('some text')).toEqual('some text');
19
- });
20
- test('Sanitize message, project_dir', () => {
21
- expect(telemetry_1.sanitizeMessage(`this is the cwd: '${process.cwd()}'`)).toEqual(`this is the cwd: [project_dir]\\???(${process.cwd().length})`);
22
- expect(telemetry_1.sanitizeMessage(`uppercase: '${process.cwd().toUpperCase()}'`)).toEqual(`uppercase: [project_dir]\\???(${process.cwd().length})`);
23
- expect(telemetry_1.sanitizeMessage(`lowercase: '${process.cwd().toLowerCase()}'`)).toEqual(`lowercase: [project_dir]\\???(${process.cwd().length})`);
24
- expect(telemetry_1.sanitizeMessage(`this is the cwd: '${process.cwd()}' and something else`)).toEqual(`this is the cwd: [project_dir]\\???(${process.cwd().length}) and something else`);
25
- expect(telemetry_1.sanitizeMessage(`this is the cwd: ${process.cwd()} and something else`)).toEqual(`this is the cwd: [project_dir]\\???(${(process.cwd() + ' and something else').length})`);
26
- });
27
- test('Sanitize message, node_modules', () => {
28
- expect(telemetry_1.sanitizeMessage(`this is the cwd: '${process.cwd()}\\node_modules'`)).toEqual(`this is the cwd: [project_dir]\\???(${(process.cwd() + '\\node_modules').length})`);
29
- expect(telemetry_1.sanitizeMessage(`this is the cwd: '${process.cwd()}\\node_modules\\foo'`)).toEqual('this is the cwd: node_modules\\foo');
30
- expect(telemetry_1.sanitizeMessage(`uppercase: '${process.cwd().toUpperCase()}\\NODE_MODULES\\foo'`)).toEqual('uppercase: node_modules\\foo');
31
- expect(telemetry_1.sanitizeMessage(`lowercase: '${process.cwd().toLowerCase()}\\NODE_MODULES\\'`)).toEqual('lowercase: node_modules\\');
32
- expect(telemetry_1.sanitizeMessage(`trailing: '${process.cwd()}\\node_modules\\' and something else`)).toEqual('trailing: node_modules\\ and something else');
33
- expect(telemetry_1.sanitizeMessage(`this is the cwd: ${process.cwd()}\\node_modules and something else that could be part of the path`)).toEqual(`this is the cwd: [project_dir]\\???(${(process.cwd() +
34
- '\\node_modules and something else that could be part of the path').length})`);
35
- expect(telemetry_1.sanitizeMessage(`this is the cwd: ${process.cwd()}\\node_modules\\ a file under nm`)).toEqual(`this is the cwd: node_modules\\ a file under nm`);
36
- });
37
- test('Sanitize message, other path', () => {
38
- expect(telemetry_1.sanitizeMessage(`this is another path: 'A:\\foo\\bar\\baz'`)).toEqual(`this is another path: [path]`);
39
- expect(telemetry_1.sanitizeMessage(`this is another path: A:\\foo\\bar\\baz`)).toEqual(`this is another path: [path]`);
40
- expect(telemetry_1.sanitizeMessage(`Cannot find module 'react-native/package.json'
41
- Require stack:
42
- - ${process.env.AppData}\\npm-cache\\_npx\\1384\\node_modules\\react-native-windows-init\\lib-commonjs\\Cli.js
43
- - ${process.env.AppData}\\npm-cache\\_npx\\1384\\node_modules\\react-native-windows-init\\bin.js`)).toEqual(`Cannot find module react-native/package.json
44
- Require stack:
45
- - [AppData]\\???(${(process.env.AppData +
46
- '\\npm-cache\\_npx\\1384\\node_modules\\react-native-windows-init\\lib-commonjs\\Cli.js').length})
47
- - [AppData]\\???(${(process.env.AppData +
48
- '\\npm-cache\\_npx\\1384\\node_modules\\react-native-windows-init\\bin.js').length})`);
49
- });
50
- test('Sanitize message, forward slashes', () => {
51
- expect(telemetry_1.sanitizeMessage(`EPERM: operation not permitted, scandir ${process.env.UserProfile.replace(/\\/g, '/')}/source/repos/rn2/wintest/windows/packages/boost.1.76.0.0/lib/native/include`)).toEqual(`EPERM: operation not permitted, scandir [UserProfile]\\???(${(process.env.UserProfile +
52
- '/source/repos/rn2/wintest/windows/packages/boost.1.76.0.0/lib/native/include').length})`);
53
- });
54
- test('Sanitize message, file share path', () => {
55
- expect(telemetry_1.sanitizeMessage(`\\\\server\\share`)).toEqual('[path]');
56
- });
57
- test('Sanitize message, with cpu/thread id', () => {
58
- expect(telemetry_1.sanitizeMessage('5>This is an error')).toEqual('This is an error');
59
- expect(telemetry_1.sanitizeMessage('5:42>This is an error')).toEqual('This is an error');
60
- });
61
- test('Error code', () => {
62
- expect(telemetry_1.tryGetErrorCode('foo bar error FOO2020: the thing')).toEqual('FOO2020');
63
- });
64
- test('Sanitize stack frame', () => {
65
- const emptyFrame = {
66
- level: 0,
67
- method: '',
68
- fileName: '',
69
- assembly: 'asdf',
70
- line: 0,
71
- };
72
- telemetry_1.sanitizeFrame(emptyFrame);
73
- expect(emptyFrame).toEqual({
74
- level: 0,
75
- assembly: '',
76
- fileName: '.',
77
- method: '',
78
- line: 0,
79
- });
80
- const frame1 = {
81
- method: '',
82
- fileName: `${process.cwd()}\\foo.js`,
83
- assembly: 'asdf',
84
- level: 0,
85
- line: 0,
86
- };
87
- telemetry_1.sanitizeFrame(frame1);
88
- expect(frame1).toEqual({
89
- assembly: '',
90
- fileName: 'telemetry\\foo.js',
91
- method: '',
92
- level: 0,
93
- line: 0,
94
- });
95
- const frame2 = {
96
- method: `myMethod (something ${process.cwd()}`,
97
- fileName: `${process.cwd()}\\foo.js`,
98
- assembly: 'asdf',
99
- level: 1,
100
- line: 42,
101
- };
102
- telemetry_1.sanitizeFrame(frame2);
103
- expect(frame2).toEqual({
104
- assembly: '',
105
- fileName: 'telemetry\\foo.js',
106
- method: 'myMethod',
107
- level: 1,
108
- line: 42,
109
- });
110
- });
111
- test('basic setup', () => {
112
- expect(telemetry_1.Telemetry.client.commonProperties.sessionId).toBeDefined();
113
- expect(telemetry_1.Telemetry.client.commonProperties.sessionId.length).toBeGreaterThanOrEqual(32);
114
- expect(telemetry_1.Telemetry.client.commonProperties.isTest).toEqual('true');
115
- });
116
- function b(s) {
117
- throw new Error('hello ' + s);
118
- }
119
- function a(s) {
120
- b(s);
121
- }
122
- test('thrown exception a->b, hello world', done => {
123
- let pass = false;
124
- telemetry_1.Telemetry.client.addTelemetryProcessor((envelope, _) => {
125
- if (envelope.data.baseType === 'ExceptionData') {
126
- const data = envelope.data.baseData;
127
- expect(data.exceptions).toBeDefined();
128
- expect(data.exceptions.length).toEqual(1);
129
- expect(data.exceptions[0].message).toEqual('hello world');
130
- const stack = data.exceptions[0].parsedStack;
131
- expect(stack).toBeDefined();
132
- expect(stack.length).toBeGreaterThan(5);
133
- const filename = path_1.basename(__filename);
134
- expect(stack[0].method).toEqual('b');
135
- expect(stack[1].method).toEqual('b');
136
- expect(stack[2].method).toEqual('Object.a');
137
- expect(stack[0].fileName).toEqual(`test\\${filename}`);
138
- expect(stack[1].fileName).toEqual(`test\\${filename}`);
139
- expect(stack[2].fileName).toEqual(`test\\${filename}`);
140
- pass = true;
141
- }
142
- return true;
143
- });
144
- try {
145
- a('world');
146
- }
147
- catch (e) {
148
- telemetry_1.Telemetry.client.trackException({ exception: e });
149
- }
150
- telemetry_1.Telemetry.client.flush();
151
- expect(pass).toBeTruthy();
152
- telemetry_1.Telemetry.client.clearTelemetryProcessors();
153
- telemetry_1.Telemetry.client.addTelemetryProcessor(telemetry_1.sanitizeEnvelope);
154
- done();
155
- });
156
- test('throw exception with error code', done => {
157
- telemetry_1.Telemetry.client.addTelemetryProcessor((envelope, _) => {
158
- const data = envelope.data.baseData;
159
- expect(data.properties.errorCode).toEqual('FOO2020');
160
- return true;
161
- });
162
- try {
163
- throw new Error('hello from an error FOO2020: the error string');
164
- }
165
- catch (e) {
166
- telemetry_1.Telemetry.client.trackException({ exception: e });
167
- telemetry_1.Telemetry.client.flush();
168
- }
169
- telemetry_1.Telemetry.client.clearTelemetryProcessors();
170
- telemetry_1.Telemetry.client.addTelemetryProcessor(telemetry_1.sanitizeEnvelope);
171
- done();
172
- });
173
- test('thrown exception a->b, hello path', done => {
174
- let pass = false;
175
- telemetry_1.Telemetry.client.addTelemetryProcessor((envelope, _) => {
176
- if (envelope.data.baseType === 'ExceptionData') {
177
- const data = envelope.data.baseData;
178
- expect(data.exceptions).toBeDefined();
179
- expect(data.exceptions.length).toEqual(1);
180
- expect(data.exceptions[0].message).toEqual(`hello [project_dir]\\???(${process.cwd().length})`);
181
- const stack = data.exceptions[0].parsedStack;
182
- expect(stack).toBeDefined();
183
- expect(stack.length).toBeGreaterThan(5);
184
- const filename = path_1.basename(__filename);
185
- expect(stack[0].method).toEqual('b');
186
- expect(stack[1].method).toEqual('b');
187
- expect(stack[2].method).toEqual('Object.a');
188
- expect(stack[0].fileName).toEqual(`test\\${filename}`);
189
- expect(stack[1].fileName).toEqual(`test\\${filename}`);
190
- expect(stack[2].fileName).toEqual(`test\\${filename}`);
191
- pass = true;
192
- }
193
- return true;
194
- });
195
- try {
196
- a(process.cwd());
197
- }
198
- catch (e) {
199
- telemetry_1.Telemetry.client.trackException({ exception: e });
200
- }
201
- telemetry_1.Telemetry.client.flush();
202
- expect(pass).toBeTruthy();
203
- expect(pass).toBeTruthy();
204
- telemetry_1.Telemetry.client.clearTelemetryProcessors();
205
- telemetry_1.Telemetry.client.addTelemetryProcessor(telemetry_1.sanitizeEnvelope);
206
- done();
207
- });
208
- test('trackEvent should not identify roleInstance', () => {
209
- telemetry_1.Telemetry.client.addTelemetryProcessor((envelope, _) => {
210
- expect(envelope.tags['ai.cloud.roleInstance']).toBeUndefined();
211
- return true;
212
- });
213
- telemetry_1.Telemetry.client.trackEvent({
214
- name: 'test',
215
- properties: {},
216
- });
217
- telemetry_1.Telemetry.client.flush();
218
- telemetry_1.Telemetry.client.clearTelemetryProcessors();
219
- telemetry_1.Telemetry.client.addTelemetryProcessor(telemetry_1.sanitizeEnvelope);
220
- });
221
- /////////////////////////
222
- // CodedError tests
223
- test('No message', done => {
224
- telemetry_1.Telemetry.preserveMessages = false;
225
- let pass = false;
226
- telemetry_1.Telemetry.client.addTelemetryProcessor((envelope, _) => {
227
- if (envelope.data.baseType === 'ExceptionData') {
228
- const data = envelope.data.baseData;
229
- expect(data.exceptions).toBeDefined();
230
- expect(data.exceptions.length).toEqual(1);
231
- expect(data.exceptions[0].message).toBeUndefined();
232
- expect(data.exceptions[0].typeName).toEqual('MSBuildError');
233
- // This should be 42, but instead it is '42'
234
- // https://github.com/microsoft/ApplicationInsights-node.js/issues/708
235
- expect(data.properties.foo).toBeDefined();
236
- expect(parseInt(data.properties.foo, 10)).toEqual(42);
237
- pass = true;
238
- }
239
- return true;
240
- });
241
- try {
242
- throw new CodedError_1.CodedError('MSBuildError', 'Something secret', {
243
- foo: 42,
244
- });
245
- }
246
- catch (e) {
247
- telemetry_1.Telemetry.client.trackException({
248
- exception: e,
249
- properties: e.data,
250
- });
251
- telemetry_1.Telemetry.client.flush();
252
- }
253
- expect(pass).toEqual(true);
254
- telemetry_1.Telemetry.client.clearTelemetryProcessors();
255
- telemetry_1.Telemetry.client.addTelemetryProcessor(telemetry_1.sanitizeEnvelope);
256
- done();
257
- });
258
- //# sourceMappingURL=sanitize.test.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"sanitize.test.js","sourceRoot":"","sources":["../../src/test/sanitize.test.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;AAEH,4CAMsB;AAEtB,+BAA8B;AAC9B,8CAAyC;AAEzC,OAAO,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC,+CAA+C;AAC9E,qBAAS,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;AACtB,qBAAS,CAAC,MAAO,CAAC,MAAM,CAAC,kBAAkB,GAAG,IAAI,CAAC;AAEnD,IAAI,CAAC,yBAAyB,EAAE,GAAG,EAAE;IACnC,WAAW;IACX,MAAM,CAAC,2BAAe,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,EA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AAO,CAAC,qBAAqB,CAAC,4BAAgB,CAAC,CAAC;IAC1D,IAAI,EAAE,CAAC;AACT,CAAC,CAAC,CAAC","sourcesContent":["/**\n * Copyright (c) Microsoft Corporation.\n * Licensed under the MIT License.\n *\n * @format\n */\n\nimport {\n Telemetry,\n sanitizeMessage,\n sanitizeEnvelope,\n sanitizeFrame,\n tryGetErrorCode,\n} from '../telemetry';\nimport * as appInsights from 'applicationinsights';\nimport {basename} from 'path';\nimport {CodedError} from '../CodedError';\n\ndelete process.env.AGENT_NAME; // allow this test to run in Azure DevOps / GHA\nTelemetry.setup(true);\nTelemetry.client!.config.disableAppInsights = true;\n\ntest('Sanitize message, no-op', () => {\n // do stuff\n expect(sanitizeMessage('')).toEqual('');\n expect(sanitizeMessage('some text')).toEqual('some text');\n});\n\ntest('Sanitize message, project_dir', () => {\n expect(sanitizeMessage(`this is the cwd: '${process.cwd()}'`)).toEqual(\n `this is the cwd: [project_dir]\\\\???(${process.cwd().length})`,\n );\n expect(\n sanitizeMessage(`uppercase: '${process.cwd().toUpperCase()}'`),\n ).toEqual(`uppercase: [project_dir]\\\\???(${process.cwd().length})`);\n expect(\n sanitizeMessage(`lowercase: '${process.cwd().toLowerCase()}'`),\n ).toEqual(`lowercase: [project_dir]\\\\???(${process.cwd().length})`);\n expect(\n sanitizeMessage(`this is the cwd: '${process.cwd()}' and something else`),\n ).toEqual(\n `this is the cwd: [project_dir]\\\\???(${\n process.cwd().length\n }) and something else`,\n );\n expect(\n sanitizeMessage(`this is the cwd: ${process.cwd()} and something else`),\n ).toEqual(\n `this is the cwd: [project_dir]\\\\???(${\n (process.cwd() + ' and something else').length\n })`,\n );\n});\n\ntest('Sanitize message, node_modules', () => {\n expect(\n sanitizeMessage(`this is the cwd: '${process.cwd()}\\\\node_modules'`),\n ).toEqual(\n `this is the cwd: [project_dir]\\\\???(${\n (process.cwd() + '\\\\node_modules').length\n })`,\n );\n expect(\n sanitizeMessage(`this is the cwd: '${process.cwd()}\\\\node_modules\\\\foo'`),\n ).toEqual('this is the cwd: node_modules\\\\foo');\n expect(\n sanitizeMessage(\n `uppercase: '${process.cwd().toUpperCase()}\\\\NODE_MODULES\\\\foo'`,\n ),\n ).toEqual('uppercase: node_modules\\\\foo');\n expect(\n sanitizeMessage(\n `lowercase: '${process.cwd().toLowerCase()}\\\\NODE_MODULES\\\\'`,\n ),\n ).toEqual('lowercase: node_modules\\\\');\n expect(\n sanitizeMessage(\n `trailing: '${process.cwd()}\\\\node_modules\\\\' and something else`,\n ),\n ).toEqual('trailing: node_modules\\\\ and something else');\n expect(\n sanitizeMessage(\n `this is the cwd: ${process.cwd()}\\\\node_modules and something else that could be part of the path`,\n ),\n ).toEqual(\n `this is the cwd: [project_dir]\\\\???(${\n (\n process.cwd() +\n '\\\\node_modules and something else that could be part of the path'\n ).length\n })`,\n );\n expect(\n sanitizeMessage(\n `this is the cwd: ${process.cwd()}\\\\node_modules\\\\ a file under nm`,\n ),\n ).toEqual(`this is the cwd: node_modules\\\\ a file under nm`);\n});\n\ntest('Sanitize message, other path', () => {\n expect(sanitizeMessage(`this is another path: 'A:\\\\foo\\\\bar\\\\baz'`)).toEqual(\n `this is another path: [path]`,\n );\n\n expect(sanitizeMessage(`this is another path: A:\\\\foo\\\\bar\\\\baz`)).toEqual(\n `this is another path: [path]`,\n );\n\n expect(\n sanitizeMessage(\n `Cannot find module 'react-native/package.json'\n Require stack:\n - ${process.env.AppData}\\\\npm-cache\\\\_npx\\\\1384\\\\node_modules\\\\react-native-windows-init\\\\lib-commonjs\\\\Cli.js\n - ${process.env.AppData}\\\\npm-cache\\\\_npx\\\\1384\\\\node_modules\\\\react-native-windows-init\\\\bin.js`,\n ),\n ).toEqual(`Cannot find module react-native/package.json \n Require stack:\n - [AppData]\\\\???(${\n (\n process.env.AppData +\n '\\\\npm-cache\\\\_npx\\\\1384\\\\node_modules\\\\react-native-windows-init\\\\lib-commonjs\\\\Cli.js'\n ).length\n })\n - [AppData]\\\\???(${\n (\n process.env.AppData +\n '\\\\npm-cache\\\\_npx\\\\1384\\\\node_modules\\\\react-native-windows-init\\\\bin.js'\n ).length\n })`);\n});\n\ntest('Sanitize message, forward slashes', () => {\n expect(\n sanitizeMessage(\n `EPERM: operation not permitted, scandir ${process.env.UserProfile!.replace(\n /\\\\/g,\n '/',\n )}/source/repos/rn2/wintest/windows/packages/boost.1.76.0.0/lib/native/include`,\n ),\n ).toEqual(\n `EPERM: operation not permitted, scandir [UserProfile]\\\\???(${\n (\n process.env.UserProfile +\n '/source/repos/rn2/wintest/windows/packages/boost.1.76.0.0/lib/native/include'\n ).length\n })`,\n );\n});\n\ntest('Sanitize message, file share path', () => {\n expect(sanitizeMessage(`\\\\\\\\server\\\\share`)).toEqual('[path]');\n});\n\ntest('Sanitize message, with cpu/thread id', () => {\n expect(sanitizeMessage('5>This is an error')).toEqual('This is an error');\n\n expect(sanitizeMessage('5:42>This is an error')).toEqual('This is an error');\n});\n\ntest('Error code', () => {\n expect(tryGetErrorCode('foo bar error FOO2020: the thing')).toEqual(\n 'FOO2020',\n );\n});\n\ntest('Sanitize stack frame', () => {\n const emptyFrame: appInsights.Contracts.StackFrame = {\n level: 0,\n method: '',\n fileName: '',\n assembly: 'asdf',\n line: 0,\n };\n sanitizeFrame(emptyFrame);\n expect(emptyFrame).toEqual({\n level: 0,\n assembly: '',\n fileName: '.',\n method: '',\n line: 0,\n });\n\n const frame1: appInsights.Contracts.StackFrame = {\n method: '',\n fileName: `${process.cwd()}\\\\foo.js`,\n assembly: 'asdf',\n level: 0,\n line: 0,\n };\n sanitizeFrame(frame1);\n expect(frame1).toEqual({\n assembly: '',\n fileName: 'telemetry\\\\foo.js',\n method: '',\n level: 0,\n line: 0,\n });\n\n const frame2: appInsights.Contracts.StackFrame = {\n method: `myMethod (something ${process.cwd()}`,\n fileName: `${process.cwd()}\\\\foo.js`,\n assembly: 'asdf',\n level: 1,\n line: 42,\n };\n sanitizeFrame(frame2);\n expect(frame2).toEqual({\n assembly: '',\n fileName: 'telemetry\\\\foo.js',\n method: 'myMethod',\n level: 1,\n line: 42,\n });\n});\n\ntest('basic setup', () => {\n expect(Telemetry.client!.commonProperties.sessionId).toBeDefined();\n\n expect(\n Telemetry.client!.commonProperties.sessionId.length,\n ).toBeGreaterThanOrEqual(32);\n\n expect(Telemetry.client!.commonProperties.isTest).toEqual('true');\n});\n\nfunction b(s: string) {\n throw new Error('hello ' + s);\n}\nfunction a(s: string) {\n b(s);\n}\n\ntest('thrown exception a->b, hello world', done => {\n let pass = false;\n Telemetry.client!.addTelemetryProcessor((envelope, _) => {\n if (envelope.data.baseType === 'ExceptionData') {\n const data = (envelope.data as any).baseData;\n expect(data.exceptions).toBeDefined();\n expect(data.exceptions.length).toEqual(1);\n expect(data.exceptions[0].message).toEqual('hello world');\n\n const stack = data.exceptions[0].parsedStack;\n expect(stack).toBeDefined();\n expect(stack.length).toBeGreaterThan(5);\n\n const filename = basename(__filename);\n expect(stack[0].method).toEqual('b');\n expect(stack[1].method).toEqual('b');\n expect(stack[2].method).toEqual('Object.a');\n expect(stack[0].fileName).toEqual(`test\\\\${filename}`);\n expect(stack[1].fileName).toEqual(`test\\\\${filename}`);\n expect(stack[2].fileName).toEqual(`test\\\\${filename}`);\n pass = true;\n }\n return true;\n });\n try {\n a('world');\n } catch (e) {\n Telemetry.client!.trackException({exception: e});\n }\n Telemetry.client!.flush();\n\n expect(pass).toBeTruthy();\n Telemetry.client!.clearTelemetryProcessors();\n Telemetry.client!.addTelemetryProcessor(sanitizeEnvelope);\n done();\n});\n\ntest('throw exception with error code', done => {\n Telemetry.client!.addTelemetryProcessor((envelope, _) => {\n const data = (envelope.data as any).baseData;\n expect(data.properties.errorCode).toEqual('FOO2020');\n return true;\n });\n\n try {\n throw new Error('hello from an error FOO2020: the error string');\n } catch (e) {\n Telemetry.client!.trackException({exception: e});\n Telemetry.client!.flush();\n }\n Telemetry.client!.clearTelemetryProcessors();\n Telemetry.client!.addTelemetryProcessor(sanitizeEnvelope);\n done();\n});\n\ntest('thrown exception a->b, hello path', done => {\n let pass = false;\n Telemetry.client!.addTelemetryProcessor((envelope, _) => {\n if (envelope.data.baseType === 'ExceptionData') {\n const data = (envelope.data as any).baseData;\n expect(data.exceptions).toBeDefined();\n expect(data.exceptions.length).toEqual(1);\n expect(data.exceptions[0].message).toEqual(\n `hello [project_dir]\\\\???(${process.cwd().length})`,\n );\n\n const stack = data.exceptions[0].parsedStack;\n expect(stack).toBeDefined();\n expect(stack.length).toBeGreaterThan(5);\n\n const filename = basename(__filename);\n expect(stack[0].method).toEqual('b');\n expect(stack[1].method).toEqual('b');\n expect(stack[2].method).toEqual('Object.a');\n expect(stack[0].fileName).toEqual(`test\\\\${filename}`);\n expect(stack[1].fileName).toEqual(`test\\\\${filename}`);\n expect(stack[2].fileName).toEqual(`test\\\\${filename}`);\n pass = true;\n }\n return true;\n });\n try {\n a(process.cwd());\n } catch (e) {\n Telemetry.client!.trackException({exception: e});\n }\n Telemetry.client!.flush();\n\n expect(pass).toBeTruthy();\n expect(pass).toBeTruthy();\n Telemetry.client!.clearTelemetryProcessors();\n Telemetry.client!.addTelemetryProcessor(sanitizeEnvelope);\n done();\n});\n\ntest('trackEvent should not identify roleInstance', () => {\n Telemetry.client!.addTelemetryProcessor((envelope, _) => {\n expect(envelope.tags['ai.cloud.roleInstance']).toBeUndefined();\n return true;\n });\n Telemetry.client!.trackEvent({\n name: 'test',\n properties: {},\n });\n Telemetry.client!.flush();\n Telemetry.client!.clearTelemetryProcessors();\n Telemetry.client!.addTelemetryProcessor(sanitizeEnvelope);\n});\n\n/////////////////////////\n// CodedError tests\ntest('No message', done => {\n Telemetry.preserveMessages = false;\n let pass = false;\n Telemetry.client!.addTelemetryProcessor((envelope, _) => {\n if (envelope.data.baseType === 'ExceptionData') {\n const data = (envelope.data as any).baseData;\n expect(data.exceptions).toBeDefined();\n expect(data.exceptions.length).toEqual(1);\n expect(data.exceptions[0].message).toBeUndefined();\n expect(data.exceptions[0].typeName).toEqual('MSBuildError');\n // This should be 42, but instead it is '42'\n // https://github.com/microsoft/ApplicationInsights-node.js/issues/708\n expect(data.properties.foo).toBeDefined();\n expect(parseInt(data.properties.foo, 10)).toEqual(42);\n pass = true;\n }\n return true;\n });\n\n try {\n throw new CodedError('MSBuildError', 'Something secret', {\n foo: 42,\n });\n } catch (e) {\n Telemetry.client!.trackException({\n exception: e,\n properties: (e as CodedError).data,\n });\n Telemetry.client!.flush();\n }\n\n expect(pass).toEqual(true);\n Telemetry.client!.clearTelemetryProcessors();\n Telemetry.client!.addTelemetryProcessor(sanitizeEnvelope);\n done();\n});\n"]}