Skip to content

Commit

Permalink
add integration tests for branch and share as branch
Browse files Browse the repository at this point in the history
  • Loading branch information
mattseddon committed Aug 19, 2022
1 parent 4fd1f60 commit 3ace691
Show file tree
Hide file tree
Showing 2 changed files with 119 additions and 11 deletions.
18 changes: 9 additions & 9 deletions extension/src/experiments/commands/register.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,15 +162,6 @@ const registerExperimentInputCommands = (
)
)

internalCommands.registerExternalCliCommand(
RegisteredCliCommands.EXPERIMENT_SHARE_AS_BRANCH,
() =>
experiments.getCwdExpNameAndInputThenRun(
getShareExperimentAsBranchCommand(experiments),
Title.ENTER_BRANCH_NAME
)
)

internalCommands.registerExternalCliCommand(
RegisteredCliCommands.EXPERIMENT_VIEW_BRANCH,
({ dvcRoot, id }: ExperimentDetails) =>
Expand All @@ -182,6 +173,15 @@ const registerExperimentInputCommands = (
)
)

internalCommands.registerExternalCliCommand(
RegisteredCliCommands.EXPERIMENT_SHARE_AS_BRANCH,
() =>
experiments.getCwdExpNameAndInputThenRun(
getShareExperimentAsBranchCommand(experiments),
Title.ENTER_BRANCH_NAME
)
)

internalCommands.registerExternalCliCommand(
RegisteredCliCommands.EXPERIMENT_VIEW_SHARE_AS_BRANCH,
({ dvcRoot, id }: ExperimentDetails) =>
Expand Down
112 changes: 110 additions & 2 deletions extension/src/test/suite/experiments/workspace.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { WorkspaceExperiments } from '../../../experiments/workspace'
import { Experiments } from '../../../experiments'
import * as QuickPick from '../../../vscode/quickPick'
import { CliExecutor } from '../../../cli/executor'
import { closeAllEditors, mockDuration } from '../util'
import { closeAllEditors, getInputBoxEvent, mockDuration } from '../util'
import { dvcDemoPath } from '../../util'
import { RegisteredCliCommands } from '../../../commands/external'
import * as Telemetry from '../../../telemetry'
Expand All @@ -26,8 +26,9 @@ import { WEBVIEW_TEST_TIMEOUT } from '../timeouts'
import { Title } from '../../../vscode/title'
import { join } from '../../util/path'
import { AvailableCommands } from '../../../commands/internal'
import * as Git from '../../../git'

suite('Workspace Experiments Test Suite', () => {
suite.only('Workspace Experiments Test Suite', () => {
const disposable = Disposable.fn()

beforeEach(() => {
Expand Down Expand Up @@ -564,6 +565,113 @@ suite('Workspace Experiments Test Suite', () => {
})
})

describe('dvc.branchExperiment', () => {
it('should be able to create a branch from an experiment', async () => {
const { experiments } = buildExperiments(disposable)
await experiments.isReady()

const testExperiment = 'exp-83425'
const mockBranch = 'brunch'
const inputEvent = getInputBoxEvent(mockBranch)

stub(window, 'showQuickPick').resolves({
value: { id: testExperiment, name: testExperiment }
} as QuickPickItemWithValue<{ id: string; name: string }>)

const mockExperimentBranch = stub(
CliExecutor.prototype,
'experimentBranch'
).resolves(
`Git branch '${mockBranch}' has been created from experiment '${testExperiment}'.
To switch to the new branch run:
git checkout ${mockBranch}`
)

stub(
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(WorkspaceExperiments as any).prototype,
'getOnlyOrPickProject'
).returns(dvcDemoPath)

stub(WorkspaceExperiments.prototype, 'getRepository').returns(experiments)

await commands.executeCommand(RegisteredCliCommands.EXPERIMENT_BRANCH)

await inputEvent
expect(mockExperimentBranch).to.be.calledWithExactly(
dvcDemoPath,
testExperiment,
mockBranch
)
})
})

describe('dvc.shareExperimentAsBranch', () => {
it('should be able to share an experiment as a branch', async () => {
const { experiments } = buildExperiments(disposable)
await experiments.isReady()

const testExperiment = 'exp-83425'
const mockBranch = 'more-brunch'
const inputEvent = getInputBoxEvent(mockBranch)

stub(window, 'showQuickPick').resolves({
value: { id: testExperiment, name: testExperiment }
} as QuickPickItemWithValue<{ id: string; name: string }>)

const mockExperimentBranch = stub(
CliExecutor.prototype,
'experimentBranch'
).resolves(
`Git branch '${mockBranch}' has been created from experiment '${testExperiment}'.
To switch to the new branch run:
git checkout ${mockBranch}`
)
const mockExperimentApply = stub(
CliExecutor.prototype,
'experimentApply'
).resolves(
`Changes for experiment '${testExperiment}' have been applied to your current workspace.`
)
const mockPush = stub(CliExecutor.prototype, 'push').resolves(
'10 files updated.'
)
const mockGitPush = stub(Git, 'gitPushBranch')
const branchPushedToRemote = new Promise(resolve =>
mockGitPush.callsFake(() => {
resolve(undefined)
return Promise.resolve(`${mockBranch} pushed to remote`)
})
)

stub(
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(WorkspaceExperiments as any).prototype,
'getOnlyOrPickProject'
).returns(dvcDemoPath)

stub(WorkspaceExperiments.prototype, 'getRepository').returns(experiments)

await commands.executeCommand(
RegisteredCliCommands.EXPERIMENT_SHARE_AS_BRANCH
)

await inputEvent
await branchPushedToRemote
expect(mockExperimentBranch).to.be.calledWithExactly(
dvcDemoPath,
testExperiment,
mockBranch
)
expect(mockExperimentApply).to.be.calledWithExactly(
dvcDemoPath,
testExperiment
)
expect(mockPush).to.be.calledWithExactly(dvcDemoPath)
expect(mockGitPush).to.be.calledWithExactly(dvcDemoPath, mockBranch)
})
})

describe('dvc.removeExperiment', () => {
it('should ask the user to pick an experiment and then remove that experiment from the workspace', async () => {
const mockExperiment = 'exp-to-remove'
Expand Down

0 comments on commit 3ace691

Please sign in to comment.