Skip to content

Commit

Permalink
chore: Add coveralls actions
Browse files Browse the repository at this point in the history
  • Loading branch information
Romakita committed Apr 21, 2021
1 parent 362c33e commit 196152d
Show file tree
Hide file tree
Showing 21 changed files with 295 additions and 116 deletions.
5 changes: 1 addition & 4 deletions .gflowrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"production": "production",
"develop": "master",
"develop": "production",
"charBranchNameSeparator": "_",
"remote": "origin",
"ignores": [],
Expand All @@ -12,8 +12,5 @@
"fix": "fix",
"chore": "chore",
"docs": "docs"
},
"refs": {
"feat_#6_change_require": "master"
}
}
6 changes: 3 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:

strategy:
matrix:
os: [ubuntu-latest, macos-latest]
os: [ubuntu-latest]
node-version: [ 12.x, 14.x, 15.x ]

steps:
Expand All @@ -48,7 +48,7 @@ jobs:
- name: Coveralls
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.GH_TOKEN }}
github-token: ${{ secrets.GITHUB_TOKEN }}
flag-name: run-${{ matrix.test_number }}
parallel: true

Expand All @@ -59,7 +59,7 @@ jobs:
- name: Coveralls Finished
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.GH_TOKEN }}
github-token: ${{ secrets.GITHUB_TOKEN }}
parallel-finished: true

build:
Expand Down
6 changes: 4 additions & 2 deletions packages/gphoto2-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,15 @@
"dependencies": {
"@tsed/core": "6.43.4",
"@tsed/logger": "5.13.2",
"ffi-napi": "4.0.3",
"ref-array-napi": "1.2.2",
"ref-napi": "^3.0.2",
"ref-napi": "3.0.2",
"ref-struct-napi": "1.1.1",
"tslib": "2.2.0"
},
"devDependencies": {
"@types/ref-napi": "^1.4.1"
"@types/ref-napi": "^1.4.1",
"@types/ffi-napi": "2.4.3"
},
"directories": {
"lib": "lib",
Expand Down
27 changes: 19 additions & 8 deletions packages/gphoto2-core/src/GPhoto2Driver.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import ffi from "ffi-napi";
import util from "util";
import {
GP_CAMERA_MODULE_ASYNC_KEYS,
GP_FILE_MODULE_ASYNC_KEYS,
Expand All @@ -17,9 +19,6 @@ import {
IGPWidgetModule
} from "./modules";

const ffi = require("ffi-napi");
const util = require("util");

/**
*
*/
Expand All @@ -33,7 +32,8 @@ export interface GPhoto2Driver
IGPPortInfoModule {}

// tslint:disable-next-line
export const GPhoto2Driver: GPhoto2Driver & {[key: string]: any} = ffi.Library("libgphoto2", {
export let GPhoto2Driver: GPhoto2Driver & Record<string, any>;
export const driverFunctions = {
// CONTEXT
...GPContextModuleDescription,

Expand All @@ -54,8 +54,19 @@ export const GPhoto2Driver: GPhoto2Driver & {[key: string]: any} = ffi.Library("

// Widget
...GPWidgetModuleDescription
});
};

// istanbul ignore next
export function getGPhoto2Driver(): GPhoto2Driver & Record<string, any> {
if (!GPhoto2Driver) {
const driver = ffi.Library("libgphoto2", driverFunctions);

[...GP_CAMERA_MODULE_ASYNC_KEYS, ...GP_FILE_MODULE_ASYNC_KEYS].forEach((key) => {
driver[`${key}_async`] = util.promisify(driver[key].async);
});

GPhoto2Driver = driver;
}

[...GP_CAMERA_MODULE_ASYNC_KEYS, ...GP_FILE_MODULE_ASYNC_KEYS].forEach((key) => {
GPhoto2Driver[`${key}_async`] = util.promisify(GPhoto2Driver[key].async);
});
return GPhoto2Driver;
}
3 changes: 3 additions & 0 deletions packages/gphoto2-core/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import "@tsed/core";
import {getGPhoto2Driver} from "./GPhoto2Driver";

export * from "./modules";
export * from "./types";
export * from "./GPhoto2Driver";
export * from "./utils/GPUtils";
export * from "./utils/GPPointer";
export * from "./utils/GPPointerRef";

getGPhoto2Driver();
84 changes: 84 additions & 0 deletions packages/gphoto2-core/src/utils/GPPointer.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import {alloc, allocCString} from "ref-napi";
import {GPPointer, GPPointerFloat, GPPointerInt, GPPointerString} from "./GPPointer";

jest.mock("ref-napi");

describe("GPPointer", () => {
describe("GPPointer()", () => {
it("should return a pointer", () => {
(alloc as any).mockReturnValue("alloc");

const pointer = GPPointer<string>("string");

expect(alloc).toHaveBeenCalledWith("string");
expect(pointer).toEqual("alloc");
});
it("should return a pointer (void)", () => {
(alloc as any).mockReturnValue("alloc");

const pointer = GPPointer<string>();

expect(alloc).toHaveBeenCalledWith("void");
expect(pointer).toEqual("alloc");
});
});

describe("GPPointerString()", () => {
it("should return a pointer from value", () => {
(alloc as any).mockReturnValue("alloc");
(allocCString as any).mockReturnValue("allocCString");

const pointer = GPPointerString("value");

expect(allocCString).toHaveBeenCalledWith("value");
expect(pointer).toEqual("allocCString");
});
it("should return a pointer from undefined", () => {
(alloc as any).mockReturnValue("alloc");
(allocCString as any).mockReturnValue("allocCString");

const pointer = GPPointerString();

expect(alloc).toHaveBeenCalledWith("string");
expect(pointer).toEqual("alloc");
});
});

describe("GPPointerInt()", () => {
it("should return a pointer", () => {
(alloc as any).mockReturnValue("alloc");

const pointer = GPPointerInt(1);

expect(alloc).toHaveBeenCalledWith("int", 1);
expect(pointer).toEqual("alloc");
});
it("should return a pointer (undefined)", () => {
(alloc as any).mockReturnValue("alloc");

const pointer = GPPointerInt();

expect(alloc).toHaveBeenCalledWith("int", undefined);
expect(pointer).toEqual("alloc");
});
});

describe("GPPointerFloat()", () => {
it("should return a pointer", () => {
(alloc as any).mockReturnValue("alloc");

const pointer = GPPointerFloat(1.0);

expect(alloc).toHaveBeenCalledWith("float", 1.0);
expect(pointer).toEqual("alloc");
});
it("should return a pointer (undefined)", () => {
(alloc as any).mockReturnValue("alloc");

const pointer = GPPointerFloat();

expect(alloc).toHaveBeenCalledWith("float", undefined);
expect(pointer).toEqual("alloc");
});
});
});
6 changes: 1 addition & 5 deletions packages/gphoto2-core/src/utils/GPPointer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,15 @@ import {PointerOf} from "../types";
* Create a new Pointer.
* @param type
* @returns {PointerOf<T>}
* @constructor
*/
export function GPPointer<T>(type: any = "void"): PointerOf<T> {
export function GPPointer<T = any>(type: any = "void"): PointerOf<T> {
return alloc(type) as any;
}

/**
* Create a new pointer of string.
* @param {string} value
* @returns {PointerOf<string>}
* @constructor
*/
export function GPPointerString(value?: string): PointerOf<string> {
return value !== undefined ? (allocCString(value) as any) : (alloc("string") as any);
Expand All @@ -25,7 +23,6 @@ export function GPPointerString(value?: string): PointerOf<string> {
* Create a new pointer of int
* @param {number} value
* @returns {PointerOf<number>}
* @constructor
*/
export function GPPointerInt(value?: number): PointerOf<number> {
return alloc("int", value) as any;
Expand All @@ -35,7 +32,6 @@ export function GPPointerInt(value?: number): PointerOf<number> {
* Create a new pointer of Float.
* @param {number} value
* @returns {PointerOf<number>}
* @constructor
*/
export function GPPointerFloat(value?: number): PointerOf<number> {
return alloc("float", value) as any;
Expand Down
38 changes: 38 additions & 0 deletions packages/gphoto2-core/src/utils/GPPointerRef.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import {getGPhoto2Driver} from "../GPhoto2Driver";
import {GPPointerRef, GPPointerRefOf} from "./GPPointerRef";
import {checkCode} from "./GPUtils";

jest.mock("../GPhoto2Driver");
jest.mock("./GPUtils");

describe("GPPointerRef", () => {
describe("GPPointerRef()", () => {
it("should return a pointerRef", () => {
const ref = GPPointerRef("string");

expect(ref.type?.name).toEqual("CString*");
});
it("should return a pointerRef (void)", () => {
const ref = GPPointerRef();

expect(ref.type?.name).toEqual("void*");
});
});
describe("GPPointerRefOf()", () => {
it("should a pointer of", () => {
const driver = {
method: jest.fn().mockReturnValue(1)
};

(getGPhoto2Driver as any).mockReturnValue(driver);

const result = GPPointerRefOf("method");

expect(result.type).toEqual({
indirection: 2,
name: "void*"
});
expect(checkCode).toHaveBeenCalledWith(1);
});
});
});
8 changes: 4 additions & 4 deletions packages/gphoto2-core/src/utils/GPPointerRef.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {alloc, refType} from "ref-napi";
import {GPhoto2Driver} from "../GPhoto2Driver";
import {getGPhoto2Driver} from "../GPhoto2Driver";
import {PointerRef} from "../types";
import {checkCode} from "./GPUtils";

Expand All @@ -9,7 +9,7 @@ import {checkCode} from "./GPUtils";
* @returns {PointerRef<T>}
* @constructor
*/
export function GPPointerRef<T>(type: any = "void"): PointerRef<T> {
export function GPPointerRef<T = any>(type: any = "void"): PointerRef<T> {
return alloc(refType(type)) as any;
}

Expand All @@ -19,10 +19,10 @@ export function GPPointerRef<T>(type: any = "void"): PointerRef<T> {
* @param type The type of the pointer
* @returns {any} A pointer
*/
export function GPPointerRefOf<T>(key: string, type: any = "void"): PointerRef<T> {
export function GPPointerRefOf<T = any>(key: string, type: any = "void"): PointerRef<T> {
const buffer: PointerRef<T> = GPPointerRef<T>(type);

checkCode((GPhoto2Driver as any)[key](buffer));
checkCode(getGPhoto2Driver()[key](buffer));

return buffer;
}
4 changes: 2 additions & 2 deletions packages/gphoto2-core/src/utils/GPUtils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {readCString} from "ref-napi";
import {GPhoto2Driver} from "../GPhoto2Driver";
import {getGPhoto2Driver} from "../GPhoto2Driver";
import {GPCodes, PointerOf} from "../types";

/**
Expand All @@ -10,7 +10,7 @@ import {GPCodes, PointerOf} from "../types";
*/
export function checkCode(returnValue: any, method = ""): any {
if (returnValue < GPCodes.GP_OK) {
const errorStr = GPhoto2Driver.gp_port_result_as_string(returnValue);
const errorStr = getGPhoto2Driver().gp_port_result_as_string(returnValue);
throw new Error(`${method} returned ${returnValue}: ${GPCodes[returnValue] || "Unsupported code"} > ${errorStr}`);
}

Expand Down
9 changes: 4 additions & 5 deletions packages/gphoto2-driver/src/components/AbilitiesList.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {checkCode, GPhoto2Driver} from "@tsed/gphoto2-core";
import {PointerAbilitiesList, RefAbilitiesList} from "@tsed/gphoto2-core";
import {checkCode, getGPhoto2Driver, PointerAbilitiesList, RefAbilitiesList} from "@tsed/gphoto2-core";
import {Context} from "./Context";
import {List} from "./List";
import {PointerWrapper} from "./PointerWrapper";
Expand All @@ -11,14 +10,14 @@ export class AbilitiesList extends PointerWrapper<PointerAbilitiesList> {
}

get size(): number {
return checkCode(GPhoto2Driver.gp_abilities_list_count(this.pointer), "gp_abilities_list_count");
return checkCode(getGPhoto2Driver().gp_abilities_list_count(this.pointer), "gp_abilities_list_count");
}

/**
*
*/
load(): this {
checkCode(GPhoto2Driver.gp_abilities_list_load(this.pointer, Context.get().pointer), "gp_abilities_list_load");
checkCode(getGPhoto2Driver().gp_abilities_list_load(this.pointer, Context.get().pointer), "gp_abilities_list_load");

return this;
}
Expand All @@ -32,7 +31,7 @@ export class AbilitiesList extends PointerWrapper<PointerAbilitiesList> {
const list = new List();

checkCode(
GPhoto2Driver.gp_abilities_list_detect(this.pointer, portInfoList.pointer, list.pointer, Context.get().pointer),
getGPhoto2Driver().gp_abilities_list_detect(this.pointer, portInfoList.pointer, list.pointer, Context.get().pointer),
"gp_abilities_list_detect"
);

Expand Down
6 changes: 3 additions & 3 deletions packages/gphoto2-driver/src/components/CameraFilePath.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import {
checkCode,
Closeable,
closeQuietly,
getGPhoto2Driver,
GPCameraFileType,
GPhoto2Driver,
PointerCamera,
PointerOf,
StructCameraFilePath
Expand Down Expand Up @@ -51,7 +51,7 @@ export class CameraFilePath implements Closeable {
const path = this.path;
const filepath = this.filename;

const result = GPhoto2Driver.gp_camera_file_get(
const result = getGPhoto2Driver().gp_camera_file_get(
pCamera,
path,
filepath,
Expand Down Expand Up @@ -81,7 +81,7 @@ export class CameraFilePath implements Closeable {
const path = this.path;
const filepath = this.filename;

const result = await GPhoto2Driver.gp_camera_file_get_async(
const result = await getGPhoto2Driver().gp_camera_file_get_async(
pCamera,
path,
filepath,
Expand Down
Loading

0 comments on commit 196152d

Please sign in to comment.