Skip to content

Commit

Permalink
Merge pull request #111 from augustocdias/fix_110
Browse files Browse the repository at this point in the history
Fix #110
  • Loading branch information
MarcelRobitaille authored Oct 2, 2024
2 parents 0d3ed6e + f0e81bd commit e3c6d9c
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Change Log

## [1.12.2] 2024-10-02

- Fix backwards compatibility of default values (#110)

## [1.12.1] 2024-10-02

- Fix errors with default values (#107)
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"displayName": "Tasks Shell Input",
"description": "Use shell commands as input for your tasks",
"icon": "icon.png",
"version": "1.12.1",
"version": "1.12.2",
"publisher": "augustocdias",
"repository": {
"url": "https://github.com/augustocdias/vscode-shell-command"
Expand Down
43 changes: 42 additions & 1 deletion src/lib/CommandHandler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,14 @@ describe("Simple cases", async () => {

test("Command as array of strings", async () => {
mockVscode.setMockData(mockData);
const args = {
command: ["cat", "${file}"],
useFirstResult: true,
taskId: "inputTest",
};

const handler = new CommandHandler(
{command: ["cat", "${file}"], useFirstResult: true},
args,
new UserInputContext(),
mockExtensionContext as unknown as vscode.ExtensionContext,
child_process,
Expand Down Expand Up @@ -250,6 +255,42 @@ test("stdio", async () => {
}
});

describe("Workspace state", () => {
test("It should return an array even if the saved value is a string", async () => {
const testDataPath = path.join(__dirname, "../test/testData/simple");

const tasksJson = await import(path.join(testDataPath, ".vscode/tasks.json"));
const mockData = (await import(path.join(testDataPath, "mockData.ts"))).default;
mockVscode.setMockData(mockData);
const input = tasksJson.inputs[0].args;

class CommandHandlerTestHelper extends CommandHandler {
public getDefault() {
return super.getDefault();
}
}

for (const workspaceStateGet of [
() => "test",
() => ["test"],
]) {
const handler = new CommandHandlerTestHelper(
{...input, rememberPrevious: true},
new UserInputContext(),
{
...mockExtensionContext,
workspaceState: {
get: workspaceStateGet,
},
} as unknown as vscode.ExtensionContext,
child_process,
);

expect(handler.getDefault()).toStrictEqual(["test"]);
}
});
});

describe("Errors", async () => {
test("It should trigger an error for an empty result", async () => {
const testDataPath = path.join(__dirname, "../test/testData/errors");
Expand Down
7 changes: 6 additions & 1 deletion src/lib/CommandHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,12 @@ export class CommandHandler {

protected getDefault() {
if (this.args.rememberPrevious && this.args.taskId) {
return this.context.workspaceState.get<string[]>(this.args.taskId, []);
const result = this.context.workspaceState
.get<string | string[]>(this.args.taskId, []);

// Backwards compatibilty for before multiselect when default was
// saved as string not array.
return (typeof result === "string") ? [result] : result;
}

return [];
Expand Down
1 change: 1 addition & 0 deletions src/test/testData/simple/.vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"type": "command",
"command": "shellCommand.execute",
"args": {
"taskId": "inputTest",
"command": "cat ${file}",
"multiselect": true,
"cwd": "${workspaceFolder}",
Expand Down
1 change: 1 addition & 0 deletions src/test/testData/simple/mockData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export default {
"type": "command",
"command": "shellCommand.execute",
"args": {
"taskId": "inputTest",
"command": "cat ${file}",
"cwd": "${workspaceFolder}",
"env": {
Expand Down

0 comments on commit e3c6d9c

Please sign in to comment.