From ab828c8857d7beac4c1a1e8c10a2dab9f829552b Mon Sep 17 00:00:00 2001 From: Roman Nikitenko Date: Tue, 2 Jul 2019 16:32:32 +0300 Subject: [PATCH] Fix task converting for custom type Signed-off-by: Roman Nikitenko --- .../src/plugin/type-converters.spec.ts | 72 +++++++++++++++---- .../plugin-ext/src/plugin/type-converters.ts | 3 +- 2 files changed, 60 insertions(+), 15 deletions(-) diff --git a/packages/plugin-ext/src/plugin/type-converters.spec.ts b/packages/plugin-ext/src/plugin/type-converters.spec.ts index 981e094a9ac86..e6d726e18df99 100644 --- a/packages/plugin-ext/src/plugin/type-converters.spec.ts +++ b/packages/plugin-ext/src/plugin/type-converters.spec.ts @@ -169,16 +169,18 @@ describe('Type converters:', () => { }); describe('convert tasks:', () => { - const type = 'shell'; + const customType = 'custom'; + const shellType = 'shell'; const label = 'yarn build'; const source = 'source'; const command = 'yarn'; + const commandLine = 'yarn run build'; const args = ['run', 'build']; const cwd = '/projects/theia'; const additionalProperty = 'some property'; const shellTaskDto: ProcessTaskDto = { - type, + type: shellType, label, source, scope: undefined, @@ -192,7 +194,7 @@ describe('Type converters:', () => { name: label, source, definition: { - type, + type: shellType, additionalProperty }, execution: { @@ -204,24 +206,39 @@ describe('Type converters:', () => { } }; - const taskDtoWithCommandLine: ProcessTaskDto = { - type, - label, + const pluginTaskWithCommandLine: theia.Task = { + name: label, source, - scope: undefined, - command, - args, - options: { cwd } + definition: { + type: shellType, + additionalProperty + }, + execution: { + commandLine, + options: { + cwd + } + } }; - const pluginTaskWithCommandLine: theia.Task = { + const customTaskDto: ProcessTaskDto = { ...shellTaskDto, type: customType }; + + const customPluginTask: theia.Task = { + ...shellPluginTask, definition: { + type: customType, + additionalProperty + } + }; + + const customPluginTaskWithCommandLine: theia.Task = { name: label, source, definition: { - type + type: customType, + additionalProperty }, execution: { - commandLine: 'yarn run build', + commandLine, options: { cwd } @@ -252,7 +269,34 @@ describe('Type converters:', () => { // then assert.notEqual(result, undefined); - assert.deepEqual(result, taskDtoWithCommandLine); + assert.deepEqual(result, shellTaskDto); + }); + + it('should convert task with custom type to dto', () => { + // when + const result: TaskDto | undefined = Converter.fromTask(customPluginTask); + + // then + assert.notEqual(result, undefined); + assert.deepEqual(result, customTaskDto); + }); + + it('should convert task with custom type from dto', () => { + // when + const result: theia.Task = Converter.toTask(customTaskDto); + + // then + assert.notEqual(result, undefined); + assert.deepEqual(result, customPluginTask); + }); + + it('should convert to task dto from custom task with commandline', () => { + // when + const result: TaskDto | undefined = Converter.fromTask(customPluginTaskWithCommandLine); + + // then + assert.notEqual(result, undefined); + assert.deepEqual(result, customTaskDto); }); }); diff --git a/packages/plugin-ext/src/plugin/type-converters.ts b/packages/plugin-ext/src/plugin/type-converters.ts index 22025f62caf41..273bd23601057 100644 --- a/packages/plugin-ext/src/plugin/type-converters.ts +++ b/packages/plugin-ext/src/plugin/type-converters.ts @@ -651,7 +651,8 @@ export function toTask(taskDto: TaskDto): theia.Task { result.execution = getProcessExecution(taskDto as ProcessTaskDto); } - if (taskType === 'shell') { + const execution = { command, args, options }; + if (taskType === 'shell' || types.ShellExecution.is(execution)) { result.execution = getShellExecution(taskDto as ProcessTaskDto); }