Skip to content

Commit

Permalink
fix breaking changes
Browse files Browse the repository at this point in the history
  • Loading branch information
mattseddon committed Feb 13, 2023
1 parent 85a9ea6 commit eb1d998
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 42 deletions.
1 change: 0 additions & 1 deletion extension/src/telemetry/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { SortDefinition } from '../experiments/model/sortBy'
import { Section, SectionCollapsed } from '../plots/webview/contract'

export const APPLICATION_INSIGHTS_KEY = '46e8e554-d50a-471a-a53b-4af2b1cd6594'
export const EXTENSION_ID = 'iterative.dvc'

const ViewOpenedEvent = {
VIEWS_EXPERIMENTS_FILTER_BY_TREE_OPENED:
Expand Down
22 changes: 1 addition & 21 deletions extension/src/telemetry/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,13 @@
import { extensions } from 'vscode'
// eslint-disable-next-line import/default
import TelemetryReporter from '@vscode/extension-telemetry'
import { getTelemetryReporter, sendTelemetryEvent } from '.'
import {
APPLICATION_INSIGHTS_KEY,
EXTENSION_ID,
IEventNamePropertyMapping
} from './constants'
import { getUserId } from './uuid'

const mockedTelemetryReporter = jest.mocked(TelemetryReporter)

const mockedExtensions = jest.mocked(extensions)
const mockedGetExtension = jest.fn()
mockedExtensions.getExtension = mockedGetExtension
const mockedPackageJSON = {
id: EXTENSION_ID,
name: 'dvc',
version: '0.1.0'
}
const mockedSendTelemetryEvent = jest.fn()
const mockedGetUserId = jest.mocked(getUserId)

Expand Down Expand Up @@ -46,20 +35,12 @@ describe('getTelemetryReporter', () => {
let telemetryReporter: TelemetryReporter | undefined

it('should create a reporter on the first call', () => {
mockedGetExtension.mockReturnValueOnce({
packageJSON: mockedPackageJSON
})
telemetryReporter = getTelemetryReporter()

expect(telemetryReporter).toBeDefined()
expect(mockedGetExtension).toHaveBeenCalledTimes(1)
expect(mockedGetExtension).toHaveBeenCalledWith('iterative.dvc')
expect(mockedTelemetryReporter).toHaveBeenCalledTimes(1)
expect(mockedTelemetryReporter).toHaveBeenCalledWith(
EXTENSION_ID,
mockedPackageJSON.version,
APPLICATION_INSIGHTS_KEY,
true
APPLICATION_INSIGHTS_KEY
)
})

Expand All @@ -68,7 +49,6 @@ describe('getTelemetryReporter', () => {

expect(telemetryReporter).toStrictEqual(sameTelemetryReporter)
expect(mockedTelemetryReporter).not.toHaveBeenCalled()
expect(mockedGetExtension).not.toHaveBeenCalled()
})
})

Expand Down
11 changes: 1 addition & 10 deletions extension/src/telemetry/index.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
// eslint-disable-next-line import/default
import TelemetryReporter from '@vscode/extension-telemetry'
import {
EXTENSION_ID,
APPLICATION_INSIGHTS_KEY,
IEventNamePropertyMapping,
ViewOpenedEventName
} from './constants'
import { getUserId } from './uuid'
import { Logger } from '../common/logger'
import { getExtensionVersion } from '../vscode/extensions'

const isTestExecution = (): boolean =>
!!process.env.VSC_TEST || process.env.NODE_ENV === 'test'
Expand All @@ -20,14 +18,7 @@ export const getTelemetryReporter = (): TelemetryReporter => {
return telemetryReporter
}

const version = getExtensionVersion(EXTENSION_ID) || 'unknown'

telemetryReporter = new TelemetryReporter(
EXTENSION_ID,
version,
APPLICATION_INSIGHTS_KEY,
true
)
telemetryReporter = new TelemetryReporter(APPLICATION_INSIGHTS_KEY)
return telemetryReporter
}

Expand Down
10 changes: 0 additions & 10 deletions extension/src/vscode/extensions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,6 @@ export const getExtensionAPI = async <T>(
} catch {}
}

export const getExtensionVersion = <T>(id: string): string | undefined => {
const extension = getExtension<T>(id)

if (!extension) {
return
}

return (extension.packageJSON as { version: string }).version
}

export const isInstalled = (id: string): boolean =>
!!extensions.all.some(extension => extension.id === id)

Expand Down

0 comments on commit eb1d998

Please sign in to comment.