mirror of
https://github.com/webrecorder/browsertrix-crawler.git
synced 2025-10-19 06:23:16 +00:00
Mock promisify
This commit is contained in:
parent
c0db99d364
commit
e3ef7c192a
1 changed files with 6 additions and 4 deletions
|
@ -1,5 +1,5 @@
|
|||
import { jest } from "@jest/globals";
|
||||
import child_process from "child_process";
|
||||
import util from "util";
|
||||
import { calculatePercentageUsed, checkDiskUtilization } from "../util/storage.js";
|
||||
|
||||
const mockDfOutput = `Filesystem 1K-blocks Used Available Use% Mounted on
|
||||
|
@ -17,7 +17,11 @@ test("ensure calculatePercentageUsed returns expected values", () => {
|
|||
expect(calculatePercentageUsed(0, 5)).toEqual(0);
|
||||
});
|
||||
|
||||
jest.mock("child_process");
|
||||
jest.mock("util", () => ({
|
||||
promisify: jest.fn(() => {
|
||||
return jest.fn().mockResolvedValue({ stdout: mockDfOutput });
|
||||
})
|
||||
}));
|
||||
|
||||
test("verify end-to-end disk utilization check works as expected with mock df return", async () => {
|
||||
const params = {
|
||||
|
@ -26,8 +30,6 @@ test("verify end-to-end disk utilization check works as expected with mock df re
|
|||
generateWACZ: true
|
||||
};
|
||||
|
||||
child_process.exec.mockImplementation((command, callback) => callback(null, {stdout: mockDfOutput}));
|
||||
|
||||
const returnValue = await checkDiskUtilization(params, 7500000);
|
||||
expect(returnValue).toEqual({
|
||||
stop: false,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue