|
1 | 1 | import { join } from 'path' |
2 | 2 | import { EventEmitter } from 'vscode' |
3 | 3 | import { Disposable, Disposer } from '@hediet/std/disposable' |
4 | | -import { Flag, GcPreserveFlag } from './constants' |
| 4 | +import { Flag, GcPreserveFlag, UNEXPECTED_ERROR_CODE } from './constants' |
5 | 5 | import { DvcExecutor } from './executor' |
6 | 6 | import { CliResult, CliStarted } from '..' |
7 | 7 | import { createProcess } from '../../process/execution' |
8 | 8 | import { flushPromises, getMockedProcess } from '../../test/util/jest' |
9 | 9 | import { getProcessEnv } from '../../env' |
10 | 10 | import { Config } from '../../config' |
11 | 11 | import { ContextKey, setContextValue } from '../../vscode/context' |
| 12 | +import { MaybeConsoleError } from '../error' |
12 | 13 |
|
13 | 14 | jest.mock('vscode') |
14 | 15 | jest.mock('@hediet/std/disposable') |
@@ -92,6 +93,37 @@ describe('CliExecutor', () => { |
92 | 93 | executable: 'dvc' |
93 | 94 | }) |
94 | 95 | }) |
| 96 | + |
| 97 | + it('should set the correct context value if the command fails', async () => { |
| 98 | + const cwd = __dirname |
| 99 | + const relPath = join('data', 'MNIST', 'raw') |
| 100 | + const unexpectedError = new Error( |
| 101 | + 'unexpected error - something something' |
| 102 | + ) |
| 103 | + const unexpectedStderr = 'This is very unexpected' |
| 104 | + ;(unexpectedError as MaybeConsoleError).exitCode = UNEXPECTED_ERROR_CODE |
| 105 | + ;(unexpectedError as MaybeConsoleError).stderr = unexpectedStderr |
| 106 | + mockedCreateProcess.mockImplementationOnce(() => { |
| 107 | + throw unexpectedError |
| 108 | + }) |
| 109 | + |
| 110 | + let error |
| 111 | + |
| 112 | + try { |
| 113 | + await dvcExecutor.add(cwd, relPath) |
| 114 | + } catch (thrownError) { |
| 115 | + error = thrownError |
| 116 | + } |
| 117 | + |
| 118 | + expect((error as MaybeConsoleError).stderr).toStrictEqual( |
| 119 | + unexpectedStderr |
| 120 | + ) |
| 121 | + |
| 122 | + expect(mockedSetContextValue).toHaveBeenLastCalledWith( |
| 123 | + ContextKey.SCM_RUNNING, |
| 124 | + false |
| 125 | + ) |
| 126 | + }) |
95 | 127 | }) |
96 | 128 |
|
97 | 129 | describe('checkout', () => { |
|
0 commit comments