Skip to content

Commit

Permalink
Deps update and code coverage updates.
Browse files Browse the repository at this point in the history
- Progress on code coverage.
  • Loading branch information
elycruz committed Nov 9, 2023
1 parent 05c11fd commit 1d8fe7b
Show file tree
Hide file tree
Showing 12 changed files with 936 additions and 829 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

# Files
*.log
#**/src/**/*.js
**/src/**/*.js.map

**/.local*
22 changes: 11 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,24 @@
"description": "",
"private": true,
"devDependencies": {
"@rollup/plugin-node-resolve": "^15.1.0",
"@rollup/plugin-terser": "^0.4.3",
"@rollup/plugin-typescript": "^11.1.2",
"@types/jest": "^29.5.3",
"@types/node": "^18.17.1",
"@rollup/plugin-node-resolve": "^15.2.3",
"@rollup/plugin-terser": "^0.4.4",
"@rollup/plugin-typescript": "^11.1.5",
"@types/jest": "^29.5.8",
"@types/node": "^18.18.9",
"@typescript-eslint/eslint-plugin": "^5.62.0",
"@typescript-eslint/parser": "^5.62.0",
"del": "^7.0.0",
"eslint": "^8.46.0",
"jest": "^29.6.2",
"jest-cli": "^29.6.2",
"del": "^7.1.0",
"eslint": "^8.53.0",
"jest": "^29.7.0",
"jest-cli": "^29.7.0",
"jest-puppeteer": "^8.0.6",
"puppeteer": "^19.11.1",
"rollup": "^2.79.1",
"ts-jest": "^29.1.1",
"ts-node": "^10.9.1",
"tslib": "^2.6.1",
"typescript": "^5.1.6"
"tslib": "^2.6.2",
"typescript": "^5.2.2"
},
"scripts": {
"eslint": "eslint -c .eslintrc.json",
Expand Down
4 changes: 3 additions & 1 deletion packages/fjl/src/boolean/alwaysFalse.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/**
* Returns `false`.
*
* @returns {boolean}
*/
export const alwaysFalse = () => false;
export const alwaysFalse = (): boolean => false;

5 changes: 3 additions & 2 deletions packages/fjl/src/boolean/alwaysTrue.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/**
* Returns `true`.
*
* @returns {boolean}
*/
export const alwaysTrue = () => true;

export const alwaysTrue = (): boolean => true;
4 changes: 2 additions & 2 deletions packages/fjl/src/boolean/equal.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/**
* Equality combinator.
*/
export const equal = (a, b) => a === b,
export const equal = (a: any, b: any) => a === b,

/**
* Curried version of `equal`
*/
$equal = a => b => a === b;
$equal = (a: any) => (b: any) => a === b;
4 changes: 3 additions & 1 deletion packages/fjl/src/boolean/isFalsy.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@

/**
* Returns whether `value` is 'falsy' or not
*
* @returns {boolean}
*/
export const isFalsy = value => !value;
export const isFalsy = (value: any): boolean => !value;

3 changes: 2 additions & 1 deletion packages/fjl/src/boolean/isTruthy.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

/**
* Returns whether `value` is 'truthy' or not.
*
* @returns {boolean}
*/
export const isTruthy = Boolean;
9 changes: 9 additions & 0 deletions packages/fjl/src/function/fnOrError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@ export const
return f;
},

/**
* @deprecated Check for your error in place instead.
*
* @param {string} symbolName
*
* @throws {Error} if given `f` is not a function.
*
* @returns {<T>(f: T) => T}
*/
$fnOrError = <T>(symbolName: string) => (f: T): T =>
fnOrError(symbolName, f)

Expand Down
2 changes: 1 addition & 1 deletion packages/fjl/src/object/defineProp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const
* errors when the `Type` is disobeyed.
*/
createTypedDescriptor = (Type: TypeRef, target: any, propName: string): PropertyDescriptor => {
let _value;
let _value: TypeRef;
return {
get: (): typeof Type => _value,
set: (value: typeof Type): void => {
Expand Down
8 changes: 7 additions & 1 deletion packages/fjl/tests/function/index_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {
truthyList
} from "../helpers";
import {flip, flip3, flip4, flip5, flipN} from "../../src/function/flip";
import {fnOrError} from "../../src/function/fnOrError";
import {$fnOrError, fnOrError} from "../../src/function/fnOrError";
import {id} from "../../src/function/id";
import {negateF, negateF2, negateF3, negateFN} from "../../src/function/negate";
import {noop} from "../../src/function/noop";
Expand Down Expand Up @@ -319,18 +319,24 @@ describe('#flip5', () => {
describe('#fnOrError', () => {
it('should be a function', () => {
expect(fnOrError).toBeInstanceOf(Function);
expect($fnOrError).toBeInstanceOf(Function);
});
it('should have an arity of 2', () => {
expect(fnOrError.length).toEqual(2);
expect($fnOrError.length).toEqual(1);
expect($fnOrError(null).length).toEqual(1);
});
it('should throw an error when not receiving a function', () => {
falsyList.forEach(f => {
expect(() => fnOrError('f', f)).toThrow();
expect(() => $fnOrError('f')(f)).toThrow();
});
});
it('should not throw an error when receiving a function', () => {
const result = fnOrError('fnOrError', fnOrError);
const result2 = $fnOrError('fnOrError')($fnOrError);
expect(result).toBeInstanceOf(Function);
expect(result2).toBeInstanceOf(Function);
});
});

Expand Down
172 changes: 98 additions & 74 deletions packages/fjl/tests/object/index_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
* @todo Continue tests refactor (from `isEmpty` tests downward).
*/
import {
$defineEnumProp,
$defineProp,
assign,
assignDeep,
createTypedDescriptor,
Expand Down Expand Up @@ -980,84 +982,106 @@ describe('#object', function () {

describe('#defineProp', function () {
const someTarget = {},
propName = 'someNum',
[target, descriptor] = defineProp(Number, [someTarget], propName);
it('should return a `target` and `descriptor` pair (tuple)', function () {
expect(target).toEqual(someTarget);
expect(!!descriptor).toEqual(true);
});
it('should define property `propName` on `target`', function () {
expect(hasOwnProperty(propName, target)).toEqual(true);
});
it('should return a target whose defined `propName` throws an error when ' +
'the wrong type is passed in', function () {
expect(() => {
target[propName] = 'some value';
}).toThrow(Error);
});
it('should return a target whose defined `propName` doesn\'t throw' +
'an error when the correct type of value is passed in', function () {
target[propName] = 99;
expect(target[propName]).toEqual(99);
});
it('should allow the user to pass in his/her own `descriptor`', function () {
const somePropName = 'somePropName',
someValue = (new Date()).getTime(),
customDescriptor = {
value: someValue,
enumerable: true
},
[target2, descriptor2] = defineProp(Number, [someTarget, customDescriptor], somePropName);
expect(() => {
target2[somePropName] = 99;
}).toThrow(Error);
expect(target2[somePropName]).toEqual(someValue);
expect(descriptor2).toEqual(customDescriptor);
expect(descriptor2.enumerable).toEqual(true);
});
someTarget2 = {},
propName = 'someNum';
(<[any, [any, PropertyDescriptor]][]>[
[someTarget, defineProp(Number, [someTarget], propName)],
[someTarget2, $defineProp(Number)([someTarget2])(propName)]
])
.forEach(([originalTrgt, [target, descriptor]]) => {
it('should return a `target` and `descriptor` pair (tuple)', function () {
expect(target).toEqual(originalTrgt);
expect(!!descriptor).toEqual(true);
});

it('should define property `propName` on `target`', function () {
expect(hasOwnProperty(propName, target)).toEqual(true);
});

it('should return a target whose defined `propName` throws an error when ' +
'the wrong type is passed in', function () {
expect(() => {
target[propName] = 'some value';
}).toThrow(Error);
});

it('should return a target whose defined `propName` doesn\'t throw' +
'an error when the correct type of value is passed in', function () {
target[propName] = 99;
expect(target[propName]).toEqual(99);
});

it('should allow the user to pass in his/her own `descriptor`', function () {
const somePropName = 'somePropName',
someValue = (new Date()).getTime(),
customDescriptor = {
value: someValue,
enumerable: true
},
[target2, descriptor2] = defineProp(Number, [originalTrgt, customDescriptor], somePropName);
expect(() => {
target2[somePropName] = 99;
}).toThrow(Error);
expect(target2[somePropName]).toEqual(someValue);
expect(descriptor2).toEqual(customDescriptor);
expect(descriptor2.enumerable).toEqual(true);
});
});
});

describe('#defineEnumProp', function () {
const someTarget = {},
propName = 'someNum',
[target, descriptor] = defineEnumProp(Number, [someTarget], propName);
it('should return a `target` and `descriptor` pair (tuple)', function () {
expect(target).toEqual(someTarget);
expect(!!descriptor).toEqual(true);
});
it('should define property `propName` on `target`', function () {
expect(hasOwnProperty(propName, target)).toEqual(true);
});
it('should set `enumerable` to `true` on returned descriptor', function () {
expect(descriptor.enumerable).toEqual(true);
expect(Object.getOwnPropertyDescriptor(target, propName).enumerable).toEqual(true);
});
it('should return a target whose defined `propName` throws an error when ' +
'the wrong type is passed in', function () {
expect(() => {
target[propName] = 'some value';
}).toThrow(Error);
});
it('should return a target whose defined `propName` doesn\'t throw' +
'an error when the correct type of value is passed in', function () {
target[propName] = 99;
expect(target[propName]).toEqual(99);
});
it('should allow the user to pass in his/her own `descriptor`', function () {
const somePropName = 'somePropName',
someValue = (new Date()).getTime(),
customDescriptor = {
value: someValue,
enumerable: false
},
[target2, descriptor2] = defineEnumProp(Number, [someTarget, customDescriptor], somePropName);
expect(() => {
target2[somePropName] = 99;
}).toThrow(Error);
expect(target2[somePropName]).toEqual(someValue);
expect(descriptor2).toEqual(customDescriptor);
expect(descriptor2.enumerable).toEqual(true);
});
someTarget2 = {},
propName = 'someNum';

(<[any, [any, PropertyDescriptor]][]>[
[someTarget, defineEnumProp(Number, [someTarget], propName)],
[someTarget2, $defineEnumProp(Number)([someTarget2])(propName)],
])
.forEach(([originalTrgt, [target, descriptor]]) => {
it('should return a `target` and `descriptor` pair (tuple)', function () {
expect(target).toEqual(originalTrgt);
expect(!!descriptor).toEqual(true);
});

it('should define property `propName` on `target`', function () {
expect(hasOwnProperty(propName, target)).toEqual(true);
});

it('should set `enumerable` to `true` on returned descriptor', function () {
expect(descriptor.enumerable).toEqual(true);
expect(Object.getOwnPropertyDescriptor(target, propName).enumerable).toEqual(true);
});

it('should return a target whose defined `propName` throws an error when ' +
'the wrong type is passed in', function () {
expect(() => {
target[propName] = 'some value';
}).toThrow(Error);
});

it('should return a target whose defined `propName` doesn\'t throw' +
'an error when the correct type of value is passed in', function () {
target[propName] = 99;
expect(target[propName]).toEqual(99);
});

it('should allow the user to pass in his/her own `descriptor`', function () {
const somePropName = 'somePropName',
someValue = (new Date()).getTime(),
customDescriptor = {
value: someValue,
enumerable: false
},
[target2, descriptor2] = defineEnumProp(Number, [originalTrgt, customDescriptor], somePropName);
expect(() => {
target2[somePropName] = 99;
}).toThrow(Error);
expect(target2[somePropName]).toEqual(someValue);
expect(descriptor2).toEqual(customDescriptor);
expect(descriptor2.enumerable).toEqual(true);
});
});
});

describe('#defineProps', function () {
Expand Down
Loading

0 comments on commit 1d8fe7b

Please sign in to comment.