From 241d924d3a191ead360176844b002c1614c32c2b Mon Sep 17 00:00:00 2001 From: Roman Nikitenko Date: Wed, 26 Jun 2019 16:01:24 +0300 Subject: [PATCH] Fix task converting for custom type Signed-off-by: Roman Nikitenko --- .../src/plugin/type-converters.spec.ts | 56 +++++++++++++++++-- .../plugin-ext/src/plugin/type-converters.ts | 3 +- 2 files changed, 53 insertions(+), 6 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..d7bc30f851fba 100644 --- a/packages/plugin-ext/src/plugin/type-converters.spec.ts +++ b/packages/plugin-ext/src/plugin/type-converters.spec.ts @@ -169,7 +169,8 @@ 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'; @@ -178,7 +179,7 @@ describe('Type converters:', () => { const additionalProperty = 'some property'; const shellTaskDto: ProcessTaskDto = { - type, + type: shellType, label, source, scope: undefined, @@ -192,7 +193,7 @@ describe('Type converters:', () => { name: label, source, definition: { - type, + type: shellType, additionalProperty }, execution: { @@ -205,7 +206,7 @@ describe('Type converters:', () => { }; const taskDtoWithCommandLine: ProcessTaskDto = { - type, + type: shellType, label, source, scope: undefined, @@ -218,7 +219,7 @@ describe('Type converters:', () => { name: label, source, definition: { - type + type: shellType }, execution: { commandLine: 'yarn run build', @@ -228,6 +229,33 @@ describe('Type converters:', () => { } }; + const customTaskDto: ProcessTaskDto = { + type: customType, + label, + source, + scope: undefined, + command, + args, + options: { cwd }, + additionalProperty + }; + + const customPluginTask: theia.Task = { + name: label, + source, + definition: { + type: customType, + additionalProperty + }, + execution: { + command, + args, + options: { + cwd + } + } + }; + it('should convert to task dto', () => { // when const result: TaskDto | undefined = Converter.fromTask(shellPluginTask); @@ -254,6 +282,24 @@ describe('Type converters:', () => { assert.notEqual(result, undefined); assert.deepEqual(result, taskDtoWithCommandLine); }); + + 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); + }); }); describe('Webview Panel Show Options:', () => { 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); }