Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix (local) intermittent test failures #1909

Merged
merged 2 commits into from
Jun 16, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 36 additions & 40 deletions extension/src/test/suite/experiments/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1205,65 +1205,61 @@ suite('Experiments Test Suite', () => {
)
})

it('should set the appropriate context value when a params file is opened', async () => {
const { experiments } = buildExperiments(disposable)
await experiments.isReady()

it('should set the appropriate context value when a params file is open in the active editor/closed', async () => {
const paramsFile = Uri.file(join(dvcDemoPath, 'params.yaml'))
await window.showTextDocument(paramsFile)

const setContextValueSpy = spy(VscodeContext, 'setContextValue')
const mockContext: { [key: string]: unknown } = {
'dvc.params.fileActive': false
}

const activeEditorUpdated = getActiveEditorUpdatedEvent()
const mockSetContextValue = stub(VscodeContext, 'setContextValue')
mockSetContextValue.callsFake((key: string, value: unknown) => {
mockContext[key] = value
return Promise.resolve(undefined)
})

await window.showTextDocument(paramsFile)
await activeEditorUpdated
const { experiments } = buildExperiments(disposable)
await experiments.isReady()

const activeEditorClosed = getActiveEditorUpdatedEvent()
expect(
mockContext['dvc.params.fileActive'],
'should set dvc.params.fileActive to true when a params file is open and the extension starts'
).to.be.true

expect(setContextValueSpy).to.be.calledOnce
expect(setContextValueSpy).to.be.calledWithExactly(
'dvc.params.fileActive',
true
)
mockSetContextValue.resetHistory()

setContextValueSpy.resetHistory()
const startupEditorClosed = getActiveEditorUpdatedEvent()

await closeAllEditors()
await activeEditorClosed
await startupEditorClosed

expect(setContextValueSpy).to.be.calledOnce
expect(setContextValueSpy).to.be.calledWithExactly(
'dvc.params.fileActive',
false
)
})
expect(
mockContext['dvc.params.fileActive'],
'should set dvc.params.fileActive to false when the params file in the active editor is closed'
).to.be.false

it('should set the appropriate context value when a params file is open and the extension starts', async () => {
const paramsFile = Uri.file(join(dvcDemoPath, 'params.yaml'))
await window.showTextDocument(paramsFile)
mockSetContextValue.resetHistory()

const setContextValueSpy = spy(VscodeContext, 'setContextValue')

const { experiments } = buildExperiments(disposable)
await experiments.isReady()
const activeEditorUpdated = getActiveEditorUpdatedEvent()

expect(setContextValueSpy).to.be.calledOnce
expect(setContextValueSpy).to.be.calledWithExactly(
'dvc.params.fileActive',
true
)
await window.showTextDocument(paramsFile)
await activeEditorUpdated

setContextValueSpy.resetHistory()
const activeEditorClosed = getActiveEditorUpdatedEvent()

expect(
mockContext['dvc.params.fileActive'],
'should set dvc.params.fileActive to true when a params file is in the active editor'
).to.be.true

await closeAllEditors()
await activeEditorClosed

expect(setContextValueSpy).to.be.calledOnce
expect(setContextValueSpy).to.be.calledWithExactly(
'dvc.params.fileActive',
false
)
expect(
mockContext['dvc.params.fileActive'],
'should set dvc.params.fileActive to false when the params file in the active editor is closed again'
).to.be.false
})

it('should not set a context value when a non-params file is open and the extension starts', async () => {
Expand Down