Skip to content

Commit

Permalink
Update by name with tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jalal246 committed May 4, 2020
1 parent b177843 commit 09dd130
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
9 changes: 6 additions & 3 deletions src/getJsonByName.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,16 @@ function getJsonByName(...names) {
/**
* extract all then filters it.
*/
const { json, pkgInfo } = getJsonByPath();
const { json, pkgInfo, unfoundJson } = getJsonByPath();

if (names.length === 0) {
// msg(`Getting all packages`);

/**
* returns all.
*/
return {
json,
pkgInfo,
unfoundJson,
};
}

Expand Down Expand Up @@ -57,6 +59,7 @@ function getJsonByName(...names) {
return {
json: filteredJson,
pkgInfo: filteredPkgInfo,
unfoundJson,
};
}

Expand Down
9 changes: 6 additions & 3 deletions test/getJsonByName.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ const { getJsonByName } = require("../src");

describe("getJsonByName", () => {
it("Default: gets current path and json", () => {
const { json, pkgInfo } = getJsonByName();
const { json, pkgInfo, unfoundJson } = getJsonByName();

expect(json).to.be.an("Array");
expect(pkgInfo).to.be.an("Object");

expect(json.length).to.be.equal(1);
expect(unfoundJson.length).to.be.equal(0);

expect(json[0]).to.have.own.property("dependencies");

Expand All @@ -27,10 +28,11 @@ describe("getJsonByName", () => {
});

it("gets array of json with default path", () => {
const { json } = getJsonByName("get-info");
const { json, unfoundJson } = getJsonByName("get-info");

expect(json).to.be.an("Array");
expect(json.length).to.be.equal(1);
expect(unfoundJson.length).to.be.equal(0);

expect(json[0].name).to.be.equal("get-info");
});
Expand Down Expand Up @@ -61,9 +63,10 @@ describe("getJsonByName", () => {
// });

it("returns empty array when name is wrong", () => {
const { json } = getJsonByName("nothingTrue");
const { json, unfoundJson } = getJsonByName("nothingTrue");

expect(json).to.be.an("Array");
expect(json.length).to.be.equal(0);
expect(unfoundJson.length).to.be.equal(0);
});
});

0 comments on commit 09dd130

Please sign in to comment.