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 Jul 4, 2019
1 parent 150c158 commit ab828c8
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 15 deletions.
72 changes: 58 additions & 14 deletions packages/plugin-ext/src/plugin/type-converters.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -192,7 +194,7 @@ describe('Type converters:', () => {
name: label,
source,
definition: {
type,
type: shellType,
additionalProperty
},
execution: {
Expand All @@ -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
}
Expand Down Expand Up @@ -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);
});
});

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 ab828c8

Please sign in to comment.