improve tests (#2923)

use es6 syntax in all tests, split weather tests, remove callbacks
This commit is contained in:
Karsten Hassel
2022-10-04 10:15:24 +02:00
committed by GitHub
parent 7694d6fa86
commit f04d578704
41 changed files with 751 additions and 840 deletions

View File

@@ -14,7 +14,7 @@ jest.mock("logger", () => ({
info: jest.fn()
}));
describe("Updatenotification", function () {
describe("Updatenotification", () => {
const execMock = jest.fn();
let gitHelper;
@@ -30,7 +30,7 @@ describe("Updatenotification", function () {
let gitFetchErr;
let gitRevListErr;
beforeAll(async function () {
beforeAll(async () => {
const { promisify } = require("util");
promisify.mockReturnValue(execMock);
@@ -38,7 +38,7 @@ describe("Updatenotification", function () {
gitHelper = new GitHelper();
});
beforeEach(function () {
beforeEach(() => {
gitRemoteOut = "";
gitRevParseOut = "";
gitStatusOut = "";
@@ -50,7 +50,7 @@ describe("Updatenotification", function () {
gitFetchErr = "";
gitRevListErr = "";
execMock.mockImplementation(function (command) {
execMock.mockImplementation((command) => {
if (command.includes("git remote -v")) {
return { stdout: gitRemoteOut, stderr: gitRemoteErr };
} else if (command.includes("git rev-parse HEAD")) {
@@ -65,7 +65,7 @@ describe("Updatenotification", function () {
});
});
afterEach(async function () {
afterEach(async () => {
gitHelper.gitRepos = [];
jest.clearAllMocks();
@@ -74,7 +74,7 @@ describe("Updatenotification", function () {
describe("default", () => {
const moduleName = "default";
beforeEach(async function () {
beforeEach(async () => {
gitRemoteOut = "origin\tgit@github.com:MichMich/MagicMirror.git (fetch)\norigin\tgit@github.com:MichMich/MagicMirror.git (push)\n";
gitRevParseOut = "332e429a41f1a2339afd4f0ae96dd125da6beada";
gitStatusOut = "## develop...origin/develop\n M tests/unit/functions/updatenotification_spec.js\n";
@@ -84,13 +84,13 @@ describe("Updatenotification", function () {
await gitHelper.add(moduleName);
});
it("returns status information", async function () {
it("returns status information", async () => {
const repos = await gitHelper.getRepos();
expect(repos[0]).toMatchSnapshot();
expect(execMock).toHaveBeenCalledTimes(5);
});
it("returns status information early if isBehindInStatus", async function () {
it("returns status information early if isBehindInStatus", async () => {
gitStatusOut = "## develop...origin/develop [behind 5]";
const repos = await gitHelper.getRepos();
@@ -98,7 +98,7 @@ describe("Updatenotification", function () {
expect(execMock).toHaveBeenCalledTimes(3);
});
it("excludes repo if status can't be retrieved", async function () {
it("excludes repo if status can't be retrieved", async () => {
const errorMessage = "Failed to retrieve status";
execMock.mockRejectedValueOnce(errorMessage);
@@ -109,7 +109,7 @@ describe("Updatenotification", function () {
expect(error).toHaveBeenCalledWith(`Failed to retrieve repo info for ${moduleName}: Failed to retrieve status`);
});
it("excludes repo if refs don't match regex", async function () {
it("excludes repo if refs don't match regex", async () => {
gitFetchErr = "";
const repos = await gitHelper.getRepos();
@@ -120,7 +120,7 @@ describe("Updatenotification", function () {
describe("custom module", () => {
const moduleName = "MMM-Fuel";
beforeEach(async function () {
beforeEach(async () => {
gitRemoteOut = `origin\thttps://github.com/fewieden/${moduleName}.git (fetch)\norigin\thttps://github.com/fewieden/${moduleName}.git (push)\n`;
gitRevParseOut = "9d8310163da94441073a93cead711ba43e8888d0";
gitStatusOut = "## master...origin/master";
@@ -130,7 +130,7 @@ describe("Updatenotification", function () {
await gitHelper.add(moduleName);
});
it("returns status information without hash", async function () {
it("returns status information without hash", async () => {
const repos = await gitHelper.getRepos();
expect(repos[0]).toMatchSnapshot();
expect(execMock).toHaveBeenCalledTimes(4);