From eed4d44c2f67b75ffe24fa5643c7a7962d5a8a58 Mon Sep 17 00:00:00 2001 From: Matt Seddon Date: Tue, 12 Jul 2022 15:07:47 +1000 Subject: [PATCH 1/3] Add end to end test for SCM and file decorations --- .../src/repository/decorationProvider.ts | 2 +- extension/src/test/e2e/extension.test.ts | 49 +++++++++++++++++++ extension/src/test/e2e/util.ts | 27 +++++++++- 3 files changed, 76 insertions(+), 2 deletions(-) diff --git a/extension/src/repository/decorationProvider.ts b/extension/src/repository/decorationProvider.ts index 3e42be857d..02cc4b43d4 100644 --- a/extension/src/repository/decorationProvider.ts +++ b/extension/src/repository/decorationProvider.ts @@ -63,7 +63,7 @@ export class DecorationProvider private static DecorationGitModified: FileDecoration = { badge: 'M', color: new ThemeColor('gitDecoration.stageModifiedResourceForeground'), - tooltip: 'DVC tracked' + tooltip: 'DVC modified' } private static DecorationTracked: FileDecoration = { diff --git a/extension/src/test/e2e/extension.test.ts b/extension/src/test/e2e/extension.test.ts index 585f225b02..b13e6ae636 100644 --- a/extension/src/test/e2e/extension.test.ts +++ b/extension/src/test/e2e/extension.test.ts @@ -1,8 +1,12 @@ +import { join } from 'path' import { suite, before, describe, it } from 'mocha' import { closeAllEditors, dismissAllNotifications, + findDecorationTooltip, + findScmTreeItems, getDVCActivityBarIcon, + getLabel, waitForDvcToFinish, waitForViewContainerToLoad } from './util' @@ -117,4 +121,49 @@ suite('DVC Extension For Visual Studio Code', () => { await webview.unfocus() }) }) + + // eslint-disable-next-line sonarjs/cognitive-complexity + describe('Source Control View', () => { + it('should show the expected changes after running an experiment', async () => { + const treeItems = await findScmTreeItems() + + const expectedScmItemLabels = [ + 'demo DVC', + 'training_metrics', + 'scalars, training_metrics', + `acc.tsv, ${join('training_metrics', 'scalars')}`, + `loss.tsv, ${join('training_metrics', 'scalars')}` + ] + const expectedScmSet = new Set(expectedScmItemLabels) + let dvcTreeItemLabels: string[] = [] + + await browser.waitUntil( + async () => { + dvcTreeItemLabels = [] + for (const treeItem of treeItems) { + const treeItemLabel = await getLabel(treeItem) + if (!expectedScmSet.has(treeItemLabel)) { + continue + } + dvcTreeItemLabels.push(treeItemLabel) + if (treeItemLabel === 'demo DVC') { + continue + } + + const tooltip = await findDecorationTooltip(treeItem) + expect(tooltip).toBeTruthy() + } + return expectedScmItemLabels.length === dvcTreeItemLabels.length + }, + { + interval: 5000, + timeout: 60000 + } + ) + + expect(expectedScmItemLabels.sort()).toStrictEqual( + dvcTreeItemLabels.sort() + ) + }).timeout(60000) + }) }) diff --git a/extension/src/test/e2e/util.ts b/extension/src/test/e2e/util.ts index d6c66b3ed6..f47c1d305d 100644 --- a/extension/src/test/e2e/util.ts +++ b/extension/src/test/e2e/util.ts @@ -1,9 +1,24 @@ -import { ChainablePromiseArray, ElementArray } from 'webdriverio' +import { + ChainablePromiseArray, + ChainablePromiseElement, + ElementArray +} from 'webdriverio' import { ViewControl } from 'wdio-vscode-service' const findProgressBars = (): ChainablePromiseArray => $$('.monaco-progress-container') +const findCurrentTreeItems = (): ChainablePromiseArray => + $$('div[role="treeitem"]') + +export const getLabel = (element: WebdriverIO.Element): Promise => + element.getAttribute('aria-label') + +export const findDecorationTooltip = ( + element: WebdriverIO.Element +): ChainablePromiseElement => + element.$('div[title*="• DVC modified"]') + export const dismissAllNotifications = async (): Promise => { await browser.waitUntil(async () => { const workbench = await browser.getWorkbench() @@ -96,3 +111,13 @@ export const closeAllEditors = async (): Promise => { const editorView = workbench.getEditorView() return editorView.closeAllEditors() } + +export const findScmTreeItems = async () => { + const workspace = await browser.getWorkbench() + const activityBar = workspace.getActivityBar() + const sourceControlIcon = await activityBar.getViewControl('Source Control') + + await sourceControlIcon?.openView() + + return findCurrentTreeItems() +} From 39aa7c31542811be018403587ac1a1a39862e8d6 Mon Sep 17 00:00:00 2001 From: Matt Seddon Date: Tue, 12 Jul 2022 15:26:50 +1000 Subject: [PATCH 2/3] refind tree items in every wait for retry --- extension/src/test/e2e/extension.test.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/extension/src/test/e2e/extension.test.ts b/extension/src/test/e2e/extension.test.ts index b13e6ae636..e57f5ec035 100644 --- a/extension/src/test/e2e/extension.test.ts +++ b/extension/src/test/e2e/extension.test.ts @@ -125,8 +125,6 @@ suite('DVC Extension For Visual Studio Code', () => { // eslint-disable-next-line sonarjs/cognitive-complexity describe('Source Control View', () => { it('should show the expected changes after running an experiment', async () => { - const treeItems = await findScmTreeItems() - const expectedScmItemLabels = [ 'demo DVC', 'training_metrics', @@ -140,6 +138,7 @@ suite('DVC Extension For Visual Studio Code', () => { await browser.waitUntil( async () => { dvcTreeItemLabels = [] + const treeItems = await findScmTreeItems() for (const treeItem of treeItems) { const treeItemLabel = await getLabel(treeItem) if (!expectedScmSet.has(treeItemLabel)) { From dbbba1ec9388f695567a4da05c71d8d32b797d59 Mon Sep 17 00:00:00 2001 From: Matt Seddon Date: Wed, 13 Jul 2022 09:52:28 +1000 Subject: [PATCH 3/3] remove timeout as it is set at global level --- extension/src/test/e2e/extension.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extension/src/test/e2e/extension.test.ts b/extension/src/test/e2e/extension.test.ts index e57f5ec035..008794a235 100644 --- a/extension/src/test/e2e/extension.test.ts +++ b/extension/src/test/e2e/extension.test.ts @@ -163,6 +163,6 @@ suite('DVC Extension For Visual Studio Code', () => { expect(expectedScmItemLabels.sort()).toStrictEqual( dvcTreeItemLabels.sort() ) - }).timeout(60000) + }) }) })