Skip to content

Commit

Permalink
unit testing updates
Browse files Browse the repository at this point in the history
  • Loading branch information
steveswork committed May 31, 2024
1 parent 58f9da4 commit c861c2c
Show file tree
Hide file tree
Showing 22 changed files with 19,636 additions and 16,280 deletions.
25 changes: 25 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
module.exports = {
collectCoverageFrom: [
'src/**/*.ts'
],
coveragePathIgnorePatterns: [
'src/constants',
'src/test-artifacts',
'src/main/test-apps',
'src/index.ts'
],
globals: {
'ts-jest': {
tsConfig: 'tsconfig.json',
diagnostics: false,
},
},
testEnvironment: 'jsdom',
testEnvironmentOptions: {
url: 'http://localhost/'
},
transform: {
'\\.[jt]sx?$': 'ts-jest'
}
};

32,165 changes: 17,592 additions & 14,573 deletions package-lock.json

Large diffs are not rendered by default.

81 changes: 49 additions & 32 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
"steveswork <stephen.isienyi@gmail.com> (https://github.com/steveswork)"
],
"dependencies": {
"-": "^0.0.1",
"@webkrafters/auto-immutable": "^1.0.0",
"@webkrafters/clone-total": "0.0.4",
"@webkrafters/data-distillery": "0.0.3",
"@webkrafters/get-property": "^1.1.2",
"@webkrafters/path-dotize": "0.0.2",
"lodash.clonedeepwith": "^4.5.0",
"lodash.isboolean": "^3.0.3",
"lodash.isempty": "^4.4.0",
"lodash.isequal": "^4.5.0",
Expand All @@ -29,50 +29,68 @@
"@babel/plugin-transform-runtime": "^7.17.0",
"@babel/preset-env": "^7.20.2",
"@babel/preset-react": "^7.18.6",
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^13.4.0",
"@testing-library/react-hooks": "^8.0.1",
"@testing-library/jest-dom": "^6.4.5",
"@testing-library/react": "^15.0.7",
"@testing-library/user-event": "^14.4.3",
"@types/jest": "^29.5.12",
"@types/jest-cli": "^24.3.0",
"@types/node": "^20.11.28",
"babel-jest": "^26.6.3",
"babel-loader": "^8.2.5",
"eslint": "^8.29.0",
"eslint-config-standard": "^16.0.2",
"babel-loader": "^9.1.3",
"eslint": "^8.57.0",
"eslint-config-standard": "^17.1.0",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-jest": "^26.0.0",
"eslint-plugin-jest": "^28.5.0",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-promise": "^4.2.1",
"eslint-plugin-promise": "^6.1.1",
"eslint-plugin-react": "^7.31.11",
"eslint-plugin-standard": "^5.0.0",
"jest": "^29.7.0",
"jest-cli": "^26.6.3",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"jest-cli": "^29.7.0",
"jest-environment-jsdom": "^29.7.0",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react-performance-testing": "^2.0.0",
"ts-jest": "^29.1.2",
"ts-node": "^10.9.2",
"typescript": "^4.8.2"
"typescript": "^5.4.5"
},
"files": [
"dist",
"logo.png"
"package.json",
"index.js",
"dist/test-artifacts/suppress-render-compat.js",
"dist/test-artifacts/suppress-render-compat.d.ts",
"dist/test-artifacts/data/create-state-obj.js",
"dist/test-artifacts/data/create-state-obj.d.ts",
"dist/model/storage/index.test.js",
"dist/model/storage/index.test.d.ts",
"dist/model/storage/index.js",
"dist/model/storage/index.d.ts",
"dist/main/test-apps/with-pure-children.js",
"dist/main/test-apps/with-pure-children.d.ts",
"dist/main/test-apps/with-connected-children.js",
"dist/main/test-apps/with-connected-children.d.ts",
"dist/main/test-apps/normal.js",
"dist/main/test-apps/normal.d.ts",
"dist/main/index.test.js",
"dist/main/index.test.d.ts",
"dist/main/index.js",
"dist/main/index.d.ts",
"dist/main/hooks/use-store/index.test.js",
"dist/main/hooks/use-store/index.test.d.ts",
"dist/main/hooks/use-store/index.js",
"dist/main/hooks/use-store/index.d.ts",
"dist/main/hooks/use-render-key-provider/index.test.js",
"dist/main/hooks/use-render-key-provider/index.test.d.ts",
"dist/main/hooks/use-render-key-provider/index.js",
"dist/main/hooks/use-render-key-provider/index.d.ts",
"dist/main/hooks/use-prehooks-ref/index.js",
"dist/main/hooks/use-prehooks-ref/index.d.ts",
"dist/index.js",
"dist/index.d.ts",
"dist/constants.js",
"dist/constants.d.ts"
],
"homepage": "https://eagleeye.js.org",
"jest": {
"collectCoverageFrom": [
"src/**/*.js"
],
"coveragePathIgnorePatterns": [
"src/test-artifacts",
"src/main/test-apps",
"src/types"
],
"transform": {
"\\.[jt]sx?$": "babel-jest"
}
},
"keywords": [
"connect",
"context",
Expand All @@ -95,8 +113,7 @@
"main": "dist/index.js",
"name": "@webkrafters/react-observable-context",
"peerDependencies": {
"@types/react": ">= 16.8.0",
"react": ">= 16.8.0"
"@types/react": ">= 16.8.0"
},
"publishConfig": {
"access": "public"
Expand All @@ -115,4 +132,4 @@
},
"types": "dist/index.d.ts",
"version": "5.0.0"
}
}
168 changes: 84 additions & 84 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import type {
ComponentType,
Context,
ForwardRefExoticComponent as FREC,
MemoExoticComponent as MEC,
PropsWithRef,
ReactNode,
RefAttributes
Context,
ForwardRefExoticComponent,
MemoExoticComponent,
ReactNode,
RefAttributes
} from 'react';

import type {
Expand Down Expand Up @@ -34,129 +32,131 @@ export type {
UpdatePayloadArray
} from '@webkrafters/auto-immutable';

export type ObservableContext<
T extends State,
SELECTOR_MAP extends SelectorMap<T> = SelectorMap<T>
> = IObservableContext<T>|PublicObservableContext<T, SELECTOR_MAP>;
export type ObservableContext<T extends State> = IObservableContext<T> | PublicObservableContext<T>;

export type PublicObservableContext<
T extends State,
SELECTOR_MAP extends SelectorMap<T> = SelectorMap<T>
> = WithObservableProvider<Context<Store<T, SELECTOR_MAP>>, T>;
export type PublicObservableContext<T extends State> = WithObservableProvider<Context<Store<T>>, T>;

export type IObservableContext<T extends State> = WithObservableProvider<Context<IStore>, T>;

export type WithObservableProvider<
LOCAL_DATA extends {} = {},
LOCAL_DATA extends Record<any, any> = {},
T extends State = State
> = LOCAL_DATA & {Provider: ObservableProvider<T>};

export type ObservableProvider<T extends State> = ForwardRefExoticComponent<ProviderProps<T>, StoreRef<T>>;

export interface ProviderProps<T extends State>{
children? : ReactNode;
prehooks? : Prehooks<T>;
storage? : IStorage<T>;
value : PartialState<T>;
> = LOCAL_DATA & { Provider: ObservableProvider<T> };

export type ObservableProvider<T extends State> = ForwardRefExoticComponent<
ProviderProps<T> &
RefAttributes<StoreRef<T>>
>;

export interface ProviderProps<T extends State> {
children?: ReactNode;
prehooks?: Prehooks<T>;
storage?: IStorage<T>;
value: PartialState<T>;
};

export type ConnectedComponentProps<
OWNPROPS extends OwnProps<State> = OwnProps,
STORE extends Store<State> = Store<State>
> = STORE & OWNPROPS;
export type ConnectProps<
OWNPROPS extends OwnProps = IProps,
STATE extends State = State,
SELECTOR_MAP extends SelectorMap = SelectorMap
> = { [K in keyof Store<STATE, SELECTOR_MAP>]: Store<STATE, SELECTOR_MAP>[K] }
& Omit<OWNPROPS, "ref">
& React.RefAttributes<OWNPROPS["ref"]>;

export type ConnectedComponent<
OWNPROPS extends OwnProps<State> = OwnProps,
STORE extends Store<State> = Store<State>
> = MemoExoticComponent<FREC<ConnectedComponentProps<OWNPROPS, STORE>>>;
export type ConnectedComponent<P extends OwnProps = IProps> = MemoExoticComponent<
React.ForwardRefExoticComponent<
React.PropsWithoutRef<Omit<P, "ref">>
& React.RefAttributes<P["ref"]>
>
>;

export type OwnProps<P extends State = {}> = PropsWithRef<P>;
export interface IProps { ref?: unknown }

export type ForwardRefExoticComponent<P, T> = FREC<PropsWithRef<P> & RefAttributes<T>>
export type OwnProps = IProps & Record<any, any>;

export type MemoExoticComponent<P={}> = MEC<ComponentType<P>>
export type Text = string | number;

export type FullStateSelector = typeof FULL_STATE_SELECTOR;

export type BaseSelectorMap<T=State> = Array<
string | keyof T | FullStateSelector
> | ({
[dataPropKey : string] : string| keyof T
} & {
[dataPropKey : string] : FullStateSelector
});
export type ObjectSelector = Record<Text, Text | FullStateSelector>;

export type SelectorMap<T extends State = State> = BaseSelectorMap<T>;
export type ArraySelector = Array<Text | FullStateSelector>;

export type Data<SELECTOR_MAP extends SelectorMap = SelectorMap> = {
[selectorKey in keyof SELECTOR_MAP] : Readonly<unknown>
};
export type SelectorMap = ObjectSelector | ArraySelector | void;

export type Data<SELECTOR_MAP extends SelectorMap> = (
SELECTOR_MAP extends ObjectSelector
? { [selectorKey in keyof SELECTOR_MAP]: Readonly<any> }
: SELECTOR_MAP extends ArraySelector
? { [selectorKey: number]: Readonly<any> }
: never
);

export type Changes<T extends State = State> = BaseChanges<T>;

export interface IStorage<T extends State> {
clone : (data : T) => T;
getItem : (key : string) => T;
removeItem : (key : string) => void;
setItem : (key : string, data : T) => void;
export interface IStorage<T extends State = State> {
clone: (data: T) => T;
getItem: (key: string) => T;
removeItem: (key: string) => void;
setItem: (key: string, data: T) => void;
};

export type NonReactUsageReport = (...args : Array<unknown>) => void;
export type Listener = <T extends State>(changes : Changes<T>) => void;
export type NonReactUsageReport = (...args: Array<unknown>) => void;

export type Listener = <T extends State>(changes: Changes<T>) => void;

export type PartialState<T extends State> = Partial<T>;

export interface Prehooks<T extends State> {
resetState? : (
resetData : PartialState<T>,
state : {
current : T;
original : T;
}
export interface Prehooks<T extends State = State> {
resetState?: (
resetData: PartialState<T>,
state: {
current: T;
original: T;
}
) => boolean;
setState?: (newChanges : Changes<T>) => boolean;
setState?: (newChanges: Changes<T>) => boolean;
};

export type Unsubscribe = ( ...args : Array<unknown> ) => void;
export type Unsubscribe = (...args: Array<unknown>) => void;

export interface IStore {
resetState : Function;
setState : Function;
resetState: Function;
setState: Function;
}

export interface IStoreInternal extends IStore {
subscribe : Function;
subscribe: Function;
}

export interface Store<
T extends State,
SELECTOR_MAP extends SelectorMap<T> = SelectorMap<T>
SELECTOR_MAP extends SelectorMap = SelectorMap
> extends IStore {
data : Data<SELECTOR_MAP>;
resetState : (propertyPaths? : Array<string>) => void;
setState : (changes : Changes<T>) => void;
data: Data<SELECTOR_MAP>;
resetState: (propertyPaths?: Array<string>) => void;
setState: (changes: Changes<T>) => void;
};

export interface StoreInternal<T extends State> extends IStoreInternal {
cache : Immutable<T>,
resetState : ( connection : Connection<T>, propertyPaths? : Array<string> ) => void;
setState : ( connection : Connection<T>, changes : Changes<T> ) => void;
subscribe : ( listener : Listener ) => Unsubscribe;
cache: Immutable<T>,
resetState: (connection: Connection<T>, propertyPaths?: Array<string>) => void;
setState: (connection: Connection<T>, changes: Changes<T>) => void;
subscribe: (listener: Listener) => Unsubscribe;
};

export interface StorePlaceholder extends IStoreInternal {
getState : NonReactUsageReport;
resetState : NonReactUsageReport;
setState : NonReactUsageReport;
subscribe : NonReactUsageReport;
getState: NonReactUsageReport;
resetState: NonReactUsageReport;
setState: NonReactUsageReport;
subscribe: NonReactUsageReport;
};

export interface StoreRef<T extends State> extends StorePlaceholder {
getState : () => T,
resetState : ( propertyPaths? : string[] ) => void;
setState : ( changes : Changes<T> ) => void;
subscribe : ( listener : Listener ) => Unsubscribe;
export interface StoreRef<T extends State = State> extends StorePlaceholder {
getState: () => T,
resetState: (propertyPaths?: string[]) => void;
setState: (changes: Changes<T>) => void;
subscribe: (listener: Listener) => Unsubscribe;
}

export {
Expand Down
2 changes: 1 addition & 1 deletion src/main/hooks/use-prehooks-ref/index.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { renderHook } from '@testing-library/react-hooks';
import { renderHook } from '@testing-library/react';

import '../../../test-artifacts/suppress-render-compat';

Expand Down
Loading

0 comments on commit c861c2c

Please sign in to comment.