Skip to content

Commit

Permalink
Merge pull request #33 from TypedProject/fix-coveralls
Browse files Browse the repository at this point in the history
  • Loading branch information
Romakita committed Apr 21, 2021
2 parents e30d1cd + bbd06bc commit 9b166d0
Show file tree
Hide file tree
Showing 26 changed files with 321 additions and 126 deletions.
5 changes: 1 addition & 4 deletions .gflowrc
@@ -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"
}
}
20 changes: 18 additions & 2 deletions .github/workflows/build.yml
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 @@ -44,7 +44,23 @@ jobs:
- name: Install dependencies
run: yarn install --frozen-lockfile --network-timeout 500000 --ignore-engines
- name: Run test
run: yarn test:coverage && (yarn coveralls || true)
run: yarn test:coverage
- name: Coveralls
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
flag-name: run-${{ matrix.test_number }}
parallel: true

coveralls:
needs: test
runs-on: ubuntu-latest
steps:
- name: Coveralls Finished
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
parallel-finished: true

build:
runs-on: ubuntu-latest
Expand Down
2 changes: 1 addition & 1 deletion README.md
@@ -1,7 +1,7 @@
# ts-gphoto2-driver

[![Build & Release](https://github.com/TypedProject/ts-gphoto2-driver/actions/workflows/build.yml/badge.svg)](https://github.com/TypedProject/ts-gphoto2-driver/actions/workflows/build.yml)
[![Coverage Status](https://coveralls.io/repos/github/TypedProject/ts-gphoto2-driver/badge.svg?branch=master)](https://coveralls.io/github/TypedProject/ts-gphoto2-driver?branch=master)
[![Coverage Status](https://coveralls.io/repos/github/TypedProject/ts-gphoto2-driver/badge.svg?branch=production)](https://coveralls.io/github/TypedProject/ts-gphoto2-driver?branch=production)
![npm](https://img.shields.io/npm/dm/%40tsed%2Fgphoto2-driver.svg)
[![npm version](https://badge.fury.io/js/%40tsed%2Fgphoto2-driver.svg)](https://badge.fury.io/js/%40tsed%2Fgphoto2-driver)
[![Dependencies](https://david-dm.org/typedproject/ts-gphoto2-driver.svg)](https://david-dm.org/typedproject/ts-gphoto2-driver#info=dependencies)
Expand Down
14 changes: 7 additions & 7 deletions jest.config.js
Expand Up @@ -10,7 +10,7 @@ module.exports = {
collectCoverage: true,

// An array of glob patterns indicating a set of files for which coverage information should be collected
// collectCoverageFrom: undefined,
collectCoverageFrom: ["packages/gphoto2-*/src/**"],

// The directory where Jest should output its coverage files
coverageDirectory: "coverage",
Expand All @@ -23,12 +23,12 @@ module.exports = {
},
// An object that configures minimum threshold enforcement for coverage results
coverageThreshold: {
// global: {
// branches: 70,
// functions: 70,
// lines: 70,
// statements: 70
// }
global: {
branches: 15.31,
functions: 9.91,
lines: 23.17,
statements: 22.91
}
},

// An array of file extensions your modules use
Expand Down
6 changes: 4 additions & 2 deletions packages/gphoto2-core/package.json
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
2 changes: 1 addition & 1 deletion packages/gphoto2-core/readme.md
@@ -1,7 +1,7 @@
# @tsed/gphoto2-core

[![Build & Release](https://github.com/TypedProject/ts-gphoto2-driver/actions/workflows/build.yml/badge.svg)](https://github.com/TypedProject/ts-gphoto2-driver/actions/workflows/build.yml)
[![Coverage Status](https://coveralls.io/repos/github/TypedProject/ts-gphoto2-driver/badge.svg?branch=master)](https://coveralls.io/github/TypedProject/ts-gphoto2-driver?branch=master)
[![Coverage Status](https://coveralls.io/repos/github/TypedProject/ts-gphoto2-driver/badge.svg?branch=production)](https://coveralls.io/github/TypedProject/ts-gphoto2-driver?branch=production)
![npm](https://img.shields.io/npm/dm/%40tsed%2Fgphoto2-core.svg)
[![npm version](https://badge.fury.io/js/%40tsed%2Fgphoto2-core.svg)](https://badge.fury.io/js/%tsed%2Fgphoto2-core)
[![Dependencies](https://david-dm.org/typedproject/ts-gphoto2-driver.svg)](https://david-dm.org/typedproject/ts-gphoto2-driver#info=dependencies)
Expand Down
27 changes: 19 additions & 8 deletions packages/gphoto2-core/src/GPhoto2Driver.ts
@@ -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
@@ -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
@@ -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
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
@@ -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
@@ -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
@@ -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
2 changes: 1 addition & 1 deletion packages/gphoto2-driver/readme.md
@@ -1,7 +1,7 @@
# ts-gphoto2-driver

[![Build & Release](https://github.com/TypedProject/ts-gphoto2-driver/actions/workflows/build.yml/badge.svg)](https://github.com/TypedProject/ts-gphoto2-driver/actions/workflows/build.yml)[![npm version](https://badge.fury.io/js/%40typedproject%2Fgphoto2-driver.svg)](https://badge.fury.io/js/%40typedproject%2Fgphoto2-driver)
[![Coverage Status](https://coveralls.io/repos/github/TypedProject/ts-gphoto2-driver/badge.svg?branch=master)](https://coveralls.io/github/TypedProject/ts-gphoto2-driver?branch=master)
[![Coverage Status](https://coveralls.io/repos/github/TypedProject/ts-gphoto2-driver/badge.svg?branch=production)](https://coveralls.io/github/TypedProject/ts-gphoto2-driver?branch=production)
![npm](https://img.shields.io/npm/dm/%40tsed%2Fgphoto2-driver.svg)
[![npm version](https://badge.fury.io/js/%40tsed%2Fgphoto2-driver.svg)](https://badge.fury.io/js/%40tsed%2Fgphoto2-driver)
[![Dependencies](https://david-dm.org/typedproject/ts-gphoto2-driver.svg)](https://david-dm.org/typedproject/ts-gphoto2-driver#info=dependencies)
Expand Down

0 comments on commit 9b166d0

Please sign in to comment.