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

feat: vite migration #157

Merged
merged 3 commits into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"
yarn lint-staged
yarn test && yarn lint-staged && yarn run tsc -p .

npx --no-install lint-staged --verbose
36 changes: 18 additions & 18 deletions __mocks__/@auth0/auth0-spa-js.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,17 @@ export const getNewFakeToken = () => {
/*
* Mocked functions that can be imported to any test for mockResolve or mockReject values
*/
export const onRedirectCallback = jest.fn();
export const getTokenSilently = jest.fn();
export const loginWithRedirect = jest.fn();
export const getUser = jest.fn();
export const handleRedirectCallback = jest.fn(() => {
export const onRedirectCallback = vi.fn();
export const getTokenSilently = vi.fn();
export const loginWithRedirect = vi.fn();
export const getUser = vi.fn();
export const handleRedirectCallback = vi.fn(() => {
return { appState: '' };
});
export const isAuthenticated = jest.fn();
export const logout = jest.fn();
export const loginWithPopup = jest.fn();
export const Auth0Client = jest.fn().mockImplementation((options: any) => ({
export const isAuthenticated = vi.fn();
export const logout = vi.fn();
export const loginWithPopup = vi.fn();
export const Auth0Client = vi.fn((options: any) => ({
getTokenSilently,
loginWithRedirect,
loginWithPopup,
Expand All @@ -53,29 +53,29 @@ export const Auth0Client = jest.fn().mockImplementation((options: any) => ({
cacheLocation: 'localstorage',
httpTimeoutMs: 10000,
cookieStorage: {
get: jest.fn(),
save: jest.fn(),
remove: jest.fn(),
get: vi.fn(),
save: vi.fn(),
remove: vi.fn(),
},
orgHintCookieName: 'auth0..organization_hint',
isAuthenticatedCookieName: 'auth0..is.authenticated',
sessionCheckExpiryDays: 1,
scope: 'offline_access',
transactionManager: {
storage: {
get: jest.fn(),
save: jest.fn(),
remove: jest.fn(),
get: vi.fn(),
save: vi.fn(),
remove: vi.fn(),
},
clientId: '',
storageKey: 'a0.spajs.txs.',
transaction: null,
},
nowProvider: jest.fn(),
nowProvider: vi.fn(),
cacheManager: {
cache: {},
keyManifest: null,
nowProvider: jest.fn(),
nowProvider: vi.fn(),
},
domainUrl: 'https://',
tokenIssuer: 'https:///',
Expand All @@ -90,5 +90,5 @@ export const Auth0Client = jest.fn().mockImplementation((options: any) => ({

/*
* Mock auth0 client with predefined values
* All necessary functions are mocked jest.fn() that can be used to run tests internally.
* All necessary functions are mocked vi.fn() that can be used to run tests internally.
*/
58 changes: 45 additions & 13 deletions __mocks__/zustand.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,55 @@
import { act } from 'react-dom/test-utils';
import actualCreate from 'zustand';
// https://docs.pmnd.rs/zustand/guides/testing#vitest
import { act } from '@testing-library/react';
import * as zustand from 'zustand';

const { create: actualCreate, createStore: actualCreateStore } = await vi.importActual<
typeof zustand
>('zustand');

// a variable to hold reset functions for all stores declared in the app
const storeResetFns = new Set();
export const storeResetFns = new Set<() => void>();

const createUncurried = <T>(stateCreator: zustand.StateCreator<T>) => {
const store = actualCreate(stateCreator);
const initialState = store.getInitialState();
storeResetFns.add(() => {
store.setState(initialState, true);
});

return store;
};

// when creating a store, we get its initial state, create a reset function and add it in the set
const create = (createState: any) => {
if (!createState) return create;
const store = actualCreate(createState);
const initialState = store.getState();
storeResetFns.add(() => store.setState(initialState, true));
export const create = (<T>(stateCreator: zustand.StateCreator<T>) => {
// to support curried version of create
return typeof stateCreator === 'function' ? createUncurried(stateCreator) : createUncurried;
}) as typeof zustand.create;

const createStoreUncurried = <T>(stateCreator: zustand.StateCreator<T>) => {
const store = actualCreateStore(stateCreator);
const initialState = store.getInitialState();
storeResetFns.add(() => {
store.setState(initialState, true);
});

return store;
};

// Reset all stores after each test run
// when creating a store, we get its initial state, create a reset function and add it in the set
export const createStore = (<T>(stateCreator: zustand.StateCreator<T>) => {
console.log('zustand createStore mock');

// to support curried version of createStore
return typeof stateCreator === 'function'
? createStoreUncurried(stateCreator)
: createStoreUncurried;
}) as typeof zustand.createStore;

// reset all stores after each test run
afterEach(() => {
// @ts-ignore
act(() => storeResetFns.forEach((resetFn) => resetFn()));
act(() => {
storeResetFns.forEach((resetFn) => {
resetFn();
});
});
});

export default create;
25 changes: 0 additions & 25 deletions jest.config.cjs

This file was deleted.

60 changes: 30 additions & 30 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@
"name": "@orfium/toolbox",
"version": "0.0.0",
"type": "module",
"main": "dist/cjs/index.cjs",
"module": "dist/esm/index.js",
"types": "dist/cjs/index.d.ts",
"main": "dist/index.umd.cjs",
"module": "dist/index.js",
"types": "dist/src/index.d.ts",
"exports": {
".": {
"import": {
"types": "./dist/esm/index.d.ts",
"default": "./dist/esm/index.js"
"types": "./dist/src/index.d.ts",
"default": "./dist/index.js"
},
"require": {
"types": "./dist/cjs/index.d.ts",
"default": "./dist/cjs/index.cjs"
"types": "./dist/src/index.d.ts",
"default": "./dist/index.umd.cjs"
},
"default": "./dist/cjs/index.cjs"
"default": "./dist/index.umd.cjs"
}
},
"files": [
Expand All @@ -37,49 +37,48 @@
"@amanda-mitchell/semantic-release-npm-multiple": "^3.5.0",
"@commitlint/cli": "^16.2.4",
"@commitlint/config-conventional": "^16.2.4",
"@emotion/react": "^11.10.4",
"@emotion/styled": "^11.10.4",
"@orfium/ictinus": "5.7.0-rc.20",
"@rollup/plugin-typescript": "^8.3.2",
"@emotion/react": "^11.11.4",
"@emotion/styled": "^11.11.5",
"@orfium/ictinus": "5.7.0-rc.21",
"@semantic-release/changelog": "^6.0.1",
"@semantic-release/git": "^10.0.1",
"@sentry/browser": "7.21.1",
"@svgr/rollup": "^6.5.0",
"@testing-library/jest-dom": "^5.16.3",
"@testing-library/react": "^13.0.0",
"@testing-library/react-hooks": "^7.0.2",
"@testing-library/user-event": "^14.0.4",
"@types/jest": "^29.5.12",
"@testing-library/jest-dom": "^6.4.6",
"@testing-library/react": "^14.3.1",
"@testing-library/react-hooks": "^8.0.1",
"@testing-library/user-event": "^14.5.2",
"@types/jwt-encode": "^1.0.0",
"@types/react": "^17.0.44",
"@types/react-router-dom": "^5.1.7",
"@typescript-eslint/eslint-plugin": "^6.19.1",
"@typescript-eslint/parser": "^6.19.1",
"@vitejs/plugin-react": "^4.3.1",
"@vitest/coverage-v8": "^1.6.0",
"eslint": "8.22.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-react": "^7.31.10",
"eslint-plugin-react-hooks": "^4.6.0",
"husky": "^8.0.0",
"identity-obj-proxy": "^3.0.0",
"jest": "^29.7.0",
"jest-environment-jsdom": "^29.7.0",
"jest-sonar-reporter": "^2.0.0",
"jsdom": "^24.1.0",
"jwt-encode": "^1.0.1",
"lint-staged": "^12.4.1",
"patch-package": "^8.0.0",
"prettier": "^2.6.2",
"prettier-plugin-organize-imports": "^3.2.2",
"react": "^18.1.0",
"react-dom": "^18.1.0",
"react-router-dom": "^5.3.1",
"rimraf": "^3.0.2",
"rollup": "^4.12.0",
"semantic-release": "^22.0.12",
"ts-jest": "^29.1.2",
"ts-lib": "^0.0.5",
"tsc-watch": "^5.0.3",
"tslib": "^2.3.1",
"typedoc": "^0.25.12",
"typescript": "^5.3.3"
"typescript": "^5.3.3",
"vite-plugin-dts": "^3.9.1",
"vite-plugin-svgr": "^4.2.0",
"vite-tsconfig-paths": "^4.3.2",
"vitest": "^1.6.0"
},
"peerDependencies": {
"@emotion/react": "^11.10.4",
Expand All @@ -95,14 +94,15 @@
"prepublishOnly": "yarn build",
"documentation": "cd documentation && yarn start",
"documentation:build": "cd documentation && yarn install && yarn build",
"build": "rimraf ./dist && rollup --config rollup.config.ts --configPlugin @rollup/plugin-typescript",
"build": "vite build",
"yalc:push": "yalc publish --push",
"watch": "tsc-watch --noClear -p ./tsconfig.json --onSuccess \"yarn yalc:push\"",
"watch": "yarn build --mode=watch",
"lint": "eslint './src/**/*.{ts,tsx}'",
"test": "jest",
"test:watch": "jest --watch",
"test": "vitest run",
"test:watch": "node --experimental-vm-modules ./node_modules/.bin/jest --watch",
"documentation:generate": "typedoc --out typeDocs src",
"documentation:up": "cd documentation && yarn start"
"documentation:up": "cd documentation && yarn start",
"postinstall": "patch-package"
},
"keywords": [
"Orfium",
Expand Down
13 changes: 13 additions & 0 deletions patches/vite-plugin-svgr+4.2.0.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
diff --git a/node_modules/vite-plugin-svgr/client.d.ts b/node_modules/vite-plugin-svgr/client.d.ts
index dbfc650..fcd6218 100644
--- a/node_modules/vite-plugin-svgr/client.d.ts
+++ b/node_modules/vite-plugin-svgr/client.d.ts
@@ -5,7 +5,7 @@ declare module "*.svg?react" {
import * as React from "react";

const ReactComponent: React.FunctionComponent<
- React.ComponentProps<"svg"> & { title?: string }
+ React.ComponentProps<"svg"> & { title?: string; alt?: string }
>;

export default ReactComponent;
40 changes: 0 additions & 40 deletions rollup.config.ts

This file was deleted.

Loading
Loading