From f6c59f4bbc88d3e203108fb88818733f663d8360 Mon Sep 17 00:00:00 2001 From: Romain Lenzotti Date: Mon, 13 Dec 2021 12:17:44 +0100 Subject: [PATCH] chore: Fix unit test --- packages/gphoto2-core/src/utils/GPPointer.ts | 1 + packages/gphoto2-driver/src/__mock__/gphoto2-core.ts | 8 ++++++++ .../gphoto2-driver/src/components/AbilitiesList.spec.ts | 7 +++---- packages/gphoto2-driver/src/components/CameraList.spec.ts | 7 +++---- packages/gphoto2-driver/src/components/List.spec.ts | 7 +++---- 5 files changed, 18 insertions(+), 12 deletions(-) create mode 100644 packages/gphoto2-driver/src/__mock__/gphoto2-core.ts diff --git a/packages/gphoto2-core/src/utils/GPPointer.ts b/packages/gphoto2-core/src/utils/GPPointer.ts index 7cde177..4b7c110 100644 --- a/packages/gphoto2-core/src/utils/GPPointer.ts +++ b/packages/gphoto2-core/src/utils/GPPointer.ts @@ -6,6 +6,7 @@ import {alloc, allocCString, Pointer, refType} from "ref-napi"; * @returns {Pointer} */ export function GPPointer(type: any = "void"): Pointer { + console.log(alloc); return alloc(type) as any; } diff --git a/packages/gphoto2-driver/src/__mock__/gphoto2-core.ts b/packages/gphoto2-driver/src/__mock__/gphoto2-core.ts new file mode 100644 index 0000000..8c4f7d1 --- /dev/null +++ b/packages/gphoto2-driver/src/__mock__/gphoto2-core.ts @@ -0,0 +1,8 @@ +import {FakeBuffer} from "./FakeBuffer"; + +export function GPPointer(refType: any, value?: any) { + return new FakeBuffer(refType.name || refType, value); +} + +export const GPPointerString = jest.fn(); +export const getGPhoto2Driver = jest.fn(); diff --git a/packages/gphoto2-driver/src/components/AbilitiesList.spec.ts b/packages/gphoto2-driver/src/components/AbilitiesList.spec.ts index 869b658..d187980 100644 --- a/packages/gphoto2-driver/src/components/AbilitiesList.spec.ts +++ b/packages/gphoto2-driver/src/components/AbilitiesList.spec.ts @@ -6,11 +6,10 @@ import {$log} from "@tsed/logger"; $log.stop(); -jest.mock("@tsed/gphoto2-core"); -jest.mock("ref-napi", () => { +jest.mock("@tsed/gphoto2-core", () => { return { - ...jest.requireActual("ref-napi"), - ...jest.requireActual("@tsed/gphoto2-driver/src/__mock__/ref-napi") + ...jest.requireActual("@tsed/gphoto2-core"), + ...jest.requireActual("@tsed/gphoto2-driver/src/__mock__/gphoto2-core") }; }); diff --git a/packages/gphoto2-driver/src/components/CameraList.spec.ts b/packages/gphoto2-driver/src/components/CameraList.spec.ts index 1474a2e..69b749a 100644 --- a/packages/gphoto2-driver/src/components/CameraList.spec.ts +++ b/packages/gphoto2-driver/src/components/CameraList.spec.ts @@ -6,11 +6,10 @@ import {alloc} from "../__mock__/ref-napi"; $log.stop(); -jest.mock("@tsed/gphoto2-core"); -jest.mock("ref-napi", () => { +jest.mock("@tsed/gphoto2-core", () => { return { - ...jest.requireActual("ref-napi"), - ...jest.requireActual("@tsed/gphoto2-driver/src/__mock__/ref-napi") + ...jest.requireActual("@tsed/gphoto2-core"), + ...jest.requireActual("@tsed/gphoto2-driver/src/__mock__/gphoto2-core") }; }); diff --git a/packages/gphoto2-driver/src/components/List.spec.ts b/packages/gphoto2-driver/src/components/List.spec.ts index 48ad369..f0866e3 100644 --- a/packages/gphoto2-driver/src/components/List.spec.ts +++ b/packages/gphoto2-driver/src/components/List.spec.ts @@ -6,11 +6,10 @@ import {alloc} from "../__mock__/ref-napi"; $log.stop(); -jest.mock("@tsed/gphoto2-core"); -jest.mock("ref-napi", () => { +jest.mock("@tsed/gphoto2-core", () => { return { - ...jest.requireActual("ref-napi"), - ...jest.requireActual("@tsed/gphoto2-driver/src/__mock__/ref-napi") + ...jest.requireActual("@tsed/gphoto2-core"), + ...jest.requireActual("@tsed/gphoto2-driver/src/__mock__/gphoto2-core") }; });