Skip to content

Commit

Permalink
Merge branch 'master' into move-added-into-ready-to-commit
Browse files Browse the repository at this point in the history
  • Loading branch information
mattseddon authored Oct 19, 2021
2 parents 8e4843e + b3a7cbf commit a01f684
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 30 deletions.
9 changes: 7 additions & 2 deletions extension/src/test/suite/experiments/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@ import { AvailableCommands, InternalCommands } from '../../../commands/internal'
import { ExperimentsWebview } from '../../../experiments/webview'
import { QuickPickItemWithValue } from '../../../vscode/quickPick'
import { ParamOrMetric } from '../../../experiments/webview/contract'
import { dvcDemoPath, experimentsUpdatedEvent, resourcePath } from '../util'
import {
closeAllEditors,
dvcDemoPath,
experimentsUpdatedEvent,
resourcePath
} from '../util'
import { buildMockMemento } from '../../util'
import { SortDefinition } from '../../../experiments/model/sortBy'
import { FilterDefinition, Operator } from '../../../experiments/model/filterBy'
Expand All @@ -35,7 +40,7 @@ suite('Experiments Test Suite', () => {

afterEach(() => {
disposable.dispose()
return commands.executeCommand('workbench.action.closeAllEditors')
return closeAllEditors()
})

describe('refresh', () => {
Expand Down
4 changes: 2 additions & 2 deletions extension/src/test/suite/experiments/workspace.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import * as QuickPick from '../../../vscode/quickPick'
import { CliRunner } from '../../../cli/runner'
import { AvailableCommands, InternalCommands } from '../../../commands/internal'
import { CliExecutor } from '../../../cli/executor'
import { dvcDemoPath, resourcePath } from '../util'
import { closeAllEditors, dvcDemoPath, resourcePath } from '../util'
import { buildMockMemento } from '../../util'
import { RegisteredCliCommands } from '../../../commands/external'
import * as Telemetry from '../../../telemetry'
Expand All @@ -30,7 +30,7 @@ suite('Workspace Experiments Test Suite', () => {

afterEach(() => {
disposable.dispose()
return commands.executeCommand('workbench.action.closeAllEditors')
return closeAllEditors()
})

const onDidChangeIsWebviewFocused = (
Expand Down
3 changes: 2 additions & 1 deletion extension/src/test/suite/extension.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { expect } from 'chai'
import { stub, restore, spy, useFakeTimers, SinonStub, match } from 'sinon'
import { window, commands, workspace, Uri } from 'vscode'
import {
closeAllEditors,
configurationChangeEvent,
quickPickInitialized,
selectQuickPickItem
Expand Down Expand Up @@ -36,7 +37,7 @@ suite('Extension Test Suite', () => {
return Promise.all([
workspace.getConfiguration().update(dvcPathOption, undefined, false),
workspace.getConfiguration().update(pythonPathOption, undefined, false),
commands.executeCommand('workbench.action.closeAllEditors')
closeAllEditors()
])
})

Expand Down
8 changes: 4 additions & 4 deletions extension/src/test/suite/fileSystem/tree.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import * as WorkspaceFolders from '../../../vscode/workspaceFolders'
import * as Setup from '../../../setup'
import {
activeTextEditorChangedEvent,
closeAllEditors,
dvcDemoPath,
getActiveTextEditorFilename
} from '../util'
Expand All @@ -32,14 +33,13 @@ suite('Tracked Explorer Tree Test Suite', () => {
const { join } = path

const disposable = Disposable.fn()

beforeEach(() => {
restore()
})

afterEach(() => {
disposable.dispose()
return commands.executeCommand('workbench.action.closeAllEditors')
return closeAllEditors()
})

describe('TrackedExplorerTree', () => {
Expand Down Expand Up @@ -179,7 +179,7 @@ suite('Tracked Explorer Tree Test Suite', () => {
expect(getActiveTextEditorFilename()).not.to.equal(__filename)
const uri = Uri.file(__filename)

const activeEditorChanged = activeTextEditorChangedEvent()
const activeEditorChanged = activeTextEditorChangedEvent(disposable)

await commands.executeCommand(
RegisteredCommands.TRACKED_EXPLORER_OPEN_FILE,
Expand All @@ -193,7 +193,7 @@ suite('Tracked Explorer Tree Test Suite', () => {
it('should be able to open a file to the side', async () => {
expect(getActiveTextEditorFilename()).not.to.equal(__filename)

const activeEditorChanged = activeTextEditorChangedEvent()
const activeEditorChanged = activeTextEditorChangedEvent(disposable)

await commands.executeCommand(
RegisteredCommands.TRACKED_EXPLORER_OPEN_TO_THE_SIDE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { stub, restore, spy } from 'sinon'
import { window, commands, Uri, MessageItem } from 'vscode'
import { Disposable } from '../../../extension'
import { CliExecutor } from '../../../cli/executor'
import { dvcDemoPath } from '../util'
import { closeAllEditors, dvcDemoPath } from '../util'
import {
RegisteredCliCommands,
RegisteredCommands
Expand All @@ -25,7 +25,7 @@ suite('Source Control Management Test Suite', () => {

afterEach(() => {
disposable.dispose()
return commands.executeCommand('workbench.action.closeAllEditors')
return closeAllEditors()
})

describe('SourceControlManagement', () => {
Expand Down
4 changes: 2 additions & 2 deletions extension/src/test/suite/repository/workspace.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { CliExecutor } from '../../../cli/executor'
import { RegisteredCliCommands } from '../../../commands/external'
import { WorkspaceRepositories } from '../../../repository/workspace'
import * as QuickPick from '../../../vscode/quickPick'
import { dvcDemoPath } from '../util'
import { closeAllEditors, dvcDemoPath } from '../util'
import { Repository } from '../../../repository'

suite('Workspace Repositories Test Suite', () => {
Expand All @@ -20,7 +20,7 @@ suite('Workspace Repositories Test Suite', () => {

afterEach(() => {
disposable.dispose()
return commands.executeCommand('workbench.action.closeAllEditors')
return closeAllEditors()
})

describe('dvc.commit', () => {
Expand Down
11 changes: 3 additions & 8 deletions extension/src/test/suite/status.test.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
import { afterEach, beforeEach, describe, it, suite } from 'mocha'
import { expect } from 'chai'
import { fake, restore, stub } from 'sinon'
import {
window,
commands,
workspace,
EventEmitter,
StatusBarItem
} from 'vscode'
import { window, workspace, EventEmitter, StatusBarItem } from 'vscode'
import { closeAllEditors } from './util'
import { Disposable } from '../../extension'
import { Status } from '../../status'
import { Cli, CliResult, CliStarted } from '../../cli'
Expand All @@ -26,7 +21,7 @@ suite('Status Test Suite', () => {
afterEach(async () => {
disposable.dispose()
await workspace.getConfiguration().update(dvcPathOption, undefined, false)
return commands.executeCommand('workbench.action.closeAllEditors')
return closeAllEditors()
})

describe('Status', () => {
Expand Down
17 changes: 13 additions & 4 deletions extension/src/test/suite/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
} from 'vscode'
import { Experiments } from '../../experiments'
import { Disposable, Disposer } from '../../extension'
import { definedAndNonEmpty } from '../../util/array'

export const dvcDemoPath = Uri.file(
resolve(__dirname, '..', '..', '..', '..', 'demo')
Expand Down Expand Up @@ -64,12 +65,20 @@ export const experimentsUpdatedEvent = (experiments: Experiments) =>
export const getFirstArgOfCall = (spy: SinonSpy, call: number) =>
spy.getCall(call).args[0]

export const activeTextEditorChangedEvent = (): Promise<
TextEditor | undefined
> =>
export const activeTextEditorChangedEvent = (
disposable: Disposer
): Promise<TextEditor | undefined> =>
new Promise(resolve =>
window.onDidChangeActiveTextEditor(editor => resolve(editor))
disposable.track(
window.onDidChangeActiveTextEditor(editor => resolve(editor))
)
)

export const getActiveTextEditorFilename = (): string | undefined =>
window.activeTextEditor?.document.fileName

export const closeAllEditors = async () => {
if (definedAndNonEmpty(window.visibleTextEditors)) {
await commands.executeCommand('workbench.action.closeAllEditors')
}
}
12 changes: 8 additions & 4 deletions extension/src/test/suite/vscode/recommend.test.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
import { join } from 'path'
import { beforeEach, describe, it, suite } from 'mocha'
import { afterEach, beforeEach, describe, it, suite } from 'mocha'
import { expect } from 'chai'
import { commands, MessageItem, Uri, window } from 'vscode'
import { MessageItem, Uri, window } from 'vscode'
import { restore, stub } from 'sinon'
import { dvcDemoPath } from '../util'
import { closeAllEditors, dvcDemoPath } from '../util'
import * as Extensions from '../../../vscode/extensions'

suite('Recommend Test Suite', () => {
beforeEach(() => {
restore()
})

afterEach(() => {
return closeAllEditors()
})

const openFileInEditor = (fileName: string) =>
window.showTextDocument(Uri.file(join(dvcDemoPath, fileName)))

Expand All @@ -36,7 +40,7 @@ suite('Recommend Test Suite', () => {
'should recommend to install the red hat yaml extension on the first call'
).to.be.calledOnce

await commands.executeCommand('workbench.action.closeAllEditors')
await closeAllEditors()

mockShowInformationMessage.resetHistory()

Expand Down
3 changes: 2 additions & 1 deletion extension/src/test/suite/vscode/walkthrough.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { afterEach, beforeEach, describe, it, suite } from 'mocha'
import { expect } from 'chai'
import { commands } from 'vscode'
import { restore, spy, stub } from 'sinon'
import { closeAllEditors } from '../util'
import { RegisteredCommands } from '../../../commands/external'
import { buildMockMemento } from '../../util'
import {
Expand All @@ -15,7 +16,7 @@ suite('Walkthrough Test Suite', () => {
})

afterEach(() => {
return commands.executeCommand('workbench.action.closeAllEditors')
return closeAllEditors()
})

describe('dvc.getStarted', () => {
Expand Down

0 comments on commit a01f684

Please sign in to comment.