mirror of
https://github.com/MichMich/MagicMirror.git
synced 2025-06-27 11:50:00 +00:00
added tests for updatenotification
This commit is contained in:
parent
c3fc745c7e
commit
277055f44e
@ -11,8 +11,9 @@ _This release is scheduled to be released on 2021-10-01._
|
|||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|
||||||
- Added showTime parameter to clock module for enabling/disabling time display in analog clock
|
- Added showTime parameter to clock module for enabling/disabling time display in analog clock.
|
||||||
- Added custom electron switches from user config (`config.electronSwitches`)
|
- Added custom electron switches from user config (`config.electronSwitches`).
|
||||||
|
- Added unit tests for updatenotification module.
|
||||||
|
|
||||||
### Updated
|
### Updated
|
||||||
|
|
||||||
|
@ -75,7 +75,12 @@ class gitHelper {
|
|||||||
}
|
}
|
||||||
gitInfo.hash = res.stdout;
|
gitInfo.hash = res.stdout;
|
||||||
}
|
}
|
||||||
res = await this.execShell("cd " + repo.folder + " && git status -sb");
|
if (repo.res) {
|
||||||
|
// mocking
|
||||||
|
res = repo.res;
|
||||||
|
} else {
|
||||||
|
res = await this.execShell("cd " + repo.folder + " && git status -sb");
|
||||||
|
}
|
||||||
if (res.stderr) {
|
if (res.stderr) {
|
||||||
Log.error("Failed to get git status for " + repo.module + ": " + res.stderr);
|
Log.error("Failed to get git status for " + repo.module + ": " + res.stderr);
|
||||||
// exit without git status info
|
// exit without git status info
|
||||||
@ -105,14 +110,26 @@ class gitHelper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async getRepoInfo(repo) {
|
async getRepoInfo(repo) {
|
||||||
let gitInfo = await this.getStatusInfo(repo);
|
let gitInfo;
|
||||||
|
if (repo.gitInfo) {
|
||||||
|
// mocking
|
||||||
|
gitInfo = repo.gitInfo;
|
||||||
|
} else {
|
||||||
|
gitInfo = await this.getStatusInfo(repo);
|
||||||
|
}
|
||||||
if (!gitInfo) {
|
if (!gitInfo) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (gitInfo.isBehindInStatus) {
|
if (gitInfo.isBehindInStatus) {
|
||||||
return gitInfo;
|
return gitInfo;
|
||||||
}
|
}
|
||||||
let res = await this.execShell("cd " + repo.folder + " && git fetch --dry-run");
|
let res;
|
||||||
|
if (repo.res) {
|
||||||
|
// mocking
|
||||||
|
res = repo.res;
|
||||||
|
} else {
|
||||||
|
res = await this.execShell("cd " + repo.folder + " && git fetch --dry-run");
|
||||||
|
}
|
||||||
// example output:
|
// example output:
|
||||||
// From https://github.com/MichMich/MagicMirror
|
// From https://github.com/MichMich/MagicMirror
|
||||||
// e40ddd4..06389e3 develop -> origin/develop
|
// e40ddd4..06389e3 develop -> origin/develop
|
||||||
@ -123,9 +140,13 @@ class gitHelper {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// get behind with refs
|
// get behind with refs
|
||||||
res = await this.execShell("cd " + repo.folder + " && git rev-list --ancestry-path --count " + matches[0]);
|
try {
|
||||||
gitInfo.behind = parseInt(res.stdout);
|
res = await this.execShell("cd " + repo.folder + " && git rev-list --ancestry-path --count " + matches[0]);
|
||||||
return gitInfo;
|
gitInfo.behind = parseInt(res.stdout);
|
||||||
|
return gitInfo;
|
||||||
|
} catch (err) {
|
||||||
|
Log.error("Failed to get git revisions for " + repo.module + ": " + err);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async getStatus() {
|
async getStatus() {
|
||||||
|
@ -3,6 +3,78 @@ const git_Helper = require("../../../modules/default/updatenotification/git_help
|
|||||||
const gitHelper = new git_Helper.gitHelper();
|
const gitHelper = new git_Helper.gitHelper();
|
||||||
gitHelper.add("default");
|
gitHelper.add("default");
|
||||||
|
|
||||||
|
const test1 = {
|
||||||
|
module: "test1",
|
||||||
|
folder: "",
|
||||||
|
res: {
|
||||||
|
stdout: "## master...origin/master [behind 8]",
|
||||||
|
stderr: ""
|
||||||
|
},
|
||||||
|
gitInfo: {
|
||||||
|
module: "default",
|
||||||
|
// commits behind:
|
||||||
|
behind: 0,
|
||||||
|
// branch name:
|
||||||
|
current: "develop",
|
||||||
|
// current hash:
|
||||||
|
hash: "",
|
||||||
|
// remote branch:
|
||||||
|
tracking: "",
|
||||||
|
isBehindInStatus: false
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const test2 = {
|
||||||
|
module: "test2",
|
||||||
|
folder: "",
|
||||||
|
res: {
|
||||||
|
stdout: "## develop...origin/develop",
|
||||||
|
stderr: ""
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const test3 = {
|
||||||
|
module: "test3",
|
||||||
|
folder: "",
|
||||||
|
res: {
|
||||||
|
stdout: "",
|
||||||
|
stderr: "error"
|
||||||
|
},
|
||||||
|
gitInfo: {
|
||||||
|
module: "default",
|
||||||
|
// commits behind:
|
||||||
|
behind: 2,
|
||||||
|
// branch name:
|
||||||
|
current: "develop",
|
||||||
|
// current hash:
|
||||||
|
hash: "",
|
||||||
|
// remote branch:
|
||||||
|
tracking: "",
|
||||||
|
isBehindInStatus: true
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const test4 = {
|
||||||
|
module: "default",
|
||||||
|
folder: path.join(__dirname, "../../.."),
|
||||||
|
res: {
|
||||||
|
stdout: "",
|
||||||
|
stderr: " e40ddd4..06389e3 develop -> origin/develop"
|
||||||
|
},
|
||||||
|
gitInfo: {
|
||||||
|
module: "default",
|
||||||
|
// commits behind:
|
||||||
|
behind: 0,
|
||||||
|
// branch name:
|
||||||
|
current: "develop",
|
||||||
|
// current hash:
|
||||||
|
hash: "",
|
||||||
|
// remote branch:
|
||||||
|
tracking: "",
|
||||||
|
isBehindInStatus: false
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
describe("Updatenotification", function () {
|
describe("Updatenotification", function () {
|
||||||
it("should return valid output for git status", async function () {
|
it("should return valid output for git status", async function () {
|
||||||
const arr = await gitHelper.getStatus();
|
const arr = await gitHelper.getStatus();
|
||||||
@ -11,4 +83,44 @@ describe("Updatenotification", function () {
|
|||||||
expect(gitInfo.current).not.toBe("");
|
expect(gitInfo.current).not.toBe("");
|
||||||
expect(gitInfo.hash).not.toBe("");
|
expect(gitInfo.hash).not.toBe("");
|
||||||
}, 15000);
|
}, 15000);
|
||||||
|
|
||||||
|
it("should return behind=8 for test1", async function () {
|
||||||
|
const gitInfo = await gitHelper.getStatusInfo(test1);
|
||||||
|
expect(gitInfo.behind).toBe(8);
|
||||||
|
expect(gitInfo.isBehindInStatus).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should return behind=0 for test2", async function () {
|
||||||
|
const gitInfo = await gitHelper.getStatusInfo(test2);
|
||||||
|
expect(gitInfo.behind).toBe(0);
|
||||||
|
expect(gitInfo.isBehindInStatus).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should return empty status object for test3", async function () {
|
||||||
|
const gitInfo = await gitHelper.getStatusInfo(test3);
|
||||||
|
expect(gitInfo).toBe(undefined);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should return empty repo object for test2", async function () {
|
||||||
|
// no gitInfo provided in res, so returns undefined
|
||||||
|
const gitInfo = await gitHelper.getRepoInfo(test2);
|
||||||
|
expect(gitInfo).toBe(undefined);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should return empty repo object for test1", async function () {
|
||||||
|
// no regex match for refs in empty string, so returns undefined
|
||||||
|
const gitInfo = await gitHelper.getRepoInfo(test1);
|
||||||
|
expect(gitInfo).toBe(undefined);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should return empty repo object for test4", async function () {
|
||||||
|
// git ref list throws error, so returns undefined
|
||||||
|
const gitInfo = await gitHelper.getRepoInfo(test4);
|
||||||
|
expect(gitInfo).toBe(undefined);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should return behind=2 for test3", async function () {
|
||||||
|
const gitInfo = await gitHelper.getRepoInfo(test3);
|
||||||
|
expect(gitInfo.behind).toBe(2);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user