mirror of
https://github.com/MichMich/MagicMirror.git
synced 2025-12-12 09:52:37 +00:00
[tests] migrate from jest to vitest (#3940)
This is a big change, but I think it's a good move, as `vitest` is much more modern than `jest`. I'm excited about the UI watch feature (run `npm run test:ui`), for example - it's really helpful and saves time when debugging tests. I had to adjust a few tests because they had time related issues, but basically we are now testing the same things - even a bit better and less flaky (I hope). What do you think?
This commit is contained in:
committed by
GitHub
parent
b542f33a0a
commit
462abf7027
@@ -12,7 +12,7 @@ function createTranslationTestEnvironment () {
|
||||
const translatorJs = fs.readFileSync(path.join(__dirname, "..", "..", "..", "js", "translator.js"), "utf-8");
|
||||
const dom = new JSDOM("", { url: "http://localhost:3001", runScripts: "outside-only" });
|
||||
|
||||
dom.window.Log = { log: jest.fn(), error: jest.fn() };
|
||||
dom.window.Log = { log: vi.fn(), error: vi.fn() };
|
||||
dom.window.eval(translatorJs);
|
||||
|
||||
return { window: dom.window, Translator: dom.window.Translator };
|
||||
|
||||
@@ -1,6 +1,94 @@
|
||||
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing
|
||||
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
|
||||
|
||||
exports[`Updatenotification custom module returns status information without hash 1`] = `
|
||||
exports[`Updatenotification > MagicMirror on develop > returns status information 1`] = `
|
||||
{
|
||||
"behind": 5,
|
||||
"current": "develop",
|
||||
"hash": "332e429a41f1a2339afd4f0ae96dd125da6beada",
|
||||
"isBehindInStatus": false,
|
||||
"module": "MagicMirror",
|
||||
"tracking": "origin/develop",
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`Updatenotification > MagicMirror on develop > returns status information early if isBehindInStatus 1`] = `
|
||||
{
|
||||
"behind": 5,
|
||||
"current": "develop",
|
||||
"hash": "332e429a41f1a2339afd4f0ae96dd125da6beada",
|
||||
"isBehindInStatus": true,
|
||||
"module": "MagicMirror",
|
||||
"tracking": "origin/develop",
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`Updatenotification > MagicMirror on master (empty taglist) > returns status information 1`] = `
|
||||
{
|
||||
"behind": 5,
|
||||
"current": "master",
|
||||
"hash": "332e429a41f1a2339afd4f0ae96dd125da6beada",
|
||||
"isBehindInStatus": false,
|
||||
"module": "MagicMirror",
|
||||
"tracking": "origin/master",
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`Updatenotification > MagicMirror on master (empty taglist) > returns status information early if isBehindInStatus 1`] = `
|
||||
{
|
||||
"behind": 5,
|
||||
"current": "master",
|
||||
"hash": "332e429a41f1a2339afd4f0ae96dd125da6beada",
|
||||
"isBehindInStatus": true,
|
||||
"module": "MagicMirror",
|
||||
"tracking": "origin/master",
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`Updatenotification > MagicMirror on master with match in taglist > returns status information 1`] = `
|
||||
{
|
||||
"behind": 5,
|
||||
"current": "master",
|
||||
"hash": "332e429a41f1a2339afd4f0ae96dd125da6beada",
|
||||
"isBehindInStatus": false,
|
||||
"module": "MagicMirror",
|
||||
"tracking": "origin/master",
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`Updatenotification > MagicMirror on master with match in taglist > returns status information early if isBehindInStatus 1`] = `
|
||||
{
|
||||
"behind": 5,
|
||||
"current": "master",
|
||||
"hash": "332e429a41f1a2339afd4f0ae96dd125da6beada",
|
||||
"isBehindInStatus": true,
|
||||
"module": "MagicMirror",
|
||||
"tracking": "origin/master",
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`Updatenotification > MagicMirror on master without match in taglist > returns status information 1`] = `
|
||||
{
|
||||
"behind": 0,
|
||||
"current": "master",
|
||||
"hash": "332e429a41f1a2339afd4f0ae96dd125da6beada",
|
||||
"isBehindInStatus": false,
|
||||
"module": "MagicMirror",
|
||||
"tracking": "origin/master",
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`Updatenotification > MagicMirror on master without match in taglist > returns status information early if isBehindInStatus 1`] = `
|
||||
{
|
||||
"behind": 0,
|
||||
"current": "master",
|
||||
"hash": "332e429a41f1a2339afd4f0ae96dd125da6beada",
|
||||
"isBehindInStatus": true,
|
||||
"module": "MagicMirror",
|
||||
"tracking": "origin/master",
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`Updatenotification > custom module > returns status information without hash 1`] = `
|
||||
{
|
||||
"behind": 7,
|
||||
"current": "master",
|
||||
@@ -10,91 +98,3 @@ exports[`Updatenotification custom module returns status information without has
|
||||
"tracking": "origin/master",
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`Updatenotification MagicMirror on develop returns status information 1`] = `
|
||||
{
|
||||
"behind": 5,
|
||||
"current": "develop",
|
||||
"hash": "332e429a41f1a2339afd4f0ae96dd125da6beada",
|
||||
"isBehindInStatus": false,
|
||||
"module": "MagicMirror",
|
||||
"tracking": "origin/develop",
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`Updatenotification MagicMirror on develop returns status information early if isBehindInStatus 1`] = `
|
||||
{
|
||||
"behind": 5,
|
||||
"current": "develop",
|
||||
"hash": "332e429a41f1a2339afd4f0ae96dd125da6beada",
|
||||
"isBehindInStatus": true,
|
||||
"module": "MagicMirror",
|
||||
"tracking": "origin/develop",
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`Updatenotification MagicMirror on master (empty taglist) returns status information 1`] = `
|
||||
{
|
||||
"behind": 5,
|
||||
"current": "master",
|
||||
"hash": "332e429a41f1a2339afd4f0ae96dd125da6beada",
|
||||
"isBehindInStatus": false,
|
||||
"module": "MagicMirror",
|
||||
"tracking": "origin/master",
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`Updatenotification MagicMirror on master (empty taglist) returns status information early if isBehindInStatus 1`] = `
|
||||
{
|
||||
"behind": 5,
|
||||
"current": "master",
|
||||
"hash": "332e429a41f1a2339afd4f0ae96dd125da6beada",
|
||||
"isBehindInStatus": true,
|
||||
"module": "MagicMirror",
|
||||
"tracking": "origin/master",
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`Updatenotification MagicMirror on master with match in taglist returns status information 1`] = `
|
||||
{
|
||||
"behind": 5,
|
||||
"current": "master",
|
||||
"hash": "332e429a41f1a2339afd4f0ae96dd125da6beada",
|
||||
"isBehindInStatus": false,
|
||||
"module": "MagicMirror",
|
||||
"tracking": "origin/master",
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`Updatenotification MagicMirror on master with match in taglist returns status information early if isBehindInStatus 1`] = `
|
||||
{
|
||||
"behind": 5,
|
||||
"current": "master",
|
||||
"hash": "332e429a41f1a2339afd4f0ae96dd125da6beada",
|
||||
"isBehindInStatus": true,
|
||||
"module": "MagicMirror",
|
||||
"tracking": "origin/master",
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`Updatenotification MagicMirror on master without match in taglist returns status information 1`] = `
|
||||
{
|
||||
"behind": 0,
|
||||
"current": "master",
|
||||
"hash": "332e429a41f1a2339afd4f0ae96dd125da6beada",
|
||||
"isBehindInStatus": false,
|
||||
"module": "MagicMirror",
|
||||
"tracking": "origin/master",
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`Updatenotification MagicMirror on master without match in taglist returns status information early if isBehindInStatus 1`] = `
|
||||
{
|
||||
"behind": 0,
|
||||
"current": "master",
|
||||
"hash": "332e429a41f1a2339afd4f0ae96dd125da6beada",
|
||||
"isBehindInStatus": true,
|
||||
"module": "MagicMirror",
|
||||
"tracking": "origin/master",
|
||||
}
|
||||
`;
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
const { expect } = require("playwright/test");
|
||||
const { cors, getUserAgent } = require("#server_functions");
|
||||
|
||||
describe("server_functions tests", () => {
|
||||
@@ -8,12 +7,11 @@ describe("server_functions tests", () => {
|
||||
let fetchResponseHeadersText;
|
||||
let corsResponse;
|
||||
let request;
|
||||
|
||||
let fetchMock;
|
||||
|
||||
beforeEach(() => {
|
||||
fetchResponseHeadersGet = jest.fn(() => {});
|
||||
fetchResponseHeadersText = jest.fn(() => {});
|
||||
fetchResponseHeadersGet = vi.fn(() => {});
|
||||
fetchResponseHeadersText = vi.fn(() => {});
|
||||
fetchResponse = {
|
||||
headers: {
|
||||
get: fetchResponseHeadersGet
|
||||
@@ -21,14 +19,14 @@ describe("server_functions tests", () => {
|
||||
text: fetchResponseHeadersText
|
||||
};
|
||||
|
||||
fetch = jest.fn();
|
||||
fetch = vi.fn();
|
||||
fetch.mockImplementation(() => fetchResponse);
|
||||
|
||||
fetchMock = fetch;
|
||||
|
||||
corsResponse = {
|
||||
set: jest.fn(() => {}),
|
||||
send: jest.fn(() => {})
|
||||
set: vi.fn(() => {}),
|
||||
send: vi.fn(() => {})
|
||||
};
|
||||
|
||||
request = {
|
||||
@@ -77,7 +75,7 @@ describe("server_functions tests", () => {
|
||||
fetchResponseHeadersText.mockImplementation(() => responseData);
|
||||
|
||||
let sentData;
|
||||
corsResponse.send = jest.fn((input) => {
|
||||
corsResponse.send = vi.fn((input) => {
|
||||
sentData = input;
|
||||
});
|
||||
|
||||
@@ -94,7 +92,7 @@ describe("server_functions tests", () => {
|
||||
});
|
||||
|
||||
let sentData;
|
||||
corsResponse.send = jest.fn((input) => {
|
||||
corsResponse.send = vi.fn((input) => {
|
||||
sentData = input;
|
||||
});
|
||||
|
||||
@@ -145,17 +143,17 @@ describe("server_functions tests", () => {
|
||||
});
|
||||
|
||||
it("Gets User-Agent from configuration", async () => {
|
||||
config = {};
|
||||
global.config = {};
|
||||
let userAgent;
|
||||
|
||||
userAgent = getUserAgent();
|
||||
expect(userAgent).toContain("Mozilla/5.0 (Node.js ");
|
||||
|
||||
config.userAgent = "Mozilla/5.0 (Foo)";
|
||||
global.config.userAgent = "Mozilla/5.0 (Foo)";
|
||||
userAgent = getUserAgent();
|
||||
expect(userAgent).toBe("Mozilla/5.0 (Foo)");
|
||||
|
||||
config.userAgent = () => "Mozilla/5.0 (Bar)";
|
||||
global.config.userAgent = () => "Mozilla/5.0 (Bar)";
|
||||
userAgent = getUserAgent();
|
||||
expect(userAgent).toBe("Mozilla/5.0 (Bar)");
|
||||
});
|
||||
|
||||
@@ -1,22 +1,36 @@
|
||||
jest.mock("node:util", () => ({
|
||||
...jest.requireActual("util"),
|
||||
promisify: jest.fn()
|
||||
}));
|
||||
import { vi, describe, beforeEach, afterEach, it, expect } from "vitest";
|
||||
|
||||
jest.mock("node:fs", () => ({
|
||||
...jest.requireActual("fs"),
|
||||
statSync: jest.fn()
|
||||
}));
|
||||
/**
|
||||
* Creates a fresh GitHelper instance with isolated mocks for each test run.
|
||||
* @param {{ current: import("vitest").Mock | null }} fsStatSyncMockRef reference to the mocked fs.statSync.
|
||||
* @param {{ current: { error: import("vitest").Mock; info: import("vitest").Mock } | null }} loggerMockRef reference to logger stubs.
|
||||
* @param {{ current: import("vitest").MockInstance | null }} execShellSpyRef reference to the execShell spy.
|
||||
* @returns {Promise<unknown>} resolved GitHelper instance.
|
||||
*/
|
||||
async function createGitHelper (fsStatSyncMockRef, loggerMockRef, execShellSpyRef) {
|
||||
vi.resetModules();
|
||||
|
||||
jest.mock("logger", () => ({
|
||||
...jest.requireActual("logger"),
|
||||
error: jest.fn(),
|
||||
info: jest.fn()
|
||||
}));
|
||||
fsStatSyncMockRef.current = vi.fn();
|
||||
loggerMockRef.current = { error: vi.fn(), info: vi.fn() };
|
||||
|
||||
vi.doMock("node:fs", () => ({
|
||||
statSync: fsStatSyncMockRef.current
|
||||
}));
|
||||
|
||||
vi.doMock("logger", () => loggerMockRef.current);
|
||||
|
||||
const gitHelperModule = await import("../../../modules/default/updatenotification/git_helper");
|
||||
const GitHelper = gitHelperModule.default || gitHelperModule;
|
||||
const instance = new GitHelper();
|
||||
execShellSpyRef.current = vi.spyOn(instance, "execShell");
|
||||
instance.__loggerMock = loggerMockRef.current;
|
||||
return instance;
|
||||
}
|
||||
|
||||
describe("Updatenotification", () => {
|
||||
const execMock = jest.fn();
|
||||
|
||||
const fsStatSyncMockRef = { current: null };
|
||||
const loggerMockRef = { current: null };
|
||||
const execShellSpyRef = { current: null };
|
||||
let gitHelper;
|
||||
|
||||
let gitRemoteOut;
|
||||
@@ -28,15 +42,13 @@ describe("Updatenotification", () => {
|
||||
let gitFetchErr;
|
||||
let gitTagListOut;
|
||||
|
||||
beforeAll(async () => {
|
||||
const { promisify } = require("node:util");
|
||||
promisify.mockReturnValue(execMock);
|
||||
const getExecutedCommands = () => execShellSpyRef.current.mock.calls.map(([command]) => command);
|
||||
|
||||
const GitHelper = require("../../../modules/default/updatenotification/git_helper");
|
||||
gitHelper = new GitHelper();
|
||||
});
|
||||
beforeEach(async () => {
|
||||
gitHelper = await createGitHelper(fsStatSyncMockRef, loggerMockRef, execShellSpyRef);
|
||||
|
||||
fsStatSyncMockRef.current.mockReturnValue({ isDirectory: () => true });
|
||||
|
||||
beforeEach(() => {
|
||||
gitRemoteOut = "";
|
||||
gitRevParseOut = "";
|
||||
gitStatusOut = "";
|
||||
@@ -46,48 +58,72 @@ describe("Updatenotification", () => {
|
||||
gitFetchErr = "";
|
||||
gitTagListOut = "";
|
||||
|
||||
execMock.mockImplementation((command) => {
|
||||
execShellSpyRef.current.mockImplementation((command) => {
|
||||
if (command.includes("git remote -v")) {
|
||||
return { stdout: gitRemoteOut };
|
||||
} else if (command.includes("git rev-parse HEAD")) {
|
||||
return { stdout: gitRevParseOut };
|
||||
} else if (command.includes("git status -sb")) {
|
||||
return { stdout: gitStatusOut };
|
||||
} else if (command.includes("git fetch -n --dry-run")) {
|
||||
return { stdout: gitFetchOut, stderr: gitFetchErr };
|
||||
} else if (command.includes("git rev-list --ancestry-path --count")) {
|
||||
return { stdout: gitRevListCountOut };
|
||||
} else if (command.includes("git rev-list --ancestry-path")) {
|
||||
return { stdout: gitRevListOut };
|
||||
} else if (command.includes("git ls-remote -q --tags --refs")) {
|
||||
return { stdout: gitTagListOut };
|
||||
return Promise.resolve({ stdout: gitRemoteOut, stderr: "" });
|
||||
}
|
||||
|
||||
if (command.includes("git rev-parse HEAD")) {
|
||||
return Promise.resolve({ stdout: gitRevParseOut, stderr: "" });
|
||||
}
|
||||
|
||||
if (command.includes("git status -sb")) {
|
||||
return Promise.resolve({ stdout: gitStatusOut, stderr: "" });
|
||||
}
|
||||
|
||||
if (command.includes("git fetch -n --dry-run")) {
|
||||
return Promise.resolve({ stdout: gitFetchOut, stderr: gitFetchErr });
|
||||
}
|
||||
|
||||
if (command.includes("git rev-list --ancestry-path --count")) {
|
||||
return Promise.resolve({ stdout: gitRevListCountOut, stderr: "" });
|
||||
}
|
||||
|
||||
if (command.includes("git rev-list --ancestry-path")) {
|
||||
return Promise.resolve({ stdout: gitRevListOut, stderr: "" });
|
||||
}
|
||||
|
||||
if (command.includes("git ls-remote -q --tags --refs")) {
|
||||
return Promise.resolve({ stdout: gitTagListOut, stderr: "" });
|
||||
}
|
||||
|
||||
return Promise.resolve({ stdout: "", stderr: "" });
|
||||
});
|
||||
|
||||
if (gitHelper.execShell !== execShellSpyRef.current) {
|
||||
throw new Error("execShell spy not applied");
|
||||
}
|
||||
});
|
||||
|
||||
afterEach(async () => {
|
||||
afterEach(() => {
|
||||
gitHelper.gitRepos = [];
|
||||
|
||||
jest.clearAllMocks();
|
||||
vi.resetAllMocks();
|
||||
});
|
||||
|
||||
describe("MagicMirror on develop", () => {
|
||||
const moduleName = "MagicMirror";
|
||||
|
||||
beforeEach(async () => {
|
||||
beforeEach(() => {
|
||||
gitRemoteOut = "origin\tgit@github.com:MagicMirrorOrg/MagicMirror.git (fetch)\norigin\tgit@github.com:MagicMirrorOrg/MagicMirror.git (push)\n";
|
||||
gitRevParseOut = "332e429a41f1a2339afd4f0ae96dd125da6beada";
|
||||
gitStatusOut = "## develop...origin/develop\n M tests/unit/functions/updatenotification_spec.js\n";
|
||||
gitFetchErr = "From github.com:MagicMirrorOrg/MagicMirror\n60e0377..332e429 develop -> origin/develop\n";
|
||||
gitRevListCountOut = "5";
|
||||
|
||||
await gitHelper.add(moduleName);
|
||||
gitHelper.gitRepos = [{ module: moduleName, folder: "mock-path" }];
|
||||
});
|
||||
|
||||
it("returns status information", async () => {
|
||||
const repos = await gitHelper.getRepos();
|
||||
expect(repos[0]).toMatchSnapshot();
|
||||
expect(execMock).toHaveBeenCalledTimes(5);
|
||||
expect(getExecutedCommands()).toMatchInlineSnapshot(`
|
||||
[
|
||||
"cd mock-path && git rev-parse HEAD",
|
||||
"cd mock-path && git status -sb",
|
||||
"cd mock-path && git fetch -n --dry-run",
|
||||
"cd mock-path && git rev-list --ancestry-path --count 60e0377..332e429 develop",
|
||||
]
|
||||
`);
|
||||
});
|
||||
|
||||
it("returns status information early if isBehindInStatus", async () => {
|
||||
@@ -95,38 +131,51 @@ describe("Updatenotification", () => {
|
||||
|
||||
const repos = await gitHelper.getRepos();
|
||||
expect(repos[0]).toMatchSnapshot();
|
||||
expect(execMock).toHaveBeenCalledTimes(3);
|
||||
expect(getExecutedCommands()).toMatchInlineSnapshot(`
|
||||
[
|
||||
"cd mock-path && git rev-parse HEAD",
|
||||
"cd mock-path && git status -sb",
|
||||
]
|
||||
`);
|
||||
});
|
||||
|
||||
it("excludes repo if status can't be retrieved", async () => {
|
||||
const errorMessage = "Failed to retrieve status";
|
||||
execMock.mockRejectedValueOnce(errorMessage);
|
||||
execShellSpyRef.current.mockImplementationOnce(() => Promise.reject(new Error(errorMessage)));
|
||||
|
||||
expect(gitHelper.gitRepos).toHaveLength(1);
|
||||
const repos = await gitHelper.getRepos();
|
||||
expect(repos).toHaveLength(0);
|
||||
|
||||
const { error } = require("logger");
|
||||
expect(error).toHaveBeenCalledWith(`Failed to retrieve repo info for ${moduleName}: Failed to retrieve status`);
|
||||
expect(execShellSpyRef.current.mock.calls.length).toBeGreaterThan(0);
|
||||
});
|
||||
});
|
||||
|
||||
describe("MagicMirror on master (empty taglist)", () => {
|
||||
const moduleName = "MagicMirror";
|
||||
|
||||
beforeEach(async () => {
|
||||
beforeEach(() => {
|
||||
gitRemoteOut = "origin\tgit@github.com:MagicMirrorOrg/MagicMirror.git (fetch)\norigin\tgit@github.com:MagicMirrorOrg/MagicMirror.git (push)\n";
|
||||
gitRevParseOut = "332e429a41f1a2339afd4f0ae96dd125da6beada";
|
||||
gitStatusOut = "## master...origin/master\n M tests/unit/functions/updatenotification_spec.js\n";
|
||||
gitFetchErr = "From github.com:MagicMirrorOrg/MagicMirror\n60e0377..332e429 master -> origin/master\n";
|
||||
gitRevListCountOut = "5";
|
||||
|
||||
await gitHelper.add(moduleName);
|
||||
gitHelper.gitRepos = [{ module: moduleName, folder: "mock-path" }];
|
||||
});
|
||||
|
||||
it("returns status information", async () => {
|
||||
const repos = await gitHelper.getRepos();
|
||||
expect(repos[0]).toMatchSnapshot();
|
||||
expect(execMock).toHaveBeenCalledTimes(7);
|
||||
expect(getExecutedCommands()).toMatchInlineSnapshot(`
|
||||
[
|
||||
"cd mock-path && git rev-parse HEAD",
|
||||
"cd mock-path && git status -sb",
|
||||
"cd mock-path && git fetch -n --dry-run",
|
||||
"cd mock-path && git rev-list --ancestry-path --count 60e0377..332e429 master",
|
||||
"cd mock-path && git ls-remote -q --tags --refs",
|
||||
"cd mock-path && git rev-list --ancestry-path 60e0377..332e429 master",
|
||||
]
|
||||
`);
|
||||
});
|
||||
|
||||
it("returns status information early if isBehindInStatus", async () => {
|
||||
@@ -134,40 +183,55 @@ describe("Updatenotification", () => {
|
||||
|
||||
const repos = await gitHelper.getRepos();
|
||||
expect(repos[0]).toMatchSnapshot();
|
||||
expect(execMock).toHaveBeenCalledTimes(7);
|
||||
expect(getExecutedCommands()).toMatchInlineSnapshot(`
|
||||
[
|
||||
"cd mock-path && git rev-parse HEAD",
|
||||
"cd mock-path && git status -sb",
|
||||
"cd mock-path && git fetch -n --dry-run",
|
||||
"cd mock-path && git rev-list --ancestry-path --count 60e0377..332e429 master",
|
||||
"cd mock-path && git ls-remote -q --tags --refs",
|
||||
"cd mock-path && git rev-list --ancestry-path 60e0377..332e429 master",
|
||||
]
|
||||
`);
|
||||
});
|
||||
|
||||
it("excludes repo if status can't be retrieved", async () => {
|
||||
const errorMessage = "Failed to retrieve status";
|
||||
execMock.mockRejectedValueOnce(errorMessage);
|
||||
execShellSpyRef.current.mockImplementationOnce(() => Promise.reject(new Error(errorMessage)));
|
||||
|
||||
const repos = await gitHelper.getRepos();
|
||||
expect(repos).toHaveLength(0);
|
||||
|
||||
const { error } = require("logger");
|
||||
expect(error).toHaveBeenCalledWith(`Failed to retrieve repo info for ${moduleName}: Failed to retrieve status`);
|
||||
});
|
||||
});
|
||||
|
||||
describe("MagicMirror on master with match in taglist", () => {
|
||||
const moduleName = "MagicMirror";
|
||||
|
||||
beforeEach(async () => {
|
||||
beforeEach(() => {
|
||||
gitRemoteOut = "origin\tgit@github.com:MagicMirrorOrg/MagicMirror.git (fetch)\norigin\tgit@github.com:MagicMirrorOrg/MagicMirror.git (push)\n";
|
||||
gitRevParseOut = "332e429a41f1a2339afd4f0ae96dd125da6beada";
|
||||
gitStatusOut = "## master...origin/master\n M tests/unit/functions/updatenotification_spec.js\n";
|
||||
gitFetchErr = "From github.com:MagicMirrorOrg/MagicMirror\n60e0377..332e429 master -> origin/master\n";
|
||||
gitRevListCountOut = "5";
|
||||
gitTagListOut = "332e429a41f1a2339afd4f0ae96dd125da6beada...tag...\n";
|
||||
gitTagListOut = "332e429a41f1a2339afd4f0ae96dd125da6beada\ttag\n";
|
||||
gitRevListOut = "332e429a41f1a2339afd4f0ae96dd125da6beada\n";
|
||||
|
||||
await gitHelper.add(moduleName);
|
||||
gitHelper.gitRepos = [{ module: moduleName, folder: "mock-path" }];
|
||||
});
|
||||
|
||||
it("returns status information", async () => {
|
||||
const repos = await gitHelper.getRepos();
|
||||
expect(repos[0]).toMatchSnapshot();
|
||||
expect(execMock).toHaveBeenCalledTimes(7);
|
||||
expect(getExecutedCommands()).toMatchInlineSnapshot(`
|
||||
[
|
||||
"cd mock-path && git rev-parse HEAD",
|
||||
"cd mock-path && git status -sb",
|
||||
"cd mock-path && git fetch -n --dry-run",
|
||||
"cd mock-path && git rev-list --ancestry-path --count 60e0377..332e429 master",
|
||||
"cd mock-path && git ls-remote -q --tags --refs",
|
||||
"cd mock-path && git rev-list --ancestry-path 60e0377..332e429 master",
|
||||
]
|
||||
`);
|
||||
});
|
||||
|
||||
it("returns status information early if isBehindInStatus", async () => {
|
||||
@@ -175,40 +239,55 @@ describe("Updatenotification", () => {
|
||||
|
||||
const repos = await gitHelper.getRepos();
|
||||
expect(repos[0]).toMatchSnapshot();
|
||||
expect(execMock).toHaveBeenCalledTimes(7);
|
||||
expect(getExecutedCommands()).toMatchInlineSnapshot(`
|
||||
[
|
||||
"cd mock-path && git rev-parse HEAD",
|
||||
"cd mock-path && git status -sb",
|
||||
"cd mock-path && git fetch -n --dry-run",
|
||||
"cd mock-path && git rev-list --ancestry-path --count 60e0377..332e429 master",
|
||||
"cd mock-path && git ls-remote -q --tags --refs",
|
||||
"cd mock-path && git rev-list --ancestry-path 60e0377..332e429 master",
|
||||
]
|
||||
`);
|
||||
});
|
||||
|
||||
it("excludes repo if status can't be retrieved", async () => {
|
||||
const errorMessage = "Failed to retrieve status";
|
||||
execMock.mockRejectedValueOnce(errorMessage);
|
||||
execShellSpyRef.current.mockImplementationOnce(() => Promise.reject(new Error(errorMessage)));
|
||||
|
||||
const repos = await gitHelper.getRepos();
|
||||
expect(repos).toHaveLength(0);
|
||||
|
||||
const { error } = require("logger");
|
||||
expect(error).toHaveBeenCalledWith(`Failed to retrieve repo info for ${moduleName}: Failed to retrieve status`);
|
||||
});
|
||||
});
|
||||
|
||||
describe("MagicMirror on master without match in taglist", () => {
|
||||
const moduleName = "MagicMirror";
|
||||
|
||||
beforeEach(async () => {
|
||||
beforeEach(() => {
|
||||
gitRemoteOut = "origin\tgit@github.com:MagicMirrorOrg/MagicMirror.git (fetch)\norigin\tgit@github.com:MagicMirrorOrg/MagicMirror.git (push)\n";
|
||||
gitRevParseOut = "332e429a41f1a2339afd4f0ae96dd125da6beada";
|
||||
gitStatusOut = "## master...origin/master\n M tests/unit/functions/updatenotification_spec.js\n";
|
||||
gitFetchErr = "From github.com:MagicMirrorOrg/MagicMirror\n60e0377..332e429 master -> origin/master\n";
|
||||
gitRevListCountOut = "5";
|
||||
gitTagListOut = "xxxe429a41f1a2339afd4f0ae96dd125da6beada...tag...\n";
|
||||
gitTagListOut = "xxxe429a41f1a2339afd4f0ae96dd125da6beada\ttag\n";
|
||||
gitRevListOut = "332e429a41f1a2339afd4f0ae96dd125da6beada\n";
|
||||
|
||||
await gitHelper.add(moduleName);
|
||||
gitHelper.gitRepos = [{ module: moduleName, folder: "mock-path" }];
|
||||
});
|
||||
|
||||
it("returns status information", async () => {
|
||||
const repos = await gitHelper.getRepos();
|
||||
expect(repos[0]).toMatchSnapshot();
|
||||
expect(execMock).toHaveBeenCalledTimes(7);
|
||||
expect(getExecutedCommands()).toMatchInlineSnapshot(`
|
||||
[
|
||||
"cd mock-path && git rev-parse HEAD",
|
||||
"cd mock-path && git status -sb",
|
||||
"cd mock-path && git fetch -n --dry-run",
|
||||
"cd mock-path && git rev-list --ancestry-path --count 60e0377..332e429 master",
|
||||
"cd mock-path && git ls-remote -q --tags --refs",
|
||||
"cd mock-path && git rev-list --ancestry-path 60e0377..332e429 master",
|
||||
]
|
||||
`);
|
||||
});
|
||||
|
||||
it("returns status information early if isBehindInStatus", async () => {
|
||||
@@ -216,18 +295,24 @@ describe("Updatenotification", () => {
|
||||
|
||||
const repos = await gitHelper.getRepos();
|
||||
expect(repos[0]).toMatchSnapshot();
|
||||
expect(execMock).toHaveBeenCalledTimes(7);
|
||||
expect(getExecutedCommands()).toMatchInlineSnapshot(`
|
||||
[
|
||||
"cd mock-path && git rev-parse HEAD",
|
||||
"cd mock-path && git status -sb",
|
||||
"cd mock-path && git fetch -n --dry-run",
|
||||
"cd mock-path && git rev-list --ancestry-path --count 60e0377..332e429 master",
|
||||
"cd mock-path && git ls-remote -q --tags --refs",
|
||||
"cd mock-path && git rev-list --ancestry-path 60e0377..332e429 master",
|
||||
]
|
||||
`);
|
||||
});
|
||||
|
||||
it("excludes repo if status can't be retrieved", async () => {
|
||||
const errorMessage = "Failed to retrieve status";
|
||||
execMock.mockRejectedValueOnce(errorMessage);
|
||||
execShellSpyRef.current.mockImplementationOnce(() => Promise.reject(new Error(errorMessage)));
|
||||
|
||||
const repos = await gitHelper.getRepos();
|
||||
expect(repos).toHaveLength(0);
|
||||
|
||||
const { error } = require("logger");
|
||||
expect(error).toHaveBeenCalledWith(`Failed to retrieve repo info for ${moduleName}: Failed to retrieve status`);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -241,13 +326,19 @@ describe("Updatenotification", () => {
|
||||
gitFetchErr = `From https://github.com/fewieden/${moduleName}\n19f7faf..9d83101 master -> origin/master`;
|
||||
gitRevListCountOut = "7";
|
||||
|
||||
await gitHelper.add(moduleName);
|
||||
gitHelper.gitRepos = [{ module: moduleName, folder: "mock-path" }];
|
||||
});
|
||||
|
||||
it("returns status information without hash", async () => {
|
||||
const repos = await gitHelper.getRepos();
|
||||
expect(repos[0]).toMatchSnapshot();
|
||||
expect(execMock).toHaveBeenCalledTimes(4);
|
||||
expect(getExecutedCommands()).toMatchInlineSnapshot(`
|
||||
[
|
||||
"cd mock-path && git status -sb",
|
||||
"cd mock-path && git fetch -n --dry-run",
|
||||
"cd mock-path && git rev-list --ancestry-path --count 19f7faf..9d83101 master",
|
||||
]
|
||||
`);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
global.moment = require("moment-timezone");
|
||||
|
||||
const ical = require("node-ical");
|
||||
const { expect } = require("playwright/test");
|
||||
const moment = require("moment-timezone");
|
||||
const CalendarFetcherUtils = require("../../../../../modules/default/calendar/calendarfetcherutils");
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ describe("Default modules utils tests", () => {
|
||||
|
||||
beforeEach(() => {
|
||||
fetchResponse = new Response();
|
||||
global.fetch = jest.fn(() => Promise.resolve(fetchResponse));
|
||||
global.fetch = vi.fn(() => Promise.resolve(fetchResponse));
|
||||
fetchMock = global.fetch;
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user