Skip to content

Commit

Permalink
fix: forEach on all of the actions (#36)
Browse files Browse the repository at this point in the history
* fix: forEach on all the actions

* fix: the versions

* fix: test

* fix: syntax

* feat: adding test to ActionsController.loadActions
  • Loading branch information
NetaMolcho authored Apr 4, 2021
1 parent df792ef commit ebfc73f
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 3 deletions.
2 changes: 1 addition & 1 deletion sample-action-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"package": "vsce package ."
},
"devDependencies": {
"@sap-devx/app-studio-toolkit-types": "0.0.5",
"@sap-devx/app-studio-toolkit-types": "0.0.4",
"@types/vscode": "^1.40.0",
"typescript": "^3.9.7",
"vsce": "^1.69.0",
Expand Down
4 changes: 3 additions & 1 deletion src/actions/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ export class ActionsController {
public static loadActions() {
vscode.extensions.all.forEach((extension) => {
if (extension?.packageJSON?.BASContributes?.actions) {
this.actions.push(extension.packageJSON.BASContributes.actions);
(extension.packageJSON.BASContributes.actions as IAction[]).forEach((action) => {
this.actions.push(action);
});
}
});
}
Expand Down
22 changes: 22 additions & 0 deletions tests/api.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import * as _ from "lodash";
import * as sinon from "sinon";
import { IAction, ActionType } from "../src/actions/interfaces";
import { ActionsController } from '../src/actions/controller';
import * as vscode from "vscode";

use(chaiAsPromised);
const extensions = { getExtension: () => {} };
Expand All @@ -13,6 +14,7 @@ const testVscode = {
};

mockVscode(testVscode, "src/api.ts");

import { bas } from "../src/api";

describe("api unit test", () => {
Expand Down Expand Up @@ -77,6 +79,26 @@ describe("api unit test", () => {

});

it("loadActions", async () => {
const action: IAction = {
"id" : "abc123",
"actionType" : ActionType.Command,
}
const allExtensioms = [{
packageJSON: {
"BASContributes": {
"actions": [action]
},
}
}]
_.set(vscode, "extensions.all", allExtensioms);

ActionsController.loadActions();
const result = await bas.getAction("abc123");
expect(result.id).to.be.equal(action.id);
expect(result.actionType).to.be.equal(action.actionType);
});

it("inactive extension is waited for", async () => {
const extension = {
isActive: false,
Expand Down
2 changes: 1 addition & 1 deletion tests/extension.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const testVscode = {
extensions: {
all: [{
packageJSON: {
BAScontributes: {
BASContributes: {
actions: [{
id : "abc123",
actionType : "command",
Expand Down

0 comments on commit ebfc73f

Please sign in to comment.