From fac36f6783c5bede76b062698331a46d673c3e9d Mon Sep 17 00:00:00 2001 From: Kim-Adeline Miguel Date: Mon, 4 May 2020 12:41:50 -0700 Subject: [PATCH 1/2] Fix slashes --- src/test/telemetry/index.unit.test.ts | 58 ++++++++++++++------------- src/test/testing/helper.ts | 2 +- 2 files changed, 31 insertions(+), 29 deletions(-) diff --git a/src/test/telemetry/index.unit.test.ts b/src/test/telemetry/index.unit.test.ts index 0823d7b341ef..7ab931e31071 100644 --- a/src/test/telemetry/index.unit.test.ts +++ b/src/test/telemetry/index.unit.test.ts @@ -13,6 +13,7 @@ import { IWorkspaceService } from '../../client/common/application/types'; import { WorkspaceService } from '../../client/common/application/workspace'; import { EXTENSION_ROOT_DIR } from '../../client/constants'; import { clearTelemetryReporter, isTelemetryDisabled, sendTelemetryEvent } from '../../client/telemetry'; +import { fixPath } from '../testing/helper'; suite('Telemetry', () => { let workspaceService: IWorkspaceService; @@ -138,22 +139,23 @@ suite('Telemetry', () => { test('Send Error Telemetry with stack trace', () => { rewiremock.enable(); const error = new Error('Boo'); + const root = fixPath(EXTENSION_ROOT_DIR); error.stack = [ 'Error: Boo', - `at Context.test (${EXTENSION_ROOT_DIR}/src/test/telemetry/index.unit.test.ts:50:23)`, - `at callFn (${EXTENSION_ROOT_DIR}/node_modules/mocha/lib/runnable.js:372:21)`, - `at Test.Runnable.run (${EXTENSION_ROOT_DIR}/node_modules/mocha/lib/runnable.js:364:7)`, - `at Runner.runTest (${EXTENSION_ROOT_DIR}/node_modules/mocha/lib/runner.js:455:10)`, - `at ${EXTENSION_ROOT_DIR}/node_modules/mocha/lib/runner.js:573:12`, - `at next (${EXTENSION_ROOT_DIR}/node_modules/mocha/lib/runner.js:369:14)`, - `at ${EXTENSION_ROOT_DIR}/node_modules/mocha/lib/runner.js:379:7`, - `at next (${EXTENSION_ROOT_DIR}/node_modules/mocha/lib/runner.js:303:14)`, - `at ${EXTENSION_ROOT_DIR}/node_modules/mocha/lib/runner.js:342:7`, - `at done (${EXTENSION_ROOT_DIR}/node_modules/mocha/lib/runnable.js:319:5)`, - `at callFn (${EXTENSION_ROOT_DIR}/node_modules/mocha/lib/runnable.js:395:7)`, - `at Hook.Runnable.run (${EXTENSION_ROOT_DIR}/node_modules/mocha/lib/runnable.js:364:7)`, - `at next (${EXTENSION_ROOT_DIR}/node_modules/mocha/lib/runner.js:317:10)`, - `at Immediate. (${EXTENSION_ROOT_DIR}/node_modules/mocha/lib/runner.js:347:5)`, + `at Context.test (${root}/src/test/telemetry/index.unit.test.ts:50:23)`, + `at callFn (${root}/node_modules/mocha/lib/runnable.js:372:21)`, + `at Test.Runnable.run (${root}/node_modules/mocha/lib/runnable.js:364:7)`, + `at Runner.runTest (${root}/node_modules/mocha/lib/runner.js:455:10)`, + `at ${root}/node_modules/mocha/lib/runner.js:573:12`, + `at next (${root}/node_modules/mocha/lib/runner.js:369:14)`, + `at ${root}/node_modules/mocha/lib/runner.js:379:7`, + `at next (${root}/node_modules/mocha/lib/runner.js:303:14)`, + `at ${root}/node_modules/mocha/lib/runner.js:342:7`, + `at done (${root}/node_modules/mocha/lib/runnable.js:319:5)`, + `at callFn (${root}/node_modules/mocha/lib/runnable.js:395:7)`, + `at Hook.Runnable.run (${root}/node_modules/mocha/lib/runnable.js:364:7)`, + `at next (${root}/node_modules/mocha/lib/runner.js:317:10)`, + `at Immediate. (${root}/node_modules/mocha/lib/runner.js:347:5)`, 'at runCallback (timers.js:789:20)', 'at tryOnImmediate (timers.js:751:5)', 'at processImmediate [as _immediateCallback] (timers.js:722:5)' @@ -181,20 +183,20 @@ suite('Telemetry', () => { expect(Reporter.errorProps).to.deep.equal([]); const expectedStack = [ - `at Context.test ${EXTENSION_ROOT_DIR}/src/test/telemetry/index.unit.test.ts:50:23`, - `at callFn ${EXTENSION_ROOT_DIR}/node_modules/mocha/lib/runnable.js:372:21`, - `at Test.Runnable.run ${EXTENSION_ROOT_DIR}/node_modules/mocha/lib/runnable.js:364:7`, - `at Runner.runTest ${EXTENSION_ROOT_DIR}/node_modules/mocha/lib/runner.js:455:10`, - `at ${EXTENSION_ROOT_DIR}/node_modules/mocha/lib/runner.js:573:12`, - `at next ${EXTENSION_ROOT_DIR}/node_modules/mocha/lib/runner.js:369:14`, - `at ${EXTENSION_ROOT_DIR}/node_modules/mocha/lib/runner.js:379:7`, - `at next ${EXTENSION_ROOT_DIR}/node_modules/mocha/lib/runner.js:303:14`, - `at ${EXTENSION_ROOT_DIR}/node_modules/mocha/lib/runner.js:342:7`, - `at done ${EXTENSION_ROOT_DIR}/node_modules/mocha/lib/runnable.js:319:5`, - `at callFn ${EXTENSION_ROOT_DIR}/node_modules/mocha/lib/runnable.js:395:7`, - `at Hook.Runnable.run ${EXTENSION_ROOT_DIR}/node_modules/mocha/lib/runnable.js:364:7`, - `at next ${EXTENSION_ROOT_DIR}/node_modules/mocha/lib/runner.js:317:10`, - `at Immediate ${EXTENSION_ROOT_DIR}/node_modules/mocha/lib/runner.js:347:5`, + `at Context.test ${root}/src/test/telemetry/index.unit.test.ts:50:23`, + `at callFn ${root}/node_modules/mocha/lib/runnable.js:372:21`, + `at Test.Runnable.run ${root}/node_modules/mocha/lib/runnable.js:364:7`, + `at Runner.runTest ${root}/node_modules/mocha/lib/runner.js:455:10`, + `at ${root}/node_modules/mocha/lib/runner.js:573:12`, + `at next ${root}/node_modules/mocha/lib/runner.js:369:14`, + `at ${root}/node_modules/mocha/lib/runner.js:379:7`, + `at next ${root}/node_modules/mocha/lib/runner.js:303:14`, + `at ${root}/node_modules/mocha/lib/runner.js:342:7`, + `at done ${root}/node_modules/mocha/lib/runnable.js:319:5`, + `at callFn ${root}/node_modules/mocha/lib/runnable.js:395:7`, + `at Hook.Runnable.run ${root}/node_modules/mocha/lib/runnable.js:364:7`, + `at next ${root}/node_modules/mocha/lib/runner.js:317:10`, + `at Immediate ${root}/node_modules/mocha/lib/runner.js:347:5`, 'at runCallback timers.js:789:20', 'at tryOnImmediate timers.js:751:5', 'at processImmediate [as _immediateCallback] timers.js:722:5' diff --git a/src/test/testing/helper.ts b/src/test/testing/helper.ts index d973f28d07d6..3f9ffbf44c89 100644 --- a/src/test/testing/helper.ts +++ b/src/test/testing/helper.ts @@ -32,7 +32,7 @@ export function lookForTestFile(tests: Tests, testFile: string) { // Only "/" (forward slash) in the given filename is affected. // // This helps with readability in test code. It allows us to use -// literals for filenames and dirnames instead of oath.join(). +// literals for filenames and dirnames instead of path.join(). export function fixPath(filename: string): string { return filename.replace(/\//, sep); } From 4eca6fccd2469db3c2571ecf8770a2d90276d11f Mon Sep 17 00:00:00 2001 From: Kim-Adeline Miguel Date: Mon, 4 May 2020 13:27:52 -0700 Subject: [PATCH 2/2] Don't use fix path, replace sep directly --- src/test/telemetry/index.unit.test.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/test/telemetry/index.unit.test.ts b/src/test/telemetry/index.unit.test.ts index 7ab931e31071..0bc9d757649e 100644 --- a/src/test/telemetry/index.unit.test.ts +++ b/src/test/telemetry/index.unit.test.ts @@ -13,7 +13,6 @@ import { IWorkspaceService } from '../../client/common/application/types'; import { WorkspaceService } from '../../client/common/application/workspace'; import { EXTENSION_ROOT_DIR } from '../../client/constants'; import { clearTelemetryReporter, isTelemetryDisabled, sendTelemetryEvent } from '../../client/telemetry'; -import { fixPath } from '../testing/helper'; suite('Telemetry', () => { let workspaceService: IWorkspaceService; @@ -139,7 +138,7 @@ suite('Telemetry', () => { test('Send Error Telemetry with stack trace', () => { rewiremock.enable(); const error = new Error('Boo'); - const root = fixPath(EXTENSION_ROOT_DIR); + const root = EXTENSION_ROOT_DIR.replace(/\\/g, '/'); error.stack = [ 'Error: Boo', `at Context.test (${root}/src/test/telemetry/index.unit.test.ts:50:23)`,