@react-native-windows/telemetry 0.67.1 → 0.68.0
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/index.d.ts +5 -2
- package/lib-commonjs/index.js +14 -6
- package/lib-commonjs/index.js.map +1 -1
- package/lib-commonjs/telemetry.d.ts +75 -20
- package/lib-commonjs/telemetry.js +284 -168
- package/lib-commonjs/telemetry.js.map +1 -1
- package/lib-commonjs/test/{sanitize.test.d.ts → basePropUtils.test.d.ts} +0 -0
- package/lib-commonjs/test/basePropUtils.test.js +116 -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 +159 -0
- package/lib-commonjs/test/errorUtils.test.js.map +1 -0
- package/lib-commonjs/test/projectUtils.test.d.ts +7 -0
- package/lib-commonjs/test/projectUtils.test.js +84 -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 +94 -0
- package/lib-commonjs/test/sanitizeUtils.test.js.map +1 -0
- package/lib-commonjs/test/telemetry.test.d.ts +26 -0
- package/lib-commonjs/test/telemetry.test.js +469 -0
- package/lib-commonjs/test/telemetry.test.js.map +1 -0
- package/lib-commonjs/test/versionUtils.test.d.ts +7 -0
- package/lib-commonjs/test/versionUtils.test.js +111 -0
- package/lib-commonjs/test/versionUtils.test.js.map +1 -0
- package/lib-commonjs/utils/basePropUtils.d.ts +66 -0
- package/lib-commonjs/utils/basePropUtils.js +131 -0
- package/lib-commonjs/utils/basePropUtils.js.map +1 -0
- package/lib-commonjs/{CodedError.d.ts → utils/errorUtils.d.ts} +27 -8
- package/lib-commonjs/utils/errorUtils.js +164 -0
- package/lib-commonjs/utils/errorUtils.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 +82 -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 +20 -9
- package/CHANGELOG.json +0 -618
- package/CHANGELOG.md +0 -260
- package/lib-commonjs/CodedError.js +0 -77
- package/lib-commonjs/CodedError.js.map +0 -1
- package/lib-commonjs/test/sanitize.test.js +0 -259
- package/lib-commonjs/test/sanitize.test.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"telemetry.js","sourceRoot":"","sources":["../src/telemetry.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,gDAAwB;AACxB,mCAAmC;AACnC,iEAAmD;AACnD,iDAAuC;AACvC,6CAAwC;AAExC,MAAa,SAAS;IAGpB,MAAM,CAAC,OAAO;QACZ,IAAI,SAAS,CAAC,MAAM,EAAE;YACpB,SAAS,CAAC,MAAM,CAAC,MAAM,CAAC,kBAAkB,GAAG,IAAI,CAAC;SACnD;QACD,SAAS,CAAC,aAAa,GAAG,IAAI,CAAC;IACjC,CAAC;IAED,MAAM,CAAC,KAAK,CAAC,gBAA0B;QACrC,IAAI,SAAS,CAAC,IAAI,EAAE,EAAE;YACpB,IAAI,CAAC,OAAO,EAAE,CAAC;YACf,OAAO;SACR;QACD,IAAI,SAAS,CAAC,MAAM,EAAE;YACpB,OAAO;SACR;QACD,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,YAAY,EAAE;YAC7B,WAAW,CAAC,aAAa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ACV,KAAK,CAAC,MAAM,CAAC,CAAC;IACjB,MAAM,IAAI,GAAG,GAAG,CAAC,GAAG,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IACjC,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,oBAAoB,CAAC,CAAC;IAChD,IAAI,MAAM,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE;QAC/B,OAAO,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;KAC1B;IACD,OAAO,CAAC,CAAC,CAAC;AACZ,CAAC;AAVD,4CAUC","sourcesContent":["/**\n * Copyright (c) Microsoft Corporation.\n * Licensed under the MIT License.\n * @format\n */\n\nimport path from 'path';\nimport {randomBytes} from 'crypto';\nimport * as appInsights from 'applicationinsights';\nimport {execSync} from 'child_process';\nimport {CodedError} from './CodedError';\n\nexport class Telemetry {\n static client?: appInsights.TelemetryClient | undefined = undefined;\n\n static disable() {\n if (Telemetry.client) {\n Telemetry.client.config.disableAppInsights = true;\n }\n Telemetry.shouldDisable = true;\n }\n\n static setup(preserveMessages?: boolean) {\n if (Telemetry.isCI()) {\n this.disable();\n return;\n }\n if (Telemetry.client) {\n return;\n }\n if (!process.env.RNW_CLI_TEST) {\n appInsights.Configuration.setInternalLogging(false, false);\n }\n appInsights.setup('795006ca-cf54-40ee-8bc6-03deb91401c3');\n Telemetry.client = appInsights.defaultClient;\n\n if (Telemetry.shouldDisable) {\n Telemetry.disable();\n }\n Telemetry.preserveMessages = preserveMessages ? true : false;\n\n if (process.env.RNW_CLI_TEST) {\n Telemetry.client.commonProperties.isTest = process.env.RNW_CLI_TEST;\n }\n if (!Telemetry.client.commonProperties.sessionId) {\n Telemetry.client.commonProperties.sessionId = randomBytes(16).toString(\n 'hex',\n );\n Telemetry.client.addTelemetryProcessor(sanitizeEnvelope);\n }\n }\n\n static isCI(): boolean {\n return (\n process.env.AGENT_NAME !== undefined || // Azure DevOps\n process.env.CIRCLECI === 'true' || // CircleCI\n process.env.TRAVIS === 'true' || // Travis\n process.env.CI === 'true' // other CIs\n );\n }\n\n static trackException(e: Error, properties?: Record<string, any>) {\n const props: Record<string, any> = {};\n if (e instanceof CodedError) {\n Object.assign(props, (e as CodedError).data);\n }\n\n const syscallExceptionFieldsToCopy = ['errno', 'syscall', 'code'];\n for (const f of syscallExceptionFieldsToCopy) {\n if ((e as any)[f]) {\n props[f] = [f];\n }\n }\n Object.assign(props, props, properties);\n Telemetry.client?.trackException({\n exception: e,\n properties: props,\n });\n }\n\n static shouldDisable: boolean = false;\n static preserveMessages: boolean = false;\n}\n\nfunction getAnonymizedPath(filepath: string): string {\n const projectRoot = process.cwd().toLowerCase();\n filepath = filepath.replace(/\\//g, '\\\\');\n const knownPathsVars = ['AppData', 'LocalAppData', 'UserProfile'];\n if (filepath.toLowerCase().startsWith(projectRoot)) {\n const ext = path.extname(filepath);\n const rest = filepath.slice(projectRoot.length);\n const nodeModules = '\\\\node_modules\\\\';\n // this is in the project dir but not under node_modules\n if (rest.toLowerCase().startsWith('\\\\windows\\\\')) {\n return `[windows]\\\\???${ext}(${filepath.length})`;\n } else if (rest.toLowerCase().startsWith(nodeModules)) {\n return 'node_modules' + rest.slice(nodeModules.length - 1);\n } else {\n return `[project_dir]\\\\???${ext}(${filepath.length})`;\n }\n } else {\n for (const knownPath of knownPathsVars) {\n if (\n process.env[knownPath] &&\n filepath.toLowerCase().startsWith(process.env[knownPath]!.toLowerCase())\n ) {\n return `[${knownPath}]\\\\???(${filepath.length})`;\n }\n }\n }\n return '[path]';\n}\n/**\n * Sanitize any paths that appear between quotes (''), brackets ([]), or double quotes (\"\").\n * @param msg the string to sanitize\n */\nexport function sanitizeMessage(msg: string): string {\n const cpuThreadId = /^\\d+(:\\d+)?>/g;\n msg = msg.replace(cpuThreadId, '');\n const parts = msg.split(/['[\\]\"]/g);\n const clean = [];\n const pathRegEx = /([A-Za-z]:|\\\\)[\\\\/]([^<>:;,?\"*\\t\\r\\n|/\\\\]+[\\\\/])+([^<>:;,?\"*\\t\\r\\n|]+\\/?)/gi;\n for (const part of parts) {\n if (pathRegEx.test(part)) {\n pathRegEx.lastIndex = -1;\n let matches: RegExpExecArray | null;\n let noPath = '';\n let last = 0;\n while ((matches = pathRegEx.exec(part))) {\n noPath +=\n part.substr(last, matches!.index - last) +\n getAnonymizedPath(matches[0]);\n last = matches!.index + matches![0].length;\n }\n clean.push(noPath);\n } else if (part !== '') {\n clean.push(part);\n }\n }\n return clean.join(' ').trim();\n}\n\nexport function sanitizeFrame(frame: any): void {\n const parens = frame.method.indexOf('(');\n if (parens !== -1) {\n // case 1: method === 'methodName (rootOfThePath'\n frame.method = frame.method.substr(0, parens).trim();\n } else {\n // case 2: method === <no_method> or something without '(', fileName is full path\n }\n // preserve only the last_directory/filename\n frame.fileName = path.join(\n path.basename(path.dirname(frame.fileName)),\n path.basename(frame.fileName),\n );\n frame.assembly = '';\n}\n\nexport function tryGetErrorCode(msg: string): string | undefined {\n const errorRegEx = /error (\\w+\\d+):/gi;\n const m = errorRegEx.exec(msg);\n return m ? m[1] : undefined;\n}\n\n/**\n * Remove PII from exceptions' stack traces and messages\n * @param envelope the telemetry envelope. Provided by AppInsights.\n */\nexport function sanitizeEnvelope(envelope: any /*context: any*/): boolean {\n if (envelope.data.baseType === 'ExceptionData') {\n const data = envelope.data.baseData;\n for (const exception of data.exceptions || []) {\n for (const frame of exception.parsedStack) {\n sanitizeFrame(frame);\n }\n const errorCode = tryGetErrorCode(exception.message);\n data.properties.errorCode = errorCode;\n // CodedError has non-PII information in its 'type' member, plus optionally some more info in its 'data'.\n // The message may contain PII information. This can be sanitized, but for now delete it.\n // Note that the type of data.exceptions[0] is always going to be ExceptionDetails. It is not the original thrown exception.\n // https://github.com/microsoft/ApplicationInsights-node.js/issues/707\n if (Telemetry.preserveMessages) {\n exception.message = sanitizeMessage(exception.message);\n } else {\n delete exception.message;\n }\n }\n }\n delete envelope.tags['ai.cloud.roleInstance'];\n return true;\n}\n\nexport function isMSFTInternal(): boolean {\n return (\n process.env.UserDNSDomain !== undefined &&\n process.env.UserDNSDomain.toLowerCase().endsWith('.microsoft.com')\n );\n}\n\nexport function getDiskFreeSpace(drivePath: string | null): number {\n const out = execSync(`dir /-C ${drivePath}`)\n .toString()\n .split('\\r\\n');\n const line = out[out.length - 2];\n const result = line.match(/(\\d+) [^\\d]+(\\d+) /);\n if (result && result.length > 2) {\n return Number(result[2]);\n }\n return -1;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"telemetry.js","sourceRoot":"","sources":["../src/telemetry.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;;;;;;;;;;;;;;;;;;;;AAEH,iEAAmD;AAEnD,qEAAuD;AACvD,mEAAqD;AACrD,+DAAiD;AA2BjD,sCAAsC;AACtC,MAAM,cAAc,GAAG,sCAAsC,CAAC;AAE9D,4DAA4D;AAC5D,MAAM,kBAAkB,GAAG,qBAAqB,CAAC;AAEjD,wGAAwG;AACxG,MAAM,kBAAkB,GAAG,qBAAqB,CAAC;AAEpC,QAAA,gBAAgB,GAAG,gBAAgB,CAAC;AACpC,QAAA,mBAAmB,GAAG,mBAAmB,CAAC;AAEvD,2CAA2C;AAC9B,QAAA,iBAAiB,GAAa;IACzC,wBAAgB;IAChB,2BAAmB;CACpB,CAAC;AAEF,4EAA4E;AAC5E,uDAAuD;AAC1C,QAAA,kBAAkB,GAAa;IAC1C,6BAA6B;IAC7B,2BAA2B;IAC3B,iCAAiC;IACjC,OAAO;IACP,cAAc;IACd,sBAAsB;IACtB,2BAA2B;CAC5B,CAAC;AAEF,4EAA4E;AAC/D,QAAA,oBAAoB,GAAa;IAC5C,mBAAmB;IACnB,4BAA4B;IAC5B,iBAAiB;CAClB,CAAC;AAEF;;GAEG;AACH,MAAa,SAAS;IAeV,MAAM,CAAC,qBAAqB;;QACpC,yEAAyE;QACzE,OAAO,MAAA,OAAO,CAAC,GAAG,CAAC,kBAAkB,CAAC,mCAAI,cAAc,CAAC;IAC3D,CAAC;IAES,MAAM,CA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;QAClE,KAAK,MAAM,CAAC,IAAI,4BAA4B,EAAE;YAC5C,IAAK,KAAa,CAAC,CAAC,CAAC,EAAE;gBACrB,KAAK,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,GAAI,KAAa,CAAC,CAAC,CAAC,CAAC;aAC9C;SACF;QAED,6BAA6B;QAC7B,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,UAAU,CAAC,CAAC;QACjC,KAAK,CAAC,OAAO,GAAG,SAAS,CAAC,WAAW,CAAC;QACtC,KAAK,CAAC,QAAQ,GAAG,SAAS,CAAC,YAAY,CAAC;QAExC,aAAa;QACb,SAAS,CAAC,MAAO,CAAC,cAAc,CAAC;YAC/B,SAAS,EAAE,KAAK;YAChB,UAAU,EAAE,KAAK;SAClB,CAAC,CAAC;QACH,SAAS,CAAC,MAAO,CAAC,KAAK,EAAE,CAAC;IAC5B,CAAC;;AA3XH,8BA4XC;AA3XkB,gBAAM,GAAiC,SAAS,CAAC;AACjD,iBAAO,GAAqB;IAC3C,WAAW,EAAE,SAAS,CAAC,qBAAqB,EAAE;IAC9C,qBAAqB,EAAE,KAAK;IAC5B,0BAA0B,EAAE,IAAI;CACjC,CAAC;AAEe,gBAAM,GAAY,aAAa,CAAC,SAAS,EAAE,CAAC;AAC5C,qBAAW,GAAgB,EAAE,CAAC;AAC9B,sBAAY,GAA2B,EAAE,CAAC;AAC1C,qBAAW,GAEa,SAAS,CAAC","sourcesContent":["/**\n * Copyright (c) Microsoft Corporation.\n * Licensed under the MIT License.\n * @format\n */\n\nimport * as appInsights from 'applicationinsights';\n\nimport * as basePropUtils from './utils/basePropUtils';\nimport * as versionUtils from './utils/versionUtils';\nimport * as errorUtils from './utils/errorUtils';\nimport * as projectUtils from './utils/projectUtils';\n\nexport interface TelemetryOptions {\n setupString: string;\n preserveErrorMessages: boolean;\n populateNpmPackageVersions: boolean;\n}\n\nexport interface CommandStartInfo {\n commandName: string;\n args: Record<string, any>;\n options: Record<string, any>;\n defaultOptions: Record<string, any>;\n}\n\nexport interface CommandEndInfo {\n resultCode: errorUtils.CodedErrorType;\n}\n\ninterface CommandInfo {\n startTime?: number;\n endTime?: number;\n startInfo?: CommandStartInfo;\n endInfo?: CommandEndInfo;\n}\n\n// This is our key with the AI backend\nconst RNWSetupString = '795006ca-cf54-40ee-8bc6-03deb91401c3';\n\n// Environment variable to override the default setup string\nconst ENV_SETUP_OVERRIDE = 'RNW_TELEMETRY_SETUP';\n\n// Environment variable to override the http proxy (such as http://localhost:8888 for Fiddler debugging)\nconst ENV_PROXY_OVERRIDE = 'RNW_TELEMETRY_PROXY';\n\nexport const CommandEventName = 'RNWCLI.Command';\nexport const CodedErrorEventName = 'RNWCLI.CodedError';\n\n// These are the event names we're tracking\nexport const EventNamesWeTrack: string[] = [\n CommandEventName,\n CodedErrorEventName,\n];\n\n// These are NPM packages we care about, in terms of capturing versions used\n// and getting more details about when reporting errors\nexport const NpmPackagesWeTrack: string[] = [\n '@react-native-community/cli',\n '@react-native-windows/cli',\n '@react-native-windows/telemetry',\n 'react',\n 'react-native',\n 'react-native-windows',\n 'react-native-windows-init',\n];\n\n// These are NPM packages we care about, in terms of capturing versions used\nexport const NuGetPackagesWeTrack: string[] = [\n 'Microsoft.UI.Xaml',\n 'Microsoft.Windows.CppWinRT',\n 'Microsoft.WinUI',\n];\n\n/**\n * The Telemetry class is responsible for reporting telemetry for RNW CLI.\n */\nexport class Telemetry {\n protected static client?: appInsights.TelemetryClient = undefined;\n protected static options: TelemetryOptions = {\n setupString: Telemetry.getDefaultSetupString(), // We default to our AI key, but callers can easily override it in setup\n preserveErrorMessages: false,\n populateNpmPackageVersions: true,\n };\n\n protected static isTest: boolean = basePropUtils.isCliTest();\n protected static commandInfo: CommandInfo = {};\n protected static versionsProp: Record<string, string> = {};\n protected static projectProp?:\n | projectUtils.AppProjectInfo\n | projectUtils.DependencyProjectInfo = undefined;\n\n protected static getDefaultSetupString(): string {\n // Enable overriding the default setup string via an environment variable\n return process.env[ENV_SETUP_OVERRIDE] ?? RNWSetupString;\n }\n\n protected static reset(): void {\n // Reset client\n if (Telemetry.client) {\n Telemetry.client.flush();\n Telemetry.client = undefined;\n }\n\n // Reset local members\n Telemetry.options = {\n setupString: Telemetry.getDefaultSetupString(),\n preserveErrorMessages: false,\n populateNpmPackageVersions: true,\n };\n Telemetry.commandInfo = {};\n Telemetry.versionsProp = {};\n Telemetry.projectProp = undefined;\n }\n\n static isEnabled(): boolean {\n return Telemetry.client !== undefined;\n }\n\n static getSessionId(): string {\n return basePropUtils.getSessionId();\n }\n\n /** Sets up the Telemetry static to be used elsewhere. */\n static async setup(options?: Partial<TelemetryOptions>) {\n if (Telemetry.client) {\n // Bail since we've already setup\n return;\n }\n\n // Bail if we're in CI and not capturing CI\n if (!this.isTest && basePropUtils.isCI() && !basePropUtils.captureCI()) {\n return;\n }\n\n // Save off options for later\n Object.assign(Telemetry.options, options);\n\n Telemetry.setupClient();\n\n await Telemetry.setupBaseProperties();\n\n Telemetry.setupTelemetryProcessors();\n }\n\n /** Sets up Telemetry.client. */\n private static setupClient() {\n appInsights.Configuration.setInternalLogging(\n Telemetry.isTest,\n Telemetry.isTest,\n );\n\n Telemetry.client = new appInsights.TelemetryClient(\n Telemetry.options.setupString,\n );\n\n // Allow overriding the proxy server via an environment variable\n const proxyServer = process.env[ENV_PROXY_OVERRIDE];\n if (proxyServer) {\n Telemetry.client.config.proxyHttpUrl = proxyServer;\n Telemetry.client.config.proxyHttpsUrl = proxyServer;\n }\n\n Telemetry.client.config.disableAppInsights = Telemetry.isTest;\n Telemetry.client.channel.setUseDiskRetryCaching(!Telemetry.isTest);\n }\n\n /** Sets up any base properties that all telemetry events require. */\n private static async setupBaseProperties() {\n Telemetry.client!.commonProperties.deviceId =\n await basePropUtils.deviceId();\n Telemetry.client!.commonProperties.deviceLocale =\n await basePropUtils.deviceLocale();\n Telemetry.client!.commonProperties.deviceNumCPUs = basePropUtils\n .deviceNumCPUs()\n .toString();\n Telemetry.client!.commonProperties.deviceTotalMemory = basePropUtils\n .deviceTotalMemory()\n .toString();\n Telemetry.client!.commonProperties.deviceDiskFreeSpace = basePropUtils\n .deviceDiskFreeSpace()\n .toString();\n Telemetry.client!.commonProperties.ciCaptured = basePropUtils\n .captureCI()\n .toString();\n Telemetry.client!.commonProperties.ciType = basePropUtils.ciType();\n Telemetry.client!.commonProperties.isMsftInternal = basePropUtils\n .isMsftInternal()\n .toString();\n\n Telemetry.client!.config.samplingPercentage = basePropUtils.sampleRate();\n\n if (Telemetry.isTest) {\n Telemetry.client!.commonProperties.isTest = true.toString();\n }\n\n Telemetry.client!.commonProperties.sessionId = Telemetry.getSessionId();\n\n await Telemetry.populateToolsVersions();\n if (Telemetry.options.populateNpmPackageVersions) {\n await Telemetry.populateNpmPackageVersions();\n }\n }\n\n /** Sets up any telemetry processors. */\n private static setupTelemetryProcessors() {\n Telemetry.client!.addTelemetryProcessor(Telemetry.basicTelemetryProcessor);\n Telemetry.client!.addTelemetryProcessor(Telemetry.errorTelemetryProcessor);\n }\n\n /**\n * Performs the processing necessary (mostly PII sanitization) for all events.\n * @param envelope The ApplicationInsights event envelope.\n * @param _contextObjects An optional context object.\n * @returns Whether to kee\n */\n private static basicTelemetryProcessor(\n envelope: appInsights.Contracts.EnvelopeTelemetry,\n _contextObjects?: {\n [name: string]: any;\n },\n ): boolean {\n delete envelope.tags['ai.cloud.roleInstance'];\n\n // Filter out \"legacy\" events from older stable branches\n const properties = envelope.data.baseData?.properties;\n if (\n properties?.eventName &&\n EventNamesWeTrack.includes(properties.eventName)\n ) {\n return true;\n }\n\n return false;\n }\n\n /**\n * Performs the processing necessary (mostly PII sanitization) for error events.\n * @param envelope\n * @param _contextObjects\n * @returns\n */\n private static errorTelemetryProcessor(\n envelope: appInsights.Contracts.EnvelopeTelemetry,\n _contextObjects?: {\n [name: string]: any;\n },\n ): boolean {\n if (envelope.data.baseType === 'ExceptionData') {\n const data = envelope.data.baseData;\n if (data?.exceptions) {\n for (const exception of data.exceptions) {\n for (const frame of exception.parsedStack) {\n errorUtils.sanitizeErrorStackFrame(frame);\n }\n // CodedError has non-PII information in its 'type' member, plus optionally some more info in its 'data'.\n // The message may contain PII information. This can be sanitized, but for now delete it.\n // Note that the type of data.exceptions[0] is always going to be ExceptionDetails. It is not the original thrown exception.\n // https://github.com/microsoft/ApplicationInsights-node.js/issues/707\n if (Telemetry.options.preserveErrorMessages) {\n exception.message = errorUtils.sanitizeErrorMessage(\n exception.message,\n );\n } else {\n delete exception.message;\n }\n }\n }\n }\n return true;\n }\n\n /** Tries to update the version of the named package/tool by calling getValue(). */\n static async tryUpdateVersionsProp(\n name: string,\n getValue: () => Promise<string | null>,\n forceRefresh?: boolean,\n ): Promise<boolean> {\n if (!Telemetry.client) {\n return true;\n }\n\n if (forceRefresh === true || !Telemetry.versionsProp[name]) {\n const value = await getValue();\n if (value) {\n Telemetry.versionsProp[name] = value;\n return true;\n }\n }\n return false;\n }\n\n /** Populates the versions property of tools we care to track. */\n static async populateToolsVersions(refresh?: boolean) {\n await Telemetry.tryUpdateVersionsProp(\n 'node',\n versionUtils.getNodeVersion,\n refresh,\n );\n await Telemetry.tryUpdateVersionsProp(\n 'npm',\n versionUtils.getNpmVersion,\n refresh,\n );\n await Telemetry.tryUpdateVersionsProp(\n 'yarn',\n versionUtils.getYarnVersion,\n refresh,\n );\n await Telemetry.tryUpdateVersionsProp(\n 'VisualStudio',\n versionUtils.getVisualStudioVersion,\n refresh,\n );\n }\n\n /** Populates the versions property of npm packages we care to track. */\n static async populateNpmPackageVersions(refresh?: boolean) {\n for (const npmPackage of NpmPackagesWeTrack) {\n await Telemetry.tryUpdateVersionsProp(\n npmPackage,\n async () => await versionUtils.getVersionOfNpmPackage(npmPackage),\n refresh,\n );\n }\n }\n\n /** Populates the versions property of nuget packages we care to track. */\n static async populateNuGetPackageVersions(\n projectFile: string,\n refresh?: boolean,\n ) {\n const nugetVersions = await versionUtils.getVersionsOfNuGetPackages(\n projectFile,\n NuGetPackagesWeTrack,\n );\n\n for (const nugetPackage of NuGetPackagesWeTrack) {\n await Telemetry.tryUpdateVersionsProp(\n nugetPackage,\n async () => nugetVersions[nugetPackage],\n refresh,\n );\n }\n }\n\n static setProjectInfo(\n info: projectUtils.AppProjectInfo | projectUtils.DependencyProjectInfo,\n ) {\n if (!Telemetry.client) {\n return;\n }\n\n Telemetry.projectProp = info;\n }\n\n static startCommand(info: CommandStartInfo) {\n if (!Telemetry.client) {\n return;\n }\n\n if (Telemetry.commandInfo.startInfo) {\n return;\n }\n\n Telemetry.commandInfo.startTime = Date.now();\n Telemetry.commandInfo.startInfo = info;\n\n // Set common command props\n Telemetry.client!.commonProperties.commandName = info.commandName;\n }\n\n static endCommand(info: CommandEndInfo, extraProps?: Record<string, any>) {\n if (!Telemetry.client) {\n return;\n }\n\n if (!Telemetry.commandInfo.startInfo) {\n return;\n }\n\n Telemetry.commandInfo.endTime = Date.now();\n Telemetry.commandInfo.endInfo = info;\n\n Telemetry.trackCommandEvent(extraProps);\n }\n\n private static trackCommandEvent(extraProps?: Record<string, any>) {\n const props: Record<string, any> = {\n eventName: CommandEventName,\n };\n\n // Set command props\n props.command = {\n options: Telemetry.commandInfo.startInfo?.options,\n defaultOptions: Telemetry.commandInfo.startInfo?.defaultOptions,\n args: Telemetry.commandInfo.startInfo?.args,\n durationInSecs:\n (Telemetry.commandInfo.endTime! - Telemetry.commandInfo.startTime!) /\n 1000,\n resultCode: Telemetry.commandInfo.endInfo?.resultCode,\n };\n\n // Set remaining common props\n Object.assign(props, extraProps);\n props.project = Telemetry.projectProp;\n props.versions = Telemetry.versionsProp;\n\n // Fire event\n Telemetry.client!.trackEvent({name: props.eventName, properties: props});\n Telemetry.client!.flush();\n }\n\n static trackException(error: Error, extraProps?: Record<string, any>) {\n if (!Telemetry.client) {\n return;\n }\n\n const props: Record<string, any> = {\n eventName: CodedErrorEventName,\n };\n\n // Save off CodedError info\n const codedError =\n error instanceof errorUtils.CodedError\n ? (error as errorUtils.CodedError)\n : null;\n props.codedError = {\n type: codedError?.type ?? 'Unknown',\n rawErrorCode: errorUtils.tryGetErrorCode(error.message) ?? '',\n data: codedError?.data ?? {},\n };\n\n if (codedError?.data) {\n Object.assign(props.codedError.data, codedError.data);\n }\n\n // Copy miscellaneous system error fields into the codedError.data object\n const syscallExceptionFieldsToCopy = ['errno', 'syscall', 'code'];\n for (const f of syscallExceptionFieldsToCopy) {\n if ((error as any)[f]) {\n props.codedError.data[f] = (error as any)[f];\n }\n }\n\n // Set remaining common props\n Object.assign(props, extraProps);\n props.project = Telemetry.projectProp;\n props.versions = Telemetry.versionsProp;\n\n // Fire event\n Telemetry.client!.trackException({\n exception: error,\n properties: props,\n });\n Telemetry.client!.flush();\n }\n}\n"]}
|
|
File without changes
|
|
@@ -0,0 +1,116 @@
|
|
|
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
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
11
|
+
}) : (function(o, m, k, k2) {
|
|
12
|
+
if (k2 === undefined) k2 = k;
|
|
13
|
+
o[k2] = m[k];
|
|
14
|
+
}));
|
|
15
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
16
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
17
|
+
}) : function(o, v) {
|
|
18
|
+
o["default"] = v;
|
|
19
|
+
});
|
|
20
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
21
|
+
if (mod && mod.__esModule) return mod;
|
|
22
|
+
var result = {};
|
|
23
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
24
|
+
__setModuleDefault(result, mod);
|
|
25
|
+
return result;
|
|
26
|
+
};
|
|
27
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
28
|
+
const basePropUtils = __importStar(require("../utils/basePropUtils"));
|
|
29
|
+
test('deviceId() is valid', async () => {
|
|
30
|
+
const value = await basePropUtils.deviceId();
|
|
31
|
+
expect(value).toBeDefined();
|
|
32
|
+
expect(value).not.toBe('');
|
|
33
|
+
expect(value).not.toBeNull();
|
|
34
|
+
});
|
|
35
|
+
test('deviceId() does not change', async () => {
|
|
36
|
+
expect(await basePropUtils.deviceId()).toBe(await basePropUtils.deviceId());
|
|
37
|
+
});
|
|
38
|
+
test('deviceLocale() is valid', async () => {
|
|
39
|
+
const value = await basePropUtils.deviceLocale();
|
|
40
|
+
expect(value).toBeDefined();
|
|
41
|
+
expect(value).not.toBe('');
|
|
42
|
+
expect(value).not.toBeNull();
|
|
43
|
+
});
|
|
44
|
+
test('deviceLocale() does not change', async () => {
|
|
45
|
+
expect(await basePropUtils.deviceLocale()).toBe(await basePropUtils.deviceLocale());
|
|
46
|
+
});
|
|
47
|
+
test('deviceNumCPUs() is valid', () => {
|
|
48
|
+
const value = basePropUtils.deviceNumCPUs();
|
|
49
|
+
expect(value).toBeGreaterThan(0);
|
|
50
|
+
});
|
|
51
|
+
test('deviceTotalMemory() is valid', () => {
|
|
52
|
+
const value = basePropUtils.deviceTotalMemory();
|
|
53
|
+
expect(value).toBeGreaterThan(0);
|
|
54
|
+
});
|
|
55
|
+
test('deviceDiskFreeSpace() is valid', () => {
|
|
56
|
+
const value = basePropUtils.deviceDiskFreeSpace();
|
|
57
|
+
expect(value).toBeGreaterThanOrEqual(0);
|
|
58
|
+
});
|
|
59
|
+
test('sampleRate() is within valid range', () => {
|
|
60
|
+
const value = basePropUtils.sampleRate();
|
|
61
|
+
expect(value).toBeGreaterThanOrEqual(0);
|
|
62
|
+
expect(value).toBeLessThanOrEqual(100);
|
|
63
|
+
});
|
|
64
|
+
test('ciType() is valid', () => {
|
|
65
|
+
const value = basePropUtils.ciType();
|
|
66
|
+
expect(value).toBeDefined();
|
|
67
|
+
expect(value).not.toBe('');
|
|
68
|
+
expect(value).not.toBeNull();
|
|
69
|
+
});
|
|
70
|
+
test('ciType() is None when not in CI', () => {
|
|
71
|
+
if (basePropUtils.isCI()) {
|
|
72
|
+
expect(basePropUtils.ciType()).not.toBe('None');
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
expect(basePropUtils.ciType()).toBe('None');
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
test('isMsftInternal() is false with no domain', () => {
|
|
79
|
+
delete process.env.UserDNSDomain;
|
|
80
|
+
expect(basePropUtils.isMsftInternal()).toBe(false);
|
|
81
|
+
});
|
|
82
|
+
test('isMsftInternal() is false with example.com domain', () => {
|
|
83
|
+
process.env.UserDNSDomain = 'example.com';
|
|
84
|
+
expect(basePropUtils.isMsftInternal()).toBe(false);
|
|
85
|
+
});
|
|
86
|
+
test('isMsftInternal() is true with Msft domain', () => {
|
|
87
|
+
process.env.UserDNSDomain = 'test.corp.microsoft.com';
|
|
88
|
+
expect(basePropUtils.isMsftInternal()).toBe(true);
|
|
89
|
+
});
|
|
90
|
+
test('isCliTest() is true if RNW_CLI_TEST env variable is set', () => {
|
|
91
|
+
process.env.RNW_CLI_TEST = 'true';
|
|
92
|
+
expect(basePropUtils.isCliTest()).toBe(true);
|
|
93
|
+
});
|
|
94
|
+
test('isCliTest() is false if no RNW_CLI_TEST variable', () => {
|
|
95
|
+
delete process.env.RNW_CLI_TEST;
|
|
96
|
+
expect(basePropUtils.isCliTest()).toBe(false);
|
|
97
|
+
});
|
|
98
|
+
test('getSessionId() is valid', () => {
|
|
99
|
+
const value = basePropUtils.getSessionId();
|
|
100
|
+
expect(value).toBeDefined();
|
|
101
|
+
expect(value).not.toBe('');
|
|
102
|
+
expect(value).not.toBeNull();
|
|
103
|
+
expect(value).toHaveLength(32);
|
|
104
|
+
});
|
|
105
|
+
test('getSessionId() is a guid', () => {
|
|
106
|
+
const value = basePropUtils.getSessionId();
|
|
107
|
+
expect(value).toHaveLength(32);
|
|
108
|
+
const parseGuid = () => {
|
|
109
|
+
parseInt(value, 16);
|
|
110
|
+
};
|
|
111
|
+
expect(parseGuid).not.toThrow();
|
|
112
|
+
});
|
|
113
|
+
test('getSessionId() does not change', () => {
|
|
114
|
+
expect(basePropUtils.getSessionId()).toBe(basePropUtils.getSessionId());
|
|
115
|
+
});
|
|
116
|
+
//# sourceMappingURL=basePropUtils.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"basePropUtils.test.js","sourceRoot":"","sources":["../../src/test/basePropUtils.test.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;;;;;;;;;;;;;;;;;;AAEH,sEAAwD;AAExD,IAAI,CAAC,qBAAqB,EAAE,KAAK,IAAI,EAAE;IACrC,MAAM,KAAK,GAAG,MAAM,aAAa,CAAC,QAAQ,EAAE,CAAC;IAC7C,MAAM,CAAC,KAAK,CAAC,CAAC,WAAW,EAAE,CAAC;IAC5B,MAAM,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IAC3B,MAAM,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC;AAC/B,CAAC,CAAC,CAAC;AAEH,IAAI,CAAC,4BAA4B,EAAE,KAAK,IAAI,EAAE;IAC5C,MAAM,CAAC,MAAM,aAAa,CAAC,QAAQ,EAAE,CAAC,CAAC,IAAI,CAAC,MAAM,aAAa,CAAC,QAAQ,EAAE,CAAC,CAAC;AAC9E,CAAC,CAAC,CAAC;AAEH,IAAI,CAAC,yBAAyB,EAAE,KAAK,IAAI,EAAE;IACzC,MAAM,KAAK,GAAG,MAAM,aAAa,CAAC,YAAY,EAAE,CAAC;IACjD,MAAM,CAAC,KAAK,CAAC,CAAC,WAAW,EAAE,CAAC;IAC5B,MAAM,CAAC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C,CAAC,IAAI,CAAC,aAAa,CAAC,YAAY,EAAE,CAAC,CAAC;AAC1E,CAAC,CAAC,CAAC","sourcesContent":["/**\n * Copyright (c) Microsoft Corporation.\n * Licensed under the MIT License.\n *\n * @format\n */\n\nimport * as basePropUtils from '../utils/basePropUtils';\n\ntest('deviceId() is valid', async () => {\n const value = await basePropUtils.deviceId();\n expect(value).toBeDefined();\n expect(value).not.toBe('');\n expect(value).not.toBeNull();\n});\n\ntest('deviceId() does not change', async () => {\n expect(await basePropUtils.deviceId()).toBe(await basePropUtils.deviceId());\n});\n\ntest('deviceLocale() is valid', async () => {\n const value = await basePropUtils.deviceLocale();\n expect(value).toBeDefined();\n expect(value).not.toBe('');\n expect(value).not.toBeNull();\n});\n\ntest('deviceLocale() does not change', async () => {\n expect(await basePropUtils.deviceLocale()).toBe(\n await basePropUtils.deviceLocale(),\n );\n});\n\ntest('deviceNumCPUs() is valid', () => {\n const value = basePropUtils.deviceNumCPUs();\n expect(value).toBeGreaterThan(0);\n});\n\ntest('deviceTotalMemory() is valid', () => {\n const value = basePropUtils.deviceTotalMemory();\n expect(value).toBeGreaterThan(0);\n});\n\ntest('deviceDiskFreeSpace() is valid', () => {\n const value = basePropUtils.deviceDiskFreeSpace();\n expect(value).toBeGreaterThanOrEqual(0);\n});\n\ntest('sampleRate() is within valid range', () => {\n const value = basePropUtils.sampleRate();\n expect(value).toBeGreaterThanOrEqual(0);\n expect(value).toBeLessThanOrEqual(100);\n});\n\ntest('ciType() is valid', () => {\n const value = basePropUtils.ciType();\n expect(value).toBeDefined();\n expect(value).not.toBe('');\n expect(value).not.toBeNull();\n});\n\ntest('ciType() is None when not in CI', () => {\n if (basePropUtils.isCI()) {\n expect(basePropUtils.ciType()).not.toBe('None');\n } else {\n expect(basePropUtils.ciType()).toBe('None');\n }\n});\n\ntest('isMsftInternal() is false with no domain', () => {\n delete process.env.UserDNSDomain;\n expect(basePropUtils.isMsftInternal()).toBe(false);\n});\n\ntest('isMsftInternal() is false with example.com domain', () => {\n process.env.UserDNSDomain = 'example.com';\n expect(basePropUtils.isMsftInternal()).toBe(false);\n});\n\ntest('isMsftInternal() is true with Msft domain', () => {\n process.env.UserDNSDomain = 'test.corp.microsoft.com';\n expect(basePropUtils.isMsftInternal()).toBe(true);\n});\n\ntest('isCliTest() is true if RNW_CLI_TEST env variable is set', () => {\n process.env.RNW_CLI_TEST = 'true';\n expect(basePropUtils.isCliTest()).toBe(true);\n});\n\ntest('isCliTest() is false if no RNW_CLI_TEST variable', () => {\n delete process.env.RNW_CLI_TEST;\n expect(basePropUtils.isCliTest()).toBe(false);\n});\n\ntest('getSessionId() is valid', () => {\n const value = basePropUtils.getSessionId();\n expect(value).toBeDefined();\n expect(value).not.toBe('');\n expect(value).not.toBeNull();\n expect(value).toHaveLength(32);\n});\n\ntest('getSessionId() is a guid', () => {\n const value = basePropUtils.getSessionId();\n expect(value).toHaveLength(32);\n\n const parseGuid = () => {\n parseInt(value, 16);\n };\n\n expect(parseGuid).not.toThrow();\n});\n\ntest('getSessionId() does not change', () => {\n expect(basePropUtils.getSessionId()).toBe(basePropUtils.getSessionId());\n});\n"]}
|
|
@@ -0,0 +1,159 @@
|
|
|
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
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
11
|
+
}) : (function(o, m, k, k2) {
|
|
12
|
+
if (k2 === undefined) k2 = k;
|
|
13
|
+
o[k2] = m[k];
|
|
14
|
+
}));
|
|
15
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
16
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
17
|
+
}) : function(o, v) {
|
|
18
|
+
o["default"] = v;
|
|
19
|
+
});
|
|
20
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
21
|
+
if (mod && mod.__esModule) return mod;
|
|
22
|
+
var result = {};
|
|
23
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
24
|
+
__setModuleDefault(result, mod);
|
|
25
|
+
return result;
|
|
26
|
+
};
|
|
27
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
28
|
+
const errorUtils = __importStar(require("../utils/errorUtils"));
|
|
29
|
+
test('tryGetErrorCode() with valid error code', () => {
|
|
30
|
+
expect(errorUtils.tryGetErrorCode('foo bar error FOO2020: the thing')).toBe('FOO2020');
|
|
31
|
+
});
|
|
32
|
+
test('tryGetErrorCode() without valid error code', () => {
|
|
33
|
+
expect(errorUtils.tryGetErrorCode('foo bar the thing')).toBeUndefined();
|
|
34
|
+
});
|
|
35
|
+
test('tryGetErrorCode() with word error but no code', () => {
|
|
36
|
+
expect(errorUtils.tryGetErrorCode('test error')).toBeUndefined();
|
|
37
|
+
});
|
|
38
|
+
test('sanitizeErrorMessage() no-op on empty string', () => {
|
|
39
|
+
expect(errorUtils.sanitizeErrorMessage('')).toBe('');
|
|
40
|
+
});
|
|
41
|
+
test('sanitizeErrorMessage() no-op on test string', () => {
|
|
42
|
+
expect(errorUtils.sanitizeErrorMessage('some text')).toBe('some text');
|
|
43
|
+
});
|
|
44
|
+
test("sanitizeErrorMessage() 'project_dir'", () => {
|
|
45
|
+
expect(errorUtils.sanitizeErrorMessage(`this is the cwd: '${process.cwd()}'`)).toBe(`this is the cwd: [project_dir]`);
|
|
46
|
+
});
|
|
47
|
+
test("sanitizeErrorMessage() 'project_dir' uppercase", () => {
|
|
48
|
+
expect(errorUtils.sanitizeErrorMessage(`uppercase: '${process.cwd().toUpperCase()}'`)).toBe(`uppercase: [project_dir]`);
|
|
49
|
+
});
|
|
50
|
+
test("sanitizeErrorMessage() 'project_dir' lowercase", () => {
|
|
51
|
+
expect(errorUtils.sanitizeErrorMessage(`lowercase: '${process.cwd().toLowerCase()}'`)).toBe(`lowercase: [project_dir]`);
|
|
52
|
+
});
|
|
53
|
+
test("sanitizeErrorMessage() 'project_dir' and something else", () => {
|
|
54
|
+
expect(errorUtils.sanitizeErrorMessage(`this is the cwd: '${process.cwd()}' and something else`)).toBe(`this is the cwd: [project_dir] and something else`);
|
|
55
|
+
});
|
|
56
|
+
test('sanitizeErrorMessage() project_dir and something else', () => {
|
|
57
|
+
expect(errorUtils.sanitizeErrorMessage(`this is the cwd: ${process.cwd()} and something else`)).toBe(`this is the cwd: [project_dir]\\???(${' and something else'.length})`);
|
|
58
|
+
});
|
|
59
|
+
test("sanitizeErrorMessage() 'node_modules'", () => {
|
|
60
|
+
expect(errorUtils.sanitizeErrorMessage(`this is the cwd: '${process.cwd()}\\node_modules'`)).toBe(`this is the cwd: [project_dir]\\???(${'node_modules'.length})`);
|
|
61
|
+
});
|
|
62
|
+
test("sanitizeErrorMessage() 'node_modules\\foo'", () => {
|
|
63
|
+
expect(errorUtils.sanitizeErrorMessage(`this is the cwd: '${process.cwd()}\\node_modules\\foo'`)).toBe(`this is the cwd: [node_modules]\\???(${'foo'.length})`);
|
|
64
|
+
});
|
|
65
|
+
test("sanitizeErrorMessage() 'node_modules\\foo' uppercase", () => {
|
|
66
|
+
expect(errorUtils.sanitizeErrorMessage(`uppercase: '${process.cwd().toUpperCase()}\\NODE_MODULES\\foo'`)).toBe(`uppercase: [node_modules]\\???(${'foo'.length})`);
|
|
67
|
+
});
|
|
68
|
+
test("sanitizeErrorMessage() 'node_modules\\foo' lowercase", () => {
|
|
69
|
+
expect(errorUtils.sanitizeErrorMessage(`lowercase: '${process.cwd().toLowerCase()}\\NODE_MODULES\\foo'`)).toBe(`lowercase: [node_modules]\\???(${'foo'.length})`);
|
|
70
|
+
});
|
|
71
|
+
test("sanitizeErrorMessage() 'node_modules\\' and something else", () => {
|
|
72
|
+
expect(errorUtils.sanitizeErrorMessage(`trailing: '${process.cwd()}\\node_modules\\' and something else`)).toBe(`trailing: [node_modules]\\???(0) and something else`);
|
|
73
|
+
});
|
|
74
|
+
test('sanitizeErrorMessage() node_modules and something else that could be part of the path', () => {
|
|
75
|
+
expect(errorUtils.sanitizeErrorMessage(`this is the cwd: ${process.cwd()}\\node_modules and something else that could be part of the path`)).toBe(`this is the cwd: [project_dir]\\???(${'node_modules and something else that could be part of the path'.length})`);
|
|
76
|
+
});
|
|
77
|
+
test('sanitizeErrorMessage() \\node_modules\\ a file under nm', () => {
|
|
78
|
+
expect(errorUtils.sanitizeErrorMessage(`this is the cwd: ${process.cwd()}\\node_modules\\ a file under nm`)).toBe(`this is the cwd: [node_modules]\\???(${' a file under nm'.length})`);
|
|
79
|
+
});
|
|
80
|
+
test('sanitizeErrorMessage() other path', () => {
|
|
81
|
+
expect(errorUtils.sanitizeErrorMessage(`this is another path: A:\\foo\\bar\\baz`)).toBe(`this is another path: [path]`);
|
|
82
|
+
});
|
|
83
|
+
test("sanitizeErrorMessage() 'other path'", () => {
|
|
84
|
+
expect(errorUtils.sanitizeErrorMessage(`this is another path: 'A:\\foo\\bar\\baz'`)).toBe(`this is another path: [path]`);
|
|
85
|
+
});
|
|
86
|
+
test('sanitizeErrorMessage() tracked packages in the npx cache', () => {
|
|
87
|
+
expect(errorUtils.sanitizeErrorMessage(`Cannot find module 'react-native/package.json'
|
|
88
|
+
Require stack:
|
|
89
|
+
- ${process.env.AppData}\\npm-cache\\_npx\\1384\\node_modules\\react-native-windows-init\\lib-commonjs\\Cli.js
|
|
90
|
+
- ${process.env.AppData}\\npm-cache\\_npx\\1384\\node_modules\\react-native-windows-init\\bin.js`)).toBe(`Cannot find module react-native/package.json
|
|
91
|
+
Require stack:
|
|
92
|
+
- [node_modules]\\react-native-windows-init\\lib-commonjs\\Cli.js
|
|
93
|
+
- [node_modules]\\react-native-windows-init\\bin.js`);
|
|
94
|
+
});
|
|
95
|
+
test('sanitizeErrorMessage() forward slashes', () => {
|
|
96
|
+
expect(errorUtils.sanitizeErrorMessage(`EPERM: operation not permitted, scandir ${process.env.UserProfile.replace(/\\/g, '/')}/source/repos/rn2/wintest/windows/packages/boost.1.76.0.0/lib/native/include`)).toBe(`EPERM: operation not permitted, scandir [UserProfile]\\???(${'/source/repos/rn2/wintest/windows/packages/boost.1.76.0.0/lib/native/include'
|
|
97
|
+
.length})`);
|
|
98
|
+
});
|
|
99
|
+
test('sanitizeErrorMessage() file share path', () => {
|
|
100
|
+
expect(errorUtils.sanitizeErrorMessage(`file here: \\\\server\\share`)).toBe('file here: [path]');
|
|
101
|
+
});
|
|
102
|
+
test('sanitizeErrorMessage() with cpu id', () => {
|
|
103
|
+
expect(errorUtils.sanitizeErrorMessage('5>This is an error')).toBe('This is an error');
|
|
104
|
+
});
|
|
105
|
+
test('sanitizeErrorMessage() with cpu/thread id', () => {
|
|
106
|
+
expect(errorUtils.sanitizeErrorMessage('5:42>This is an error')).toEqual('This is an error');
|
|
107
|
+
});
|
|
108
|
+
test('sanitizeErrorStackFrame() with empty frame', () => {
|
|
109
|
+
const emptyFrame = {
|
|
110
|
+
level: 0,
|
|
111
|
+
method: '',
|
|
112
|
+
fileName: '',
|
|
113
|
+
assembly: 'asdf',
|
|
114
|
+
line: 0,
|
|
115
|
+
};
|
|
116
|
+
errorUtils.sanitizeErrorStackFrame(emptyFrame);
|
|
117
|
+
expect(emptyFrame).toEqual({
|
|
118
|
+
level: 0,
|
|
119
|
+
assembly: '',
|
|
120
|
+
fileName: '[path]',
|
|
121
|
+
method: '',
|
|
122
|
+
line: 0,
|
|
123
|
+
});
|
|
124
|
+
});
|
|
125
|
+
test('sanitizeErrorStackFrame() with assembly name', () => {
|
|
126
|
+
const frame1 = {
|
|
127
|
+
method: '',
|
|
128
|
+
fileName: `${process.cwd()}\\foo.js`,
|
|
129
|
+
assembly: 'asdf',
|
|
130
|
+
level: 0,
|
|
131
|
+
line: 0,
|
|
132
|
+
};
|
|
133
|
+
errorUtils.sanitizeErrorStackFrame(frame1);
|
|
134
|
+
expect(frame1).toEqual({
|
|
135
|
+
assembly: '',
|
|
136
|
+
fileName: '[project_dir]\\???.js(6)',
|
|
137
|
+
method: '',
|
|
138
|
+
level: 0,
|
|
139
|
+
line: 0,
|
|
140
|
+
});
|
|
141
|
+
});
|
|
142
|
+
test('sanitizeErrorStackFrame() with method name', () => {
|
|
143
|
+
const frame2 = {
|
|
144
|
+
method: `myMethod (something ${process.cwd()}`,
|
|
145
|
+
fileName: `${process.cwd()}\\telemetry\\foo.js`,
|
|
146
|
+
assembly: 'asdf',
|
|
147
|
+
level: 1,
|
|
148
|
+
line: 42,
|
|
149
|
+
};
|
|
150
|
+
errorUtils.sanitizeErrorStackFrame(frame2);
|
|
151
|
+
expect(frame2).toEqual({
|
|
152
|
+
assembly: '',
|
|
153
|
+
fileName: '[project_dir]\\???.js(16)',
|
|
154
|
+
method: 'myMethod',
|
|
155
|
+
level: 1,
|
|
156
|
+
line: 42,
|
|
157
|
+
});
|
|
158
|
+
});
|
|
159
|
+
//# sourceMappingURL=errorUtils.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errorUtils.test.js","sourceRoot":"","sources":["../../src/test/errorUtils.test.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;;;;;;;;;;;;;;;;;;AAIH,gEAAkD;AAElD,IAAI,CAAC,yCAAyC,EAAE,GAAG,EAAE;IACnD,MAAM,CAAC,UAAU,CAAC,eAAe,CAAC,kCAAkC,CAAC,CAAC,CAAC,IAAI,CACzE,SAAS,CACV,CAAC;AACJ,CAAC,CAAC,CAAC;AAEH,IAAI,CAAC,4CAA4C,EAAE,GAAG,EAAE;IACtD,MAAM,CAAC,UAAU,CAAC,eAAe,CAAC,mBAAmB,CAAC,CAAC,CAAC,aAAa,EAAE,CAAC;AAC1E,CAAC,CAAC,CAAC;AAEH,IAAI,CAAC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;QAClB,MAAM,EAAE,EAAE;QACV,IAAI,EAAE,CAAC;KACR,CAAC,CAAC;AACL,CAAC,CAAC,CAAC;AAEH,IAAI,CAAC,8CAA8C,EAAE,GAAG,EAAE;IACxD,MAAM,MAAM,GAAqC;QAC/C,MAAM,EAAE,EAAE;QACV,QAAQ,EAAE,GAAG,OAAO,CAAC,GAAG,EAAE,UAAU;QACpC,QAAQ,EAAE,MAAM;QAChB,KAAK,EAAE,CAAC;QACR,IAAI,EAAE,CAAC;KACR,CAAC;IACF,UAAU,CAAC,uBAAuB,CAAC,MAAM,CAAC,CAAC;IAC3C,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC;QACrB,QAAQ,EAAE,EAAE;QACZ,QAAQ,EAAE,0BAA0B;QACpC,MAAM,EAAE,EAAE;QACV,KAAK,EAAE,CAAC;QACR,IAAI,EAAE,CAAC;KACR,CAAC,CAAC;AACL,CAAC,CAAC,CAAC;AAEH,IAAI,CAAC,4CAA4C,EAAE,GAAG,EAAE;IACtD,MAAM,MAAM,GAAqC;QAC/C,MAAM,EAAE,uBAAuB,OAAO,CAAC,GAAG,EAAE,EAAE;QAC9C,QAAQ,EAAE,GAAG,OAAO,CAAC,GAAG,EAAE,qBAAqB;QAC/C,QAAQ,EAAE,MAAM;QAChB,KAAK,EAAE,CAAC;QACR,IAAI,EAAE,EAAE;KACT,CAAC;IACF,UAAU,CAAC,uBAAuB,CAAC,MAAM,CAAC,CAAC;IAC3C,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC;QACrB,QAAQ,EAAE,EAAE;QACZ,QAAQ,EAAE,2BAA2B;QACrC,MAAM,EAAE,UAAU;QAClB,KAAK,EAAE,CAAC;QACR,IAAI,EAAE,EAAE;KACT,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["/**\n * Copyright (c) Microsoft Corporation.\n * Licensed under the MIT License.\n *\n * @format\n */\n\nimport * as appInsights from 'applicationinsights';\n\nimport * as errorUtils from '../utils/errorUtils';\n\ntest('tryGetErrorCode() with valid error code', () => {\n expect(errorUtils.tryGetErrorCode('foo bar error FOO2020: the thing')).toBe(\n 'FOO2020',\n );\n});\n\ntest('tryGetErrorCode() without valid error code', () => {\n expect(errorUtils.tryGetErrorCode('foo bar the thing')).toBeUndefined();\n});\n\ntest('tryGetErrorCode() with word error but no code', () => {\n expect(errorUtils.tryGetErrorCode('test error')).toBeUndefined();\n});\n\ntest('sanitizeErrorMessage() no-op on empty string', () => {\n expect(errorUtils.sanitizeErrorMessage('')).toBe('');\n});\n\ntest('sanitizeErrorMessage() no-op on test string', () => {\n expect(errorUtils.sanitizeErrorMessage('some text')).toBe('some text');\n});\n\ntest(\"sanitizeErrorMessage() 'project_dir'\", () => {\n expect(\n errorUtils.sanitizeErrorMessage(`this is the cwd: '${process.cwd()}'`),\n ).toBe(`this is the cwd: [project_dir]`);\n});\n\ntest(\"sanitizeErrorMessage() 'project_dir' uppercase\", () => {\n expect(\n errorUtils.sanitizeErrorMessage(\n `uppercase: '${process.cwd().toUpperCase()}'`,\n ),\n ).toBe(`uppercase: [project_dir]`);\n});\n\ntest(\"sanitizeErrorMessage() 'project_dir' lowercase\", () => {\n expect(\n errorUtils.sanitizeErrorMessage(\n `lowercase: '${process.cwd().toLowerCase()}'`,\n ),\n ).toBe(`lowercase: [project_dir]`);\n});\n\ntest(\"sanitizeErrorMessage() 'project_dir' and something else\", () => {\n expect(\n errorUtils.sanitizeErrorMessage(\n `this is the cwd: '${process.cwd()}' and something else`,\n ),\n ).toBe(`this is the cwd: [project_dir] and something else`);\n});\n\ntest('sanitizeErrorMessage() project_dir and something else', () => {\n expect(\n errorUtils.sanitizeErrorMessage(\n `this is the cwd: ${process.cwd()} and something else`,\n ),\n ).toBe(\n `this is the cwd: [project_dir]\\\\???(${' and something else'.length})`,\n );\n});\n\ntest(\"sanitizeErrorMessage() 'node_modules'\", () => {\n expect(\n errorUtils.sanitizeErrorMessage(\n `this is the cwd: '${process.cwd()}\\\\node_modules'`,\n ),\n ).toBe(`this is the cwd: [project_dir]\\\\???(${'node_modules'.length})`);\n});\n\ntest(\"sanitizeErrorMessage() 'node_modules\\\\foo'\", () => {\n expect(\n errorUtils.sanitizeErrorMessage(\n `this is the cwd: '${process.cwd()}\\\\node_modules\\\\foo'`,\n ),\n ).toBe(`this is the cwd: [node_modules]\\\\???(${'foo'.length})`);\n});\n\ntest(\"sanitizeErrorMessage() 'node_modules\\\\foo' uppercase\", () => {\n expect(\n errorUtils.sanitizeErrorMessage(\n `uppercase: '${process.cwd().toUpperCase()}\\\\NODE_MODULES\\\\foo'`,\n ),\n ).toBe(`uppercase: [node_modules]\\\\???(${'foo'.length})`);\n});\n\ntest(\"sanitizeErrorMessage() 'node_modules\\\\foo' lowercase\", () => {\n expect(\n errorUtils.sanitizeErrorMessage(\n `lowercase: '${process.cwd().toLowerCase()}\\\\NODE_MODULES\\\\foo'`,\n ),\n ).toBe(`lowercase: [node_modules]\\\\???(${'foo'.length})`);\n});\n\ntest(\"sanitizeErrorMessage() 'node_modules\\\\' and something else\", () => {\n expect(\n errorUtils.sanitizeErrorMessage(\n `trailing: '${process.cwd()}\\\\node_modules\\\\' and something else`,\n ),\n ).toBe(`trailing: [node_modules]\\\\???(0) and something else`);\n});\n\ntest('sanitizeErrorMessage() node_modules and something else that could be part of the path', () => {\n expect(\n errorUtils.sanitizeErrorMessage(\n `this is the cwd: ${process.cwd()}\\\\node_modules and something else that could be part of the path`,\n ),\n ).toBe(\n `this is the cwd: [project_dir]\\\\???(${\n 'node_modules and something else that could be part of the path'.length\n })`,\n );\n});\n\ntest('sanitizeErrorMessage() \\\\node_modules\\\\ a file under nm', () => {\n expect(\n errorUtils.sanitizeErrorMessage(\n `this is the cwd: ${process.cwd()}\\\\node_modules\\\\ a file under nm`,\n ),\n ).toBe(`this is the cwd: [node_modules]\\\\???(${' a file under nm'.length})`);\n});\n\ntest('sanitizeErrorMessage() other path', () => {\n expect(\n errorUtils.sanitizeErrorMessage(`this is another path: A:\\\\foo\\\\bar\\\\baz`),\n ).toBe(`this is another path: [path]`);\n});\n\ntest(\"sanitizeErrorMessage() 'other path'\", () => {\n expect(\n errorUtils.sanitizeErrorMessage(\n `this is another path: 'A:\\\\foo\\\\bar\\\\baz'`,\n ),\n ).toBe(`this is another path: [path]`);\n});\n\ntest('sanitizeErrorMessage() tracked packages in the npx cache', () => {\n expect(\n errorUtils.sanitizeErrorMessage(\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 ).toBe(`Cannot find module react-native/package.json\n Require stack:\n - [node_modules]\\\\react-native-windows-init\\\\lib-commonjs\\\\Cli.js\n - [node_modules]\\\\react-native-windows-init\\\\bin.js`);\n});\n\ntest('sanitizeErrorMessage() forward slashes', () => {\n expect(\n errorUtils.sanitizeErrorMessage(\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 ).toBe(\n `EPERM: operation not permitted, scandir [UserProfile]\\\\???(${\n '/source/repos/rn2/wintest/windows/packages/boost.1.76.0.0/lib/native/include'\n .length\n })`,\n );\n});\n\ntest('sanitizeErrorMessage() file share path', () => {\n expect(errorUtils.sanitizeErrorMessage(`file here: \\\\\\\\server\\\\share`)).toBe(\n 'file here: [path]',\n );\n});\n\ntest('sanitizeErrorMessage() with cpu id', () => {\n expect(errorUtils.sanitizeErrorMessage('5>This is an error')).toBe(\n 'This is an error',\n );\n});\n\ntest('sanitizeErrorMessage() with cpu/thread id', () => {\n expect(errorUtils.sanitizeErrorMessage('5:42>This is an error')).toEqual(\n 'This is an error',\n );\n});\n\ntest('sanitizeErrorStackFrame() with empty frame', () => {\n const emptyFrame: appInsights.Contracts.StackFrame = {\n level: 0,\n method: '',\n fileName: '',\n assembly: 'asdf',\n line: 0,\n };\n errorUtils.sanitizeErrorStackFrame(emptyFrame);\n expect(emptyFrame).toEqual({\n level: 0,\n assembly: '',\n fileName: '[path]',\n method: '',\n line: 0,\n });\n});\n\ntest('sanitizeErrorStackFrame() with assembly name', () => {\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 errorUtils.sanitizeErrorStackFrame(frame1);\n expect(frame1).toEqual({\n assembly: '',\n fileName: '[project_dir]\\\\???.js(6)',\n method: '',\n level: 0,\n line: 0,\n });\n});\n\ntest('sanitizeErrorStackFrame() with method name', () => {\n const frame2: appInsights.Contracts.StackFrame = {\n method: `myMethod (something ${process.cwd()}`,\n fileName: `${process.cwd()}\\\\telemetry\\\\foo.js`,\n assembly: 'asdf',\n level: 1,\n line: 42,\n };\n errorUtils.sanitizeErrorStackFrame(frame2);\n expect(frame2).toEqual({\n assembly: '',\n fileName: '[project_dir]\\\\???.js(16)',\n method: 'myMethod',\n level: 1,\n line: 42,\n });\n});\n"]}
|
|
@@ -0,0 +1,84 @@
|
|
|
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
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
11
|
+
}) : (function(o, m, k, k2) {
|
|
12
|
+
if (k2 === undefined) k2 = k;
|
|
13
|
+
o[k2] = m[k];
|
|
14
|
+
}));
|
|
15
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
16
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
17
|
+
}) : function(o, v) {
|
|
18
|
+
o["default"] = v;
|
|
19
|
+
});
|
|
20
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
21
|
+
if (mod && mod.__esModule) return mod;
|
|
22
|
+
var result = {};
|
|
23
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
24
|
+
__setModuleDefault(result, mod);
|
|
25
|
+
return result;
|
|
26
|
+
};
|
|
27
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
28
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
29
|
+
};
|
|
30
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
31
|
+
const path_1 = __importDefault(require("path"));
|
|
32
|
+
const child_process_1 = require("child_process");
|
|
33
|
+
const projectUtils = __importStar(require("../utils/projectUtils"));
|
|
34
|
+
test('getProjectId() does not match project name', () => {
|
|
35
|
+
const projectName = 'test-project';
|
|
36
|
+
expect(projectUtils.getProjectId(projectName)).not.toContain(projectName);
|
|
37
|
+
});
|
|
38
|
+
test('getProjectId() does not change for same project name', () => {
|
|
39
|
+
const projectName = 'test-project';
|
|
40
|
+
expect(projectUtils.getProjectId(projectName)).toBe(projectUtils.getProjectId(projectName));
|
|
41
|
+
});
|
|
42
|
+
test('getProjectId() returns different ids for different project names', () => {
|
|
43
|
+
const projectName1 = 'test-project1';
|
|
44
|
+
const projectName2 = 'test-project2';
|
|
45
|
+
expect(projectUtils.getProjectId(projectName1)).not.toBe(projectUtils.getProjectId(projectName2));
|
|
46
|
+
});
|
|
47
|
+
test('usesReactNativeConfig() is false with no react-native.config.js present', async () => {
|
|
48
|
+
const projectRoot = path_1.default.resolve(__dirname, 'projects/BlankUsesTypeScript');
|
|
49
|
+
const value = await projectUtils.usesReactNativeConfig(projectRoot);
|
|
50
|
+
expect(value).toBe(false);
|
|
51
|
+
});
|
|
52
|
+
test('usesReactNativeConfig() is true with react-native.config.js present', async () => {
|
|
53
|
+
const projectRoot = path_1.default.resolve(__dirname, 'projects/BlankUsesReactNativeConfig');
|
|
54
|
+
const value = await projectUtils.usesReactNativeConfig(projectRoot);
|
|
55
|
+
expect(value).toBe(true);
|
|
56
|
+
});
|
|
57
|
+
test('usesTypeScript() is false with no tsconfig.json present', async () => {
|
|
58
|
+
const projectRoot = path_1.default.resolve(__dirname, 'projects/BlankUsesReactNativeConfig');
|
|
59
|
+
const value = await projectUtils.usesTypeScript(projectRoot);
|
|
60
|
+
expect(value).toBe(false);
|
|
61
|
+
});
|
|
62
|
+
test('usesTypeScript() is true with tsconfig.json present', async () => {
|
|
63
|
+
const projectRoot = path_1.default.resolve(__dirname, 'projects/BlankUsesTypeScript');
|
|
64
|
+
const value = await projectUtils.usesTypeScript(projectRoot);
|
|
65
|
+
expect(value).toBe(true);
|
|
66
|
+
});
|
|
67
|
+
test('configToProjectInfo() works with playground project info', async () => {
|
|
68
|
+
const playgroundRoot = path_1.default.resolve(__dirname, '../../../../playground');
|
|
69
|
+
const config = JSON.parse((0, child_process_1.execSync)('npx react-native config', {
|
|
70
|
+
cwd: playgroundRoot,
|
|
71
|
+
stdio: ['ignore', 'pipe', 'ignore'],
|
|
72
|
+
}).toString());
|
|
73
|
+
const info = await projectUtils.configToProjectInfo(config);
|
|
74
|
+
expect(info).not.toBeNull();
|
|
75
|
+
const projectInfo = info;
|
|
76
|
+
expect(projectInfo.id).toBe(projectUtils.getProjectId('playground'));
|
|
77
|
+
expect(projectInfo.platforms).toStrictEqual(['windows']);
|
|
78
|
+
expect(projectInfo.rnwLang).toBe('cpp');
|
|
79
|
+
expect(projectInfo.usesTS).toBe(true);
|
|
80
|
+
expect(projectInfo.usesRNConfig).toBe(true);
|
|
81
|
+
expect(projectInfo.jsEngine).toBe('Hermes');
|
|
82
|
+
expect(projectInfo.rnwSource).toBe('Source');
|
|
83
|
+
});
|
|
84
|
+
//# sourceMappingURL=projectU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AC;IAEF,MAAM,IAAI,GAAG,MAAM,YAAY,CAAC,mBAAmB,CAAC,MAAM,CAAC,CAAC;IAC5D,MAAM,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC;IAE5B,MAAM,WAAW,GAAG,IAAmC,CAAC;IAExD,MAAM,CAAC,WAAW,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,YAAY,CAAC,YAAY,CAAC,YAAY,CAAC,CAAC,CAAC;IACrE,MAAM,CAAC,WAAW,CAAC,SAAS,CAAC,CAAC,aAAa,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC;IACzD,MAAM,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACxC,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACtC,MAAM,CAAC,WAAW,CAAC,YAAY,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC5C,MAAM,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IAC5C,MAAM,CAAC,WAAW,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;AAC/C,CAAC,CAAC,CAAC","sourcesContent":["/**\n * Copyright (c) Microsoft Corporation.\n * Licensed under the MIT License.\n *\n * @format\n */\n\nimport path from 'path';\nimport {execSync} from 'child_process';\n\nimport * as projectUtils from '../utils/projectUtils';\n\ntest('getProjectId() does not match project name', () => {\n const projectName = 'test-project';\n expect(projectUtils.getProjectId(projectName)).not.toContain(projectName);\n});\n\ntest('getProjectId() does not change for same project name', () => {\n const projectName = 'test-project';\n expect(projectUtils.getProjectId(projectName)).toBe(\n projectUtils.getProjectId(projectName),\n );\n});\n\ntest('getProjectId() returns different ids for different project names', () => {\n const projectName1 = 'test-project1';\n const projectName2 = 'test-project2';\n expect(projectUtils.getProjectId(projectName1)).not.toBe(\n projectUtils.getProjectId(projectName2),\n );\n});\n\ntest('usesReactNativeConfig() is false with no react-native.config.js present', async () => {\n const projectRoot = path.resolve(__dirname, 'projects/BlankUsesTypeScript');\n const value = await projectUtils.usesReactNativeConfig(projectRoot);\n expect(value).toBe(false);\n});\n\ntest('usesReactNativeConfig() is true with react-native.config.js present', async () => {\n const projectRoot = path.resolve(\n __dirname,\n 'projects/BlankUsesReactNativeConfig',\n );\n const value = await projectUtils.usesReactNativeConfig(projectRoot);\n expect(value).toBe(true);\n});\n\ntest('usesTypeScript() is false with no tsconfig.json present', async () => {\n const projectRoot = path.resolve(\n __dirname,\n 'projects/BlankUsesReactNativeConfig',\n );\n const value = await projectUtils.usesTypeScript(projectRoot);\n expect(value).toBe(false);\n});\n\ntest('usesTypeScript() is true with tsconfig.json present', async () => {\n const projectRoot = path.resolve(__dirname, 'projects/BlankUsesTypeScript');\n const value = await projectUtils.usesTypeScript(projectRoot);\n expect(value).toBe(true);\n});\n\ntest('configToProjectInfo() works with playground project info', async () => {\n const playgroundRoot = path.resolve(__dirname, '../../../../playground');\n const config = JSON.parse(\n execSync('npx react-native config', {\n cwd: playgroundRoot,\n stdio: ['ignore', 'pipe', 'ignore'],\n }).toString(),\n );\n\n const info = await projectUtils.configToProjectInfo(config);\n expect(info).not.toBeNull();\n\n const projectInfo = info as projectUtils.AppProjectInfo;\n\n expect(projectInfo.id).toBe(projectUtils.getProjectId('playground'));\n expect(projectInfo.platforms).toStrictEqual(['windows']);\n expect(projectInfo.rnwLang).toBe('cpp');\n expect(projectInfo.usesTS).toBe(true);\n expect(projectInfo.usesRNConfig).toBe(true);\n expect(projectInfo.jsEngine).toBe('Hermes');\n expect(projectInfo.rnwSource).toBe('Source');\n});\n"]}
|
|
@@ -0,0 +1,94 @@
|
|
|
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
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
11
|
+
}) : (function(o, m, k, k2) {
|
|
12
|
+
if (k2 === undefined) k2 = k;
|
|
13
|
+
o[k2] = m[k];
|
|
14
|
+
}));
|
|
15
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
16
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
17
|
+
}) : function(o, v) {
|
|
18
|
+
o["default"] = v;
|
|
19
|
+
});
|
|
20
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
21
|
+
if (mod && mod.__esModule) return mod;
|
|
22
|
+
var result = {};
|
|
23
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
24
|
+
__setModuleDefault(result, mod);
|
|
25
|
+
return result;
|
|
26
|
+
};
|
|
27
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
28
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
29
|
+
};
|
|
30
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
31
|
+
const path_1 = __importDefault(require("path"));
|
|
32
|
+
const sanitizeUtils = __importStar(require("../utils/sanitizeUtils"));
|
|
33
|
+
const projectDir = process.cwd();
|
|
34
|
+
test('getAnonymizedPath() with project dir is anonymized', () => {
|
|
35
|
+
const originalPath = projectDir;
|
|
36
|
+
const anonymizedPath = sanitizeUtils.getAnonymizedPath(originalPath);
|
|
37
|
+
expect(anonymizedPath).not.toBe(originalPath);
|
|
38
|
+
expect(anonymizedPath.startsWith('[project_dir]')).toBe(true);
|
|
39
|
+
});
|
|
40
|
+
test('getAnonymizedPath() with project/index.js is anonymized', () => {
|
|
41
|
+
const originalPath = path_1.default.join(projectDir, 'index.js');
|
|
42
|
+
const anonymizedPath = sanitizeUtils.getAnonymizedPath(originalPath);
|
|
43
|
+
expect(anonymizedPath).not.toBe(originalPath);
|
|
44
|
+
expect(anonymizedPath.startsWith('[project_dir]\\???.js')).toBe(true);
|
|
45
|
+
});
|
|
46
|
+
test('getAnonymizedPath() with project/windows/test.sln is anonymized', () => {
|
|
47
|
+
const originalPath = path_1.default.normalize(path_1.default.join(projectDir, 'windows/test.sln'));
|
|
48
|
+
const anonymizedPath = sanitizeUtils.getAnonymizedPath(originalPath);
|
|
49
|
+
expect(anonymizedPath).not.toBe(originalPath);
|
|
50
|
+
expect(anonymizedPath.startsWith('[windows]\\???.sln')).toBe(true);
|
|
51
|
+
});
|
|
52
|
+
test('getAnonymizedPath() with project/node_modules for untracked package is anonymized', () => {
|
|
53
|
+
const originalPath = path_1.default.normalize(path_1.default.join(projectDir, 'node_modules/untracked/index.js'));
|
|
54
|
+
const anonymizedPath = sanitizeUtils.getAnonymizedPath(originalPath);
|
|
55
|
+
expect(anonymizedPath).not.toBe(originalPath);
|
|
56
|
+
expect(anonymizedPath.startsWith('[node_modules]\\???.js')).toBe(true);
|
|
57
|
+
});
|
|
58
|
+
test('getAnonymizedPath() with project/node_modules for react-secret-pii package is anonymized', () => {
|
|
59
|
+
const originalPath = path_1.default.normalize(path_1.default.join(projectDir, 'node_modules/react-secret-pii/index.js'));
|
|
60
|
+
const anonymizedPath = sanitizeUtils.getAnonymizedPath(originalPath);
|
|
61
|
+
expect(anonymizedPath).not.toBe(originalPath);
|
|
62
|
+
expect(anonymizedPath.startsWith('[node_modules]\\???.js')).toBe(true);
|
|
63
|
+
});
|
|
64
|
+
test('getAnonymizedPath() with path under react-native-windows is anonymized', () => {
|
|
65
|
+
const originalPath = path_1.default.normalize(path_1.default.join(projectDir, 'node_modules/react-native-windows/index.js'));
|
|
66
|
+
const anonymizedPath = sanitizeUtils.getAnonymizedPath(originalPath);
|
|
67
|
+
expect(anonymizedPath).not.toBe(originalPath);
|
|
68
|
+
expect(anonymizedPath).toBe('[node_modules]\\react-native-windows\\index.js');
|
|
69
|
+
});
|
|
70
|
+
test('getAnonymizedPath() with path under @react-native-windows/cli is anonymized', () => {
|
|
71
|
+
const originalPath = path_1.default.normalize(path_1.default.join(projectDir, 'node_modules/@react-native-windows/cli/index.js'));
|
|
72
|
+
const anonymizedPath = sanitizeUtils.getAnonymizedPath(originalPath);
|
|
73
|
+
expect(anonymizedPath).not.toBe(originalPath);
|
|
74
|
+
expect(anonymizedPath).toBe('[node_modules]\\@react-native-windows\\cli\\index.js');
|
|
75
|
+
});
|
|
76
|
+
test('getAnonymizedPath() with path under %%LocalAppData%% is anonymized', () => {
|
|
77
|
+
const originalPath = path_1.default.normalize(path_1.default.join(process.env.LocalAppData, 'test.sln'));
|
|
78
|
+
const anonymizedPath = sanitizeUtils.getAnonymizedPath(originalPath);
|
|
79
|
+
expect(anonymizedPath).not.toBe(originalPath);
|
|
80
|
+
expect(anonymizedPath.startsWith('[LocalAppData]\\???')).toBe(true);
|
|
81
|
+
});
|
|
82
|
+
test('getAnonymizedPath() with a tracked npm package under %%LocalAppData%% is anonymized', () => {
|
|
83
|
+
const originalPath = path_1.default.normalize(path_1.default.join(process.env.LocalAppData, 'node_modules/@react-native-windows/cli/index.js'));
|
|
84
|
+
const anonymizedPath = sanitizeUtils.getAnonymizedPath(originalPath);
|
|
85
|
+
expect(anonymizedPath).not.toBe(originalPath);
|
|
86
|
+
expect(anonymizedPath).toBe('[node_modules]\\@react-native-windows\\cli\\index.js');
|
|
87
|
+
});
|
|
88
|
+
test('getAnonymizedPath() with arbitrary path not under project dir is anonymized', () => {
|
|
89
|
+
const originalPath = 'test.sln';
|
|
90
|
+
const anonymizedPath = sanitizeUtils.getAnonymizedPath(originalPath);
|
|
91
|
+
expect(anonymizedPath).not.toBe(originalPath);
|
|
92
|
+
expect(anonymizedPath).toBe('[path]');
|
|
93
|
+
});
|
|
94
|
+
//# sourceMappingURL=sanitizeUtils.test.js.map
|