Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix!: testing + linting technical debt #945

Merged
merged 9 commits into from
Mar 1, 2023
5 changes: 5 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,10 @@
"@typescript-eslint/no-empty-function": 0,
"react/prop-types": 0,
"@typescript-eslint/no-non-null-assertion": 0
},
"settings": {
"react": {
"version": "detect"
}
}
}
25 changes: 25 additions & 0 deletions jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import type {Config} from 'jest';

const config: Config = {
coveragePathIgnorePatterns: [
"/node_modules/"
],
coverageThreshold: {
global: {
branches: 80,
functions: 80,
lines: 80,
statements: -10
}
},
preset: "ts-jest",
testPathIgnorePatterns: [
"/node_modules/",
"/__fixtures__/",
"<rootDir>/build"
],
testEnvironment: "jsdom",
setupFilesAfterEnv: ["<rootDir>/jest.setup.ts"],
};

export default config;
5 changes: 5 additions & 0 deletions jest.setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import failOnConsole from 'jest-fail-on-console'

failOnConsole({
shouldFailOnWarn: false,
});
41 changes: 12 additions & 29 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,50 +19,33 @@
"generate-docs": "typedoc --out docs src",
"bundlewatch": "bundlewatch --config .bundlewatch.config.json"
},
"jest": {
"coveragePathIgnorePatterns": [
"/node_modules/"
],
"coverageThreshold": {
"global": {
"branches": 80,
"functions": 80,
"lines": 80,
"statements": -10
}
},
"preset": "ts-jest",
"testPathIgnorePatterns": [
"/node_modules/",
"/__fixtures__/",
"<rootDir>/build"
]
},
"dependencies": {
"oidc-client-ts": "^2.0.5"
},
"devDependencies": {
"@testing-library/jest-dom": "^5.4.0",
"@testing-library/react": "^11.0.4",
"@testing-library/jest-dom": "5.16.5",
"@testing-library/react": "14.0.0",
"@types/faker": "^6.6.9",
"@types/jest": "^26.0.10",
"@types/jest": "29.4.0",
"@types/node": "^17.0.29",
"@types/react": "^18.0.8",
"@typescript-eslint/eslint-plugin": "^4.2.0",
"@typescript-eslint/parser": "^4.2.0",
"@typescript-eslint/eslint-plugin": "5.54.0",
"@typescript-eslint/parser": "5.54.0",
"bundlewatch": "^0.3.2",
"eslint": "^7.9.0",
"eslint-config-airbnb-base": "^14.1.0",
"eslint-config-prettier": "^8.1.0",
"eslint-plugin-import": "^2.18.0",
"eslint-plugin-jest": "^26.7.0",
"eslint-plugin-jest": "27.2.1",
"eslint-plugin-react": "^7.19.0",
"faker": "^6.6.6",
"jest": "^25.3.0",
"jest-cli": "^26.0.1",
"jest": "29.4.3",
"jest-cli": "29.4.3",
"jest-environment-jsdom": "29.4.3",
"jest-fail-on-console": "3.0.2",
"react": "^18.1.0",
"react-dom": "^18.1.0",
"ts-jest": "^25.3.1",
"ts-jest": "29.0.5",
"ts-node-dev": "^1.0.0-pre.40",
"typedoc": "0.23.24",
"typedoc-plugin-markdown": "3.14.0",
Expand All @@ -72,4 +55,4 @@
"react": "^16.8.0 || ^17.0.0 || ^18.0.0",
"react-dom": "^16.8.0 || || ^17.0.0 || ^18.0.0"
}
}
}
16 changes: 7 additions & 9 deletions src/AuthContext.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { FC, useState, useEffect, useRef, PropsWithChildren, useMemo, useCallback } from 'react';
import { UserManager, User } from 'oidc-client-ts';
import { UserManager, User, SigninRedirectArgs, SignoutRedirectArgs } from 'oidc-client-ts';
import {
Location,
AuthProviderProps,
Expand Down Expand Up @@ -105,15 +105,15 @@ export const AuthProvider: FC<PropsWithChildren<AuthProviderProps>> = ({
}, []);

useEffect(() => {
const getUser = async (): Promise<void> => {
(async () => {
// Store current isMounted since this could change while awaiting async operations below
const isMounted = isMountedRef.current;

/**
* Check if the user is returning back from OIDC.
*/
if (hasCodeInUrl(location)) {
const user: any = await userManager.signinCallback();
const user = await userManager.signinCallback() || null;
simenandre marked this conversation as resolved.
Show resolved Hide resolved
setUserData(user);
setIsLoading(false);
onSignIn && onSignIn(user);
Expand All @@ -128,9 +128,7 @@ export const AuthProvider: FC<PropsWithChildren<AuthProviderProps>> = ({
setUserData(user);
setIsLoading(false);
}
return;
};
getUser();
})();
}, [location, userManager, autoSignIn, onBeforeSignIn, onSignIn]);

useEffect(() => {
Expand All @@ -147,7 +145,7 @@ export const AuthProvider: FC<PropsWithChildren<AuthProviderProps>> = ({

const value = useMemo<AuthContextProps>(() => {
return {
signIn: async (args: any): Promise<void> => {
signIn: async (args?: SigninRedirectArgs): Promise<void> => {
simenandre marked this conversation as resolved.
Show resolved Hide resolved
await userManager.signinRedirect(args);
},
signInPopup: async (): Promise<void> => {
Expand All @@ -157,7 +155,7 @@ export const AuthProvider: FC<PropsWithChildren<AuthProviderProps>> = ({
await userManager!.removeUser();
await signOutHooks();
},
signOutRedirect: async (args?: any): Promise<void> => {
signOutRedirect: async (args?: SignoutRedirectArgs): Promise<void> => {
await userManager!.signoutRedirect(args);
await signOutHooks();
},
Expand All @@ -172,4 +170,4 @@ export const AuthProvider: FC<PropsWithChildren<AuthProviderProps>> = ({
{children}
</AuthContext.Provider>
);
};
};
8 changes: 4 additions & 4 deletions src/AuthContextInterface.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {UserManager, User, PopupWindowFeatures} from 'oidc-client-ts';
import {UserManager, User, PopupWindowFeatures, SigninRedirectArgs, SignoutRedirectArgs} from 'oidc-client-ts';
export interface Location {
search: string;
hash: string;
Expand Down Expand Up @@ -124,7 +124,7 @@ export interface AuthContextProps {
/**
* Alias for userManager.signInRedirect
*/
signIn: (args?: unknown) => Promise<void>;
signIn: (args?: SigninRedirectArgs) => Promise<void>;
/**
* Alias for userManager.signinPopup
*/
Expand All @@ -136,7 +136,7 @@ export interface AuthContextProps {
/**
*
*/
signOutRedirect: (args?: unknown) => Promise<void>;
signOutRedirect: (args?: SignoutRedirectArgs) => Promise<void>;
simenandre marked this conversation as resolved.
Show resolved Hide resolved
/**
* See [UserManager](https://authts.github.io/oidc-client-ts/classes/UserManager.html) for more details.
*/
Expand All @@ -149,4 +149,4 @@ export interface AuthContextProps {
* Auth state: True until the library has been initialized.
*/
isLoading: boolean;
}
}
Loading