@react-native-windows/telemetry 0.0.0-canary.12 → 0.0.0-canary.121
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.
- package/lib-commonjs/e2etest/telemetry.test.d.ts +26 -0
- package/lib-commonjs/e2etest/telemetry.test.js +574 -0
- package/lib-commonjs/e2etest/telemetry.test.js.map +1 -0
- package/lib-commonjs/index.d.ts +11 -7
- package/lib-commonjs/index.js +26 -14
- package/lib-commonjs/index.js.map +1 -1
- package/lib-commonjs/telemetry.d.ts +75 -29
- package/lib-commonjs/telemetry.js +433 -201
- package/lib-commonjs/telemetry.js.map +1 -1
- package/lib-commonjs/test/{sanitize.test.d.ts → basePropUtils.test.d.ts} +7 -7
- package/lib-commonjs/test/basePropUtils.test.js +145 -0
- package/lib-commonjs/test/basePropUtils.test.js.map +1 -0
- package/lib-commonjs/test/errorUtils.test.d.ts +7 -0
- package/lib-commonjs/test/errorUtils.test.js +160 -0
- package/lib-commonjs/test/errorUtils.test.js.map +1 -0
- package/lib-commonjs/test/nameUtils.test.d.ts +7 -0
- package/lib-commonjs/test/nameUtils.test.js +54 -0
- package/lib-commonjs/test/nameUtils.test.js.map +1 -0
- package/lib-commonjs/test/projectUtils.test.d.ts +7 -0
- package/lib-commonjs/test/projectUtils.test.js +88 -0
- package/lib-commonjs/test/projectUtils.test.js.map +1 -0
- package/lib-commonjs/test/sanitizeUtils.test.d.ts +7 -0
- package/lib-commonjs/test/sanitizeUtils.test.js +98 -0
- package/lib-commonjs/test/sanitizeUtils.test.js.map +1 -0
- package/lib-commonjs/test/versionUtils.test.d.ts +7 -0
- package/lib-commonjs/test/versionUtils.test.js +115 -0
- package/lib-commonjs/test/versionUtils.test.js.map +1 -0
- package/lib-commonjs/utils/basePropUtils.d.ts +92 -0
- package/lib-commonjs/utils/basePropUtils.js +217 -0
- package/lib-commonjs/utils/basePropUtils.js.map +1 -0
- package/lib-commonjs/{CodedError.d.ts → utils/errorUtils.d.ts} +93 -61
- package/lib-commonjs/utils/errorUtils.js +183 -0
- package/lib-commonjs/utils/errorUtils.js.map +1 -0
- package/lib-commonjs/utils/nameUtils.d.ts +7 -0
- package/lib-commonjs/utils/nameUtils.js +22 -0
- package/lib-commonjs/utils/nameUtils.js.map +1 -0
- package/lib-commonjs/utils/optionUtils.d.ts +45 -0
- package/lib-commonjs/utils/optionUtils.js +96 -0
- package/lib-commonjs/utils/optionUtils.js.map +1 -0
- package/lib-commonjs/utils/projectUtils.d.ts +50 -0
- package/lib-commonjs/utils/projectUtils.js +187 -0
- package/lib-commonjs/utils/projectUtils.js.map +1 -0
- package/lib-commonjs/utils/sanitizeUtils.d.ts +12 -0
- package/lib-commonjs/utils/sanitizeUtils.js +85 -0
- package/lib-commonjs/utils/sanitizeUtils.js.map +1 -0
- package/lib-commonjs/utils/versionUtils.d.ts +38 -0
- package/lib-commonjs/utils/versionUtils.js +156 -0
- package/lib-commonjs/utils/versionUtils.js.map +1 -0
- package/package.json +39 -22
- package/CHANGELOG.json +0 -170
- package/CHANGELOG.md +0 -87
- package/lib-commonjs/CodedError.js +0 -77
- package/lib-commonjs/CodedError.js.map +0 -1
- package/lib-commonjs/test/sanitize.test.js +0 -258
- package/lib-commonjs/test/sanitize.test.js.map +0 -1
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Microsoft Corporation.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*
|
|
5
|
+
* @format
|
|
6
|
+
*/
|
|
7
|
+
import * as coreOneDS from '@microsoft/1ds-core-js';
|
|
8
|
+
import { Telemetry, TelemetryOptions } from '../telemetry';
|
|
9
|
+
export declare class TelemetryTest extends Telemetry {
|
|
10
|
+
protected static hasTestTelemetryProviders: boolean;
|
|
11
|
+
protected static testTelemetryProvidersRan: boolean;
|
|
12
|
+
/** Run at the beginning of each test. */
|
|
13
|
+
static startTest(options?: Partial<TelemetryOptions>): Promise<void>;
|
|
14
|
+
/** Run at the end of each test where telemetry was fired. */
|
|
15
|
+
static endTest(finalCallback?: () => void): void;
|
|
16
|
+
/** Sets that the telemetry provider has run. */
|
|
17
|
+
static setTestTelemetryProvidersRan(): void;
|
|
18
|
+
/** Retrieves the value of a common property.*/
|
|
19
|
+
static getCommonProperty(key: string): string | undefined;
|
|
20
|
+
/** Retrieves the version of the specified tool/package. */
|
|
21
|
+
static getVersion(key: string): string | null;
|
|
22
|
+
/** Retrieves the value of the preserveErrorMessages option. */
|
|
23
|
+
static getPreserveErrorMessages(): boolean;
|
|
24
|
+
/** Adds a telemetry processor, usually for verifying the envelope. */
|
|
25
|
+
static addTelemetryInitializer(telemetryInitializer: (envelope: coreOneDS.ITelemetryItem) => boolean): void;
|
|
26
|
+
}
|
|
@@ -0,0 +1,574 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) Microsoft Corporation.
|
|
4
|
+
* Licensed under the MIT License.
|
|
5
|
+
*
|
|
6
|
+
* @format
|
|
7
|
+
*/
|
|
8
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
9
|
+
if (k2 === undefined) k2 = k;
|
|
10
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
11
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
12
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
13
|
+
}
|
|
14
|
+
Object.defineProperty(o, k2, desc);
|
|
15
|
+
}) : (function(o, m, k, k2) {
|
|
16
|
+
if (k2 === undefined) k2 = k;
|
|
17
|
+
o[k2] = m[k];
|
|
18
|
+
}));
|
|
19
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
20
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
21
|
+
}) : function(o, v) {
|
|
22
|
+
o["default"] = v;
|
|
23
|
+
});
|
|
24
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
25
|
+
if (mod && mod.__esModule) return mod;
|
|
26
|
+
var result = {};
|
|
27
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
28
|
+
__setModuleDefault(result, mod);
|
|
29
|
+
return result;
|
|
30
|
+
};
|
|
31
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
32
|
+
exports.TelemetryTest = void 0;
|
|
33
|
+
const path = __importStar(require("path"));
|
|
34
|
+
const telemetry_1 = require("../telemetry");
|
|
35
|
+
const basePropUtils = __importStar(require("../utils/basePropUtils"));
|
|
36
|
+
const errorUtils = __importStar(require("../utils/errorUtils"));
|
|
37
|
+
const projectUtils = __importStar(require("../utils/projectUtils"));
|
|
38
|
+
const versionUtils = __importStar(require("../utils/versionUtils"));
|
|
39
|
+
class CustomTestError extends Error {
|
|
40
|
+
constructor(message) {
|
|
41
|
+
super(message);
|
|
42
|
+
this.name = 'CustomTestError';
|
|
43
|
+
this.errno = '123';
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
class TelemetryTest extends telemetry_1.Telemetry {
|
|
47
|
+
/** Run at the beginning of each test. */
|
|
48
|
+
static async startTest(options) {
|
|
49
|
+
TelemetryTest.hasTestTelemetryProviders = false;
|
|
50
|
+
TelemetryTest.testTelemetryProvidersRan = false;
|
|
51
|
+
if (TelemetryTest.isEnabled()) {
|
|
52
|
+
telemetry_1.Telemetry.reset();
|
|
53
|
+
}
|
|
54
|
+
// Ensure that we don't actually fire events when testing
|
|
55
|
+
telemetry_1.Telemetry.isTestEnvironment = true;
|
|
56
|
+
await telemetry_1.Telemetry.setup(options);
|
|
57
|
+
}
|
|
58
|
+
/** Run at the end of each test where telemetry was fired. */
|
|
59
|
+
static endTest(finalCallback) {
|
|
60
|
+
var _a;
|
|
61
|
+
(_a = telemetry_1.Telemetry.appInsightsCore) === null || _a === void 0 ? void 0 : _a.flush(undefined /* isAsync */, () => {
|
|
62
|
+
// Your callback logic here
|
|
63
|
+
if (TelemetryTest.hasTestTelemetryProviders) {
|
|
64
|
+
expect(TelemetryTest.testTelemetryProvidersRan).toBe(true);
|
|
65
|
+
}
|
|
66
|
+
if (finalCallback) {
|
|
67
|
+
finalCallback();
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
/** Sets that the telemetry provider has run. */
|
|
72
|
+
static setTestTelemetryProvidersRan() {
|
|
73
|
+
TelemetryTest.testTelemetryProvidersRan = true;
|
|
74
|
+
}
|
|
75
|
+
/** Retrieves the value of a common property.*/
|
|
76
|
+
static getCommonProperty(key) {
|
|
77
|
+
return TelemetryTest.commonProperties[key];
|
|
78
|
+
}
|
|
79
|
+
/** Retrieves the version of the specified tool/package. */
|
|
80
|
+
static getVersion(key) {
|
|
81
|
+
return key in TelemetryTest.versionsProp
|
|
82
|
+
? TelemetryTest.versionsProp[key]
|
|
83
|
+
: null;
|
|
84
|
+
}
|
|
85
|
+
/** Retrieves the value of the preserveErrorMessages option. */
|
|
86
|
+
static getPreserveErrorMessages() {
|
|
87
|
+
return TelemetryTest.options.preserveErrorMessages;
|
|
88
|
+
}
|
|
89
|
+
/** Adds a telemetry processor, usually for verifying the envelope. */
|
|
90
|
+
static addTelemetryInitializer(telemetryInitializer) {
|
|
91
|
+
var _a;
|
|
92
|
+
(_a = TelemetryTest.appInsightsCore) === null || _a === void 0 ? void 0 : _a.addTelemetryInitializer(telemetryInitializer);
|
|
93
|
+
TelemetryTest.hasTestTelemetryProviders = true;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
exports.TelemetryTest = TelemetryTest;
|
|
97
|
+
test('setup() verify session id is valid and a common property', async () => {
|
|
98
|
+
await TelemetryTest.startTest();
|
|
99
|
+
const sessionId = TelemetryTest.getSessionId();
|
|
100
|
+
expect(sessionId).toBeDefined();
|
|
101
|
+
expect(sessionId).toHaveLength(32);
|
|
102
|
+
expect(sessionId).toBe(basePropUtils.getSessionId());
|
|
103
|
+
expect(TelemetryTest.getCommonProperty('sessionId')).toBe(sessionId);
|
|
104
|
+
TelemetryTest.endTest();
|
|
105
|
+
});
|
|
106
|
+
test('setup() verify static common property values with async sources', async () => {
|
|
107
|
+
await TelemetryTest.startTest();
|
|
108
|
+
const props = {
|
|
109
|
+
deviceId: basePropUtils.deviceId,
|
|
110
|
+
deviceLocale: basePropUtils.deviceLocale,
|
|
111
|
+
};
|
|
112
|
+
for (const key in props) {
|
|
113
|
+
if (!(key in Object.prototype)) {
|
|
114
|
+
const value = TelemetryTest.getCommonProperty(key);
|
|
115
|
+
expect(value).toBeDefined();
|
|
116
|
+
expect(value).toBe(await props[key]());
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
TelemetryTest.endTest();
|
|
120
|
+
});
|
|
121
|
+
test('setup() verify static common property values with sync sources', async () => {
|
|
122
|
+
await TelemetryTest.startTest();
|
|
123
|
+
const props = {
|
|
124
|
+
deviceArchitecture: () => basePropUtils.deviceArchitecture(),
|
|
125
|
+
nodePlatform: () => basePropUtils.nodePlatform(),
|
|
126
|
+
deviceNumCPUs: () => basePropUtils.deviceNumCPUs().toString(),
|
|
127
|
+
deviceTotalMemory: () => basePropUtils.deviceTotalMemory().toString(),
|
|
128
|
+
ciCaptured: () => basePropUtils.captureCI().toString(),
|
|
129
|
+
ciType: () => basePropUtils.ciType(),
|
|
130
|
+
isMsftInternal: () => basePropUtils.isMsftInternal().toString(),
|
|
131
|
+
isTest: () => 'true',
|
|
132
|
+
};
|
|
133
|
+
for (const key in props) {
|
|
134
|
+
if (!(key in Object.prototype)) {
|
|
135
|
+
const value = TelemetryTest.getCommonProperty(key);
|
|
136
|
+
expect(value).toBeDefined();
|
|
137
|
+
expect(value).toBe(props[key]());
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
TelemetryTest.endTest();
|
|
141
|
+
});
|
|
142
|
+
test('setup() verify other common property values are defined', async () => {
|
|
143
|
+
await TelemetryTest.startTest();
|
|
144
|
+
const props = ['deviceDiskFreeSpace'];
|
|
145
|
+
for (const key of props) {
|
|
146
|
+
const value = TelemetryTest.getCommonProperty(key);
|
|
147
|
+
expect(value).toBeDefined();
|
|
148
|
+
}
|
|
149
|
+
TelemetryTest.endTest();
|
|
150
|
+
});
|
|
151
|
+
test('setup() verify tool versions are populated', async () => {
|
|
152
|
+
await TelemetryTest.startTest();
|
|
153
|
+
const props = {
|
|
154
|
+
node: versionUtils.getNodeVersion,
|
|
155
|
+
npm: versionUtils.getNpmVersion,
|
|
156
|
+
yarn: versionUtils.getYarnVersion,
|
|
157
|
+
VisualStudio: versionUtils.getVisualStudioVersion,
|
|
158
|
+
};
|
|
159
|
+
for (const key in props) {
|
|
160
|
+
if (!(key in Object.prototype)) {
|
|
161
|
+
const value = await props[key]();
|
|
162
|
+
expect(value).toBe(TelemetryTest.getVersion(key));
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
TelemetryTest.endTest();
|
|
166
|
+
});
|
|
167
|
+
test('tryUpdateVersionsProp() returns true for adding a new version', async () => {
|
|
168
|
+
await TelemetryTest.startTest();
|
|
169
|
+
const name = 'test';
|
|
170
|
+
const version = '1.0';
|
|
171
|
+
expect(await TelemetryTest.tryUpdateVersionsProp(name, async () => version)).toBe(true);
|
|
172
|
+
expect(TelemetryTest.getVersion(name)).toBe(version);
|
|
173
|
+
TelemetryTest.endTest();
|
|
174
|
+
});
|
|
175
|
+
test('tryUpdateVersionsProp() returns false for adding an existing version with refresh is false', async () => {
|
|
176
|
+
await TelemetryTest.startTest();
|
|
177
|
+
const name = 'test';
|
|
178
|
+
const version = '1.0';
|
|
179
|
+
expect(await TelemetryTest.tryUpdateVersionsProp(name, async () => version)).toBe(true);
|
|
180
|
+
let getValueCalled = false;
|
|
181
|
+
expect(await TelemetryTest.tryUpdateVersionsProp(name, async () => {
|
|
182
|
+
getValueCalled = true;
|
|
183
|
+
return version;
|
|
184
|
+
})).toBe(false);
|
|
185
|
+
expect(getValueCalled).toBe(false);
|
|
186
|
+
TelemetryTest.endTest();
|
|
187
|
+
});
|
|
188
|
+
test('tryUpdateVersionsProp() returns true for adding an existing version with refresh is true', async () => {
|
|
189
|
+
await TelemetryTest.startTest();
|
|
190
|
+
const name = 'test';
|
|
191
|
+
const version = '1.0';
|
|
192
|
+
expect(await TelemetryTest.tryUpdateVersionsProp(name, async () => version)).toBe(true);
|
|
193
|
+
let getValueCalled = false;
|
|
194
|
+
expect(await TelemetryTest.tryUpdateVersionsProp(name, async () => {
|
|
195
|
+
getValueCalled = true;
|
|
196
|
+
return version;
|
|
197
|
+
}, true)).toBe(true);
|
|
198
|
+
expect(getValueCalled).toBe(true);
|
|
199
|
+
TelemetryTest.endTest();
|
|
200
|
+
});
|
|
201
|
+
/** Returns the CommandStartInfo for our fake 'test-command'. */
|
|
202
|
+
function getTestCommandStartInfo() {
|
|
203
|
+
return {
|
|
204
|
+
commandName: 'test-command',
|
|
205
|
+
args: {
|
|
206
|
+
testArg1: 'true',
|
|
207
|
+
testArg2: '10',
|
|
208
|
+
testArg3: 'testValue',
|
|
209
|
+
},
|
|
210
|
+
options: {
|
|
211
|
+
testArg0: 'unsetArg',
|
|
212
|
+
testArg1: true,
|
|
213
|
+
testArg2: 10,
|
|
214
|
+
testArg3: 'testValue',
|
|
215
|
+
},
|
|
216
|
+
defaultOptions: {
|
|
217
|
+
testArg0: 'unsetArg',
|
|
218
|
+
testArg1: false,
|
|
219
|
+
testArg2: 0,
|
|
220
|
+
testArg3: 'defaultValue',
|
|
221
|
+
},
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
/** Returns the CommandEndInfo for our fake 'test-command'. */
|
|
225
|
+
function getTestCommandEndInfo(resultCode) {
|
|
226
|
+
return {
|
|
227
|
+
resultCode,
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
function getTestCommandProjectInfo() {
|
|
231
|
+
return {
|
|
232
|
+
id: projectUtils.getProjectId('test-app-project'),
|
|
233
|
+
platforms: ['windows'],
|
|
234
|
+
rnwLang: 'cpp',
|
|
235
|
+
usesTS: true,
|
|
236
|
+
usesRNConfig: false,
|
|
237
|
+
jsEngine: 'Chakra',
|
|
238
|
+
rnwSource: 'Source',
|
|
239
|
+
dependencies: [
|
|
240
|
+
{
|
|
241
|
+
id: projectUtils.getProjectId('test-module-project'),
|
|
242
|
+
platforms: ['android', 'windows'],
|
|
243
|
+
rnwLang: 'cpp',
|
|
244
|
+
},
|
|
245
|
+
],
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
function getExtraProps() {
|
|
249
|
+
return {
|
|
250
|
+
extraProp1: true,
|
|
251
|
+
extraProp2: 1234,
|
|
252
|
+
extraProp3: 'test',
|
|
253
|
+
extraProp4: ['test'],
|
|
254
|
+
extraProp5: {
|
|
255
|
+
nestedProp1: true,
|
|
256
|
+
nestedProp2: 1234,
|
|
257
|
+
},
|
|
258
|
+
};
|
|
259
|
+
}
|
|
260
|
+
/** Asynchronously waits the number in ms. */
|
|
261
|
+
async function promiseDelay(ms) {
|
|
262
|
+
return new Promise(resolve => setTimeout(resolve, ms));
|
|
263
|
+
}
|
|
264
|
+
/** The body of the fake 'test-command' which will throw the provided error. */
|
|
265
|
+
async function testCommandBody(errorToThrow) {
|
|
266
|
+
await promiseDelay(100);
|
|
267
|
+
if (errorToThrow) {
|
|
268
|
+
throw errorToThrow;
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
/** Runs the complete 'test-command' with the right Telemetry setup and cleanup. */
|
|
272
|
+
async function runTestCommandE2E(commandBody) {
|
|
273
|
+
TelemetryTest.startCommand(getTestCommandStartInfo());
|
|
274
|
+
TelemetryTest.setProjectInfo(getTestCommandProjectInfo());
|
|
275
|
+
let errorCode = 'Success';
|
|
276
|
+
let caughtError;
|
|
277
|
+
try {
|
|
278
|
+
await commandBody();
|
|
279
|
+
}
|
|
280
|
+
catch (ex) {
|
|
281
|
+
caughtError = ex instanceof Error ? ex : new Error(String(ex));
|
|
282
|
+
errorCode =
|
|
283
|
+
caughtError instanceof errorUtils.CodedError
|
|
284
|
+
? caughtError.type
|
|
285
|
+
: 'Unknown';
|
|
286
|
+
TelemetryTest.trackException(caughtError);
|
|
287
|
+
}
|
|
288
|
+
TelemetryTest.endCommand(getTestCommandEndInfo(errorCode), getExtraProps());
|
|
289
|
+
}
|
|
290
|
+
/** Verifies the contents of events fired during the 'test-command'. */
|
|
291
|
+
function verifyTestCommandTelemetryProcessor(caughtErrors, expectedResultCode, expectedError) {
|
|
292
|
+
return envelope => {
|
|
293
|
+
var _a, _b;
|
|
294
|
+
TelemetryTest.setTestTelemetryProvidersRan();
|
|
295
|
+
try {
|
|
296
|
+
// Processor has run, so the test can (potentially) pass
|
|
297
|
+
const properties = envelope.baseData;
|
|
298
|
+
expect(properties).toBeDefined();
|
|
299
|
+
// Verify basics
|
|
300
|
+
const commonProperties = properties.common;
|
|
301
|
+
expect(commonProperties.commandName).toBe('test-command');
|
|
302
|
+
// Verify versions info
|
|
303
|
+
const versions = properties.versions;
|
|
304
|
+
expect(versions).toBeDefined();
|
|
305
|
+
expect(Object.keys(versions).length).toBeGreaterThan(0);
|
|
306
|
+
for (const key of Object.keys(versions)) {
|
|
307
|
+
expect(versions[key]).toBe(TelemetryTest.getVersion(key));
|
|
308
|
+
}
|
|
309
|
+
// Verify project info
|
|
310
|
+
const project = properties.project;
|
|
311
|
+
expect(project).toStrictEqual(getTestCommandProjectInfo());
|
|
312
|
+
// Verify properties exclusive to error scenarios
|
|
313
|
+
if (envelope.name === telemetry_1.CodedErrorEventName) {
|
|
314
|
+
// Verify exception info
|
|
315
|
+
const exceptionData = envelope.data.exceptionData;
|
|
316
|
+
expect(exceptionData).toBeDefined();
|
|
317
|
+
expect(exceptionData.message).toBeDefined();
|
|
318
|
+
expect(exceptionData.message).not.toBe('');
|
|
319
|
+
expect(exceptionData.message).toBe(TelemetryTest.getPreserveErrorMessages()
|
|
320
|
+
? errorUtils.sanitizeErrorMessage((expectedError === null || expectedError === void 0 ? void 0 : expectedError.message) || 'None')
|
|
321
|
+
: '[Removed]');
|
|
322
|
+
// Verify coded error info
|
|
323
|
+
const codedError = envelope.data.codedError;
|
|
324
|
+
expect(codedError).toBeDefined();
|
|
325
|
+
expect(codedError.type).toBe(expectedError instanceof errorUtils.CodedError
|
|
326
|
+
? expectedError.type
|
|
327
|
+
: 'Unknown');
|
|
328
|
+
// If the exception type is not CodedError but any data got copied into envelope.CodedError.data,
|
|
329
|
+
// for instance autolinking error info, build the expected CodedError.data.
|
|
330
|
+
let expectedCodedErrorData = {};
|
|
331
|
+
if (expectedError instanceof CustomTestError) {
|
|
332
|
+
expectedCodedErrorData = { errno: expectedError.errno };
|
|
333
|
+
}
|
|
334
|
+
expect(codedError.data).toStrictEqual((_a = expectedError.data) !== null && _a !== void 0 ? _a : expectedCodedErrorData);
|
|
335
|
+
}
|
|
336
|
+
else {
|
|
337
|
+
// If this is not error scenario, it must be a command successful event.
|
|
338
|
+
expect(envelope.name).toBe(telemetry_1.CommandEventName);
|
|
339
|
+
// Verify command info
|
|
340
|
+
const expectedInfo = getTestCommandStartInfo();
|
|
341
|
+
const command = envelope.data.command;
|
|
342
|
+
expect(command).toBeDefined();
|
|
343
|
+
expect(command.args).toStrictEqual(expectedInfo.args);
|
|
344
|
+
expect(command.options).toStrictEqual(expectedInfo.options);
|
|
345
|
+
expect(command.defaultOptions).toStrictEqual(expectedInfo.defaultOptions);
|
|
346
|
+
expect(command.durationInSecs).toBeGreaterThan(0);
|
|
347
|
+
expect(command.resultCode).toBe(expectedResultCode !== null && expectedResultCode !== void 0 ? expectedResultCode : 'Success');
|
|
348
|
+
// Verify extra props
|
|
349
|
+
const extraProps = getExtraProps();
|
|
350
|
+
expect((_b = envelope.data) === null || _b === void 0 ? void 0 : _b.additionalData).toStrictEqual(extraProps);
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
catch (ex) {
|
|
354
|
+
caughtErrors.push(ex instanceof Error ? ex : new Error(String(ex)));
|
|
355
|
+
}
|
|
356
|
+
return true;
|
|
357
|
+
};
|
|
358
|
+
}
|
|
359
|
+
test('Telemetry run test command end to end, verify event fires', async () => {
|
|
360
|
+
await TelemetryTest.startTest();
|
|
361
|
+
// AI eats errors thrown in telemetry processors
|
|
362
|
+
const caughtErrors = [];
|
|
363
|
+
TelemetryTest.addTelemetryInitializer(verifyTestCommandTelemetryProcessor(caughtErrors));
|
|
364
|
+
await runTestCommandE2E(testCommandBody);
|
|
365
|
+
TelemetryTest.endTest(() => {
|
|
366
|
+
// Check if any errors were thrown
|
|
367
|
+
expect(caughtErrors).toHaveLength(0);
|
|
368
|
+
});
|
|
369
|
+
});
|
|
370
|
+
const testTelemetryOptions = [
|
|
371
|
+
{ preserveErrorMessages: false },
|
|
372
|
+
{ preserveErrorMessages: true },
|
|
373
|
+
];
|
|
374
|
+
test.each(testTelemetryOptions)('Telemetry run test command end to end with CodedError, verify events fire %s', async (options) => {
|
|
375
|
+
await TelemetryTest.startTest(options);
|
|
376
|
+
const expectedError = new errorUtils.CodedError('MSBuildError', 'test error');
|
|
377
|
+
// AI eats errors thrown in telemetry processors
|
|
378
|
+
const caughtErrors = [];
|
|
379
|
+
TelemetryTest.addTelemetryInitializer(verifyTestCommandTelemetryProcessor(caughtErrors, expectedError.type, expectedError));
|
|
380
|
+
await runTestCommandE2E(() => testCommandBody(expectedError));
|
|
381
|
+
TelemetryTest.endTest(() => {
|
|
382
|
+
// Check if any errors were thrown
|
|
383
|
+
expect(caughtErrors).toHaveLength(0);
|
|
384
|
+
});
|
|
385
|
+
});
|
|
386
|
+
test.each(testTelemetryOptions)('Telemetry run test command end to end with CodedError (with error in message), verify events fire %s', async (options) => {
|
|
387
|
+
await TelemetryTest.startTest(options);
|
|
388
|
+
const expectedError = new errorUtils.CodedError('MSBuildError', 'error FOO2020: test error');
|
|
389
|
+
// AI eats errors thrown in telemetry processors
|
|
390
|
+
const caughtErrors = [];
|
|
391
|
+
TelemetryTest.addTelemetryInitializer(verifyTestCommandTelemetryProcessor(caughtErrors, expectedError.type, expectedError));
|
|
392
|
+
await runTestCommandE2E(() => testCommandBody(expectedError));
|
|
393
|
+
TelemetryTest.endTest(() => {
|
|
394
|
+
// Check if any errors were thrown
|
|
395
|
+
expect(caughtErrors).toHaveLength(0);
|
|
396
|
+
});
|
|
397
|
+
});
|
|
398
|
+
test.each(testTelemetryOptions)('Telemetry run test command end to end with CodedError (with data), verify events fire %s', async (options) => {
|
|
399
|
+
await TelemetryTest.startTest(options);
|
|
400
|
+
const expectedError = new errorUtils.CodedError('MSBuildError', 'test error', { foo: 42 });
|
|
401
|
+
// AI eats errors thrown in telemetry processors
|
|
402
|
+
const caughtErrors = [];
|
|
403
|
+
TelemetryTest.addTelemetryInitializer(verifyTestCommandTelemetryProcessor(caughtErrors, expectedError.type, expectedError));
|
|
404
|
+
await runTestCommandE2E(() => testCommandBody(expectedError));
|
|
405
|
+
TelemetryTest.endTest(() => {
|
|
406
|
+
// Check if any errors were thrown
|
|
407
|
+
expect(caughtErrors).toHaveLength(0);
|
|
408
|
+
});
|
|
409
|
+
});
|
|
410
|
+
test.each(testTelemetryOptions)('Telemetry run test command end to end with Error, verify events fire %s', async (options) => {
|
|
411
|
+
await TelemetryTest.startTest(options);
|
|
412
|
+
const expectedError = new Error('error FOO2020: test error');
|
|
413
|
+
// AI eats errors thrown in telemetry processors
|
|
414
|
+
const caughtErrors = [];
|
|
415
|
+
TelemetryTest.addTelemetryInitializer(verifyTestCommandTelemetryProcessor(caughtErrors, 'Unknown', expectedError));
|
|
416
|
+
await runTestCommandE2E(() => testCommandBody(expectedError));
|
|
417
|
+
TelemetryTest.endTest(() => {
|
|
418
|
+
// Check if any errors were thrown
|
|
419
|
+
expect(caughtErrors).toHaveLength(0);
|
|
420
|
+
});
|
|
421
|
+
});
|
|
422
|
+
test.each(testTelemetryOptions)('Telemetry run test command end to end with Error (no message), verify events fire %s', async (options) => {
|
|
423
|
+
await TelemetryTest.startTest(options);
|
|
424
|
+
const expectedError = new Error();
|
|
425
|
+
// AI eats errors thrown in telemetry processors
|
|
426
|
+
const caughtErrors = [];
|
|
427
|
+
TelemetryTest.addTelemetryInitializer(verifyTestCommandTelemetryProcessor(caughtErrors, 'Unknown', expectedError));
|
|
428
|
+
await runTestCommandE2E(() => testCommandBody(expectedError));
|
|
429
|
+
TelemetryTest.endTest(() => {
|
|
430
|
+
// Check if any errors were thrown
|
|
431
|
+
expect(caughtErrors).toHaveLength(0);
|
|
432
|
+
});
|
|
433
|
+
});
|
|
434
|
+
function b(s) {
|
|
435
|
+
throw new Error('hello ' + s);
|
|
436
|
+
}
|
|
437
|
+
function a(s) {
|
|
438
|
+
b(s);
|
|
439
|
+
}
|
|
440
|
+
/** Verifies the contents of an exception's message and stack frames */
|
|
441
|
+
function getVerifyStackTelemetryProcessor(caughtErrors, expectedError) {
|
|
442
|
+
return envelope => {
|
|
443
|
+
try {
|
|
444
|
+
// Processor has run, so the test can (potentially) pass
|
|
445
|
+
TelemetryTest.setTestTelemetryProvidersRan();
|
|
446
|
+
if (envelope.name === telemetry_1.CodedErrorEventName) {
|
|
447
|
+
const data = envelope.data;
|
|
448
|
+
expect(data.exceptionData).toBeDefined();
|
|
449
|
+
expect(data.exceptionData.message).toBeDefined();
|
|
450
|
+
expect(data.exceptionData.message).not.toBe('');
|
|
451
|
+
expect(data.exceptionData.message).toBe(TelemetryTest.getPreserveErrorMessages()
|
|
452
|
+
? errorUtils.sanitizeErrorMessage(expectedError.message || 'None')
|
|
453
|
+
: '[Removed]');
|
|
454
|
+
const stack = data.exceptionData.parsedStack;
|
|
455
|
+
expect(stack).toBeDefined();
|
|
456
|
+
expect(stack.length).toBeGreaterThan(2);
|
|
457
|
+
const filename = path.relative(process.cwd(), __filename);
|
|
458
|
+
expect(stack[0].functionName).toEqual('b');
|
|
459
|
+
expect(stack[1].functionName).toEqual('b');
|
|
460
|
+
expect(stack[2].functionName).toEqual('a');
|
|
461
|
+
expect(stack[0].filePath).toEqual(`[project_dir]\\???.ts(${filename.length})`);
|
|
462
|
+
expect(stack[1].filePath).toEqual(`[project_dir]\\???.ts(${filename.length})`);
|
|
463
|
+
expect(stack[2].filePath).toEqual(`[project_dir]\\???.ts(${filename.length})`);
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
catch (ex) {
|
|
467
|
+
caughtErrors.push(ex instanceof Error ? ex : new Error(String(ex)));
|
|
468
|
+
}
|
|
469
|
+
return true;
|
|
470
|
+
};
|
|
471
|
+
}
|
|
472
|
+
test.each(testTelemetryOptions)('Telemetry run test command end to end with Error, verify sanitized message and stack %s', async (options) => {
|
|
473
|
+
await TelemetryTest.startTest(options);
|
|
474
|
+
const expectedError = new Error('hello world');
|
|
475
|
+
// AI eats errors thrown in telemetry processors
|
|
476
|
+
const caughtErrors = [];
|
|
477
|
+
TelemetryTest.addTelemetryInitializer(getVerifyStackTelemetryProcessor(caughtErrors, expectedError));
|
|
478
|
+
await runTestCommandE2E(async () => {
|
|
479
|
+
await promiseDelay(100);
|
|
480
|
+
a('world');
|
|
481
|
+
});
|
|
482
|
+
TelemetryTest.endTest(() => {
|
|
483
|
+
// Check if any errors were thrown
|
|
484
|
+
expect(caughtErrors).toHaveLength(0);
|
|
485
|
+
});
|
|
486
|
+
});
|
|
487
|
+
test.each(testTelemetryOptions)('Telemetry run test command end to end with Error, verify sanitized message with path and stack %s', async (options) => {
|
|
488
|
+
await TelemetryTest.startTest(options);
|
|
489
|
+
const expectedError = new Error(`hello ${process.cwd()}`);
|
|
490
|
+
// AI eats errors thrown in telemetry processors
|
|
491
|
+
const caughtErrors = [];
|
|
492
|
+
TelemetryTest.addTelemetryInitializer(getVerifyStackTelemetryProcessor(caughtErrors, expectedError));
|
|
493
|
+
await runTestCommandE2E(async () => {
|
|
494
|
+
await promiseDelay(100);
|
|
495
|
+
a(process.cwd());
|
|
496
|
+
});
|
|
497
|
+
TelemetryTest.endTest(() => {
|
|
498
|
+
// Check if any errors were thrown
|
|
499
|
+
expect(caughtErrors).toHaveLength(0);
|
|
500
|
+
});
|
|
501
|
+
});
|
|
502
|
+
test.each(testTelemetryOptions)('A custom Error-based object with MS Build error info is copied into codedError.data appropriately by trackException()', async (options) => {
|
|
503
|
+
await TelemetryTest.startTest(options);
|
|
504
|
+
const expectedError = new CustomTestError('some message');
|
|
505
|
+
// AI eats errors thrown in telemetry processors
|
|
506
|
+
const caughtErrors = [];
|
|
507
|
+
TelemetryTest.addTelemetryInitializer(verifyTestCommandTelemetryProcessor(caughtErrors, 'Unknown', expectedError));
|
|
508
|
+
await runTestCommandE2E(() => testCommandBody(expectedError));
|
|
509
|
+
TelemetryTest.endTest(() => {
|
|
510
|
+
// Check if any errors were thrown
|
|
511
|
+
expect(caughtErrors).toHaveLength(0);
|
|
512
|
+
});
|
|
513
|
+
});
|
|
514
|
+
test.each(testTelemetryOptions)('Telemetry run test command end to end with CodedError, verifies PII is scrubbed if present in CodedError.', async (options) => {
|
|
515
|
+
await TelemetryTest.startTest(options);
|
|
516
|
+
const codedErrorInfo = new errorUtils.CodedError('MSBuildError', // type
|
|
517
|
+
'test error', // message
|
|
518
|
+
{
|
|
519
|
+
fieldWithPath: 'Test Error occurred at C:\\some\\file\\path\\project.build.appxrecipe',
|
|
520
|
+
fieldWithNoPath: 'Test Error data',
|
|
521
|
+
fieldWithNoString: 14,
|
|
522
|
+
arrayField: [
|
|
523
|
+
'No path',
|
|
524
|
+
15,
|
|
525
|
+
'Clean this path: C:\\some\\file\\path2\\project.build.appxrecipe',
|
|
526
|
+
[
|
|
527
|
+
'No path',
|
|
528
|
+
150,
|
|
529
|
+
'Also clean this: C:\\some\\file\\path2\\project.build.appxrecipe',
|
|
530
|
+
],
|
|
531
|
+
],
|
|
532
|
+
someObject: {
|
|
533
|
+
fieldWithPath: 'Test Error occurred at C:\\some\\file\\path3\\project.build.appxrecipe',
|
|
534
|
+
fieldWithNoPath: 'Test Error data 2',
|
|
535
|
+
fieldWithNoString: 16,
|
|
536
|
+
nestedObject: {
|
|
537
|
+
fieldWithPath: 'Test Error occurred at C:\\some\\file\\path4\\project.build.appxrecipe',
|
|
538
|
+
fieldWithNoPath: 'Test Error data 3',
|
|
539
|
+
fieldWithNoString: 17, // expectation: no changes to this value.
|
|
540
|
+
},
|
|
541
|
+
},
|
|
542
|
+
});
|
|
543
|
+
const expectedError = new errorUtils.CodedError('MSBuildError', // type
|
|
544
|
+
'test error', // message
|
|
545
|
+
{
|
|
546
|
+
fieldWithPath: 'Test Error occurred at [path]',
|
|
547
|
+
fieldWithNoPath: 'Test Error data',
|
|
548
|
+
fieldWithNoString: 14,
|
|
549
|
+
arrayField: [
|
|
550
|
+
'No path',
|
|
551
|
+
15,
|
|
552
|
+
'Clean this path: [path]',
|
|
553
|
+
['No path', 150, 'Also clean this: [path]'],
|
|
554
|
+
],
|
|
555
|
+
someObject: {
|
|
556
|
+
fieldWithPath: 'Test Error occurred at [path]',
|
|
557
|
+
fieldWithNoPath: 'Test Error data 2',
|
|
558
|
+
fieldWithNoString: 16,
|
|
559
|
+
nestedObject: {
|
|
560
|
+
fieldWithPath: 'Test Error occurred at [path]',
|
|
561
|
+
fieldWithNoPath: 'Test Error data 3',
|
|
562
|
+
fieldWithNoString: 17,
|
|
563
|
+
},
|
|
564
|
+
},
|
|
565
|
+
});
|
|
566
|
+
const caughtErrors = [];
|
|
567
|
+
TelemetryTest.addTelemetryInitializer(verifyTestCommandTelemetryProcessor(caughtErrors, expectedError.type, expectedError));
|
|
568
|
+
await runTestCommandE2E(() => testCommandBody(codedErrorInfo));
|
|
569
|
+
TelemetryTest.endTest(() => {
|
|
570
|
+
// Check if any errors were thrown
|
|
571
|
+
expect(caughtErrors).toHaveLength(0);
|
|
572
|
+
});
|
|
573
|
+
});
|
|
574
|
+
//# sourceMappingURL=telemetry.test.js.map
|