Skip to content

Commit

Permalink
Fix task converting for custom type
Browse files Browse the repository at this point in the history
Signed-off-by: Roman Nikitenko <rnikiten@redhat.com>
  • Loading branch information
RomanNikitenko committed Jun 26, 2019
1 parent 2e8cd6f commit 241d924
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 6 deletions.
56 changes: 51 additions & 5 deletions packages/plugin-ext/src/plugin/type-converters.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -178,7 +179,7 @@ describe('Type converters:', () => {
const additionalProperty = 'some property';

const shellTaskDto: ProcessTaskDto = {
type,
type: shellType,
label,
source,
scope: undefined,
Expand All @@ -192,7 +193,7 @@ describe('Type converters:', () => {
name: label,
source,
definition: {
type,
type: shellType,
additionalProperty
},
execution: {
Expand All @@ -205,7 +206,7 @@ describe('Type converters:', () => {
};

const taskDtoWithCommandLine: ProcessTaskDto = {
type,
type: shellType,
label,
source,
scope: undefined,
Expand All @@ -218,7 +219,7 @@ describe('Type converters:', () => {
name: label,
source,
definition: {
type
type: shellType
},
execution: {
commandLine: 'yarn run build',
Expand All @@ -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);
Expand All @@ -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:', () => {
Expand Down
3 changes: 2 additions & 1 deletion packages/plugin-ext/src/plugin/type-converters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down

0 comments on commit 241d924

Please sign in to comment.