Add jest
Signed-off-by: Šimon Brandner <simon.bra.ag@gmail.com>
This commit is contained in:
		
					parent
					
						
							
								b8af9a0733
							
						
					
				
			
			
				commit
				
					
						fcaa126147
					
				
			
		
					 7 changed files with 2105 additions and 81 deletions
				
			
		
							
								
								
									
										15
									
								
								babel.config.cjs
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										15
									
								
								babel.config.cjs
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,15 @@ | |||
| module.exports = { | ||||
|   presets: [ | ||||
|     [ | ||||
|       "@babel/preset-env", | ||||
|       { | ||||
|         targets: { | ||||
|           node: "current", | ||||
|         }, | ||||
|       }, | ||||
|     ], | ||||
|     "@babel/preset-react", | ||||
|     "@babel/preset-typescript", | ||||
|   ], | ||||
|   plugins: ["babel-plugin-transform-vite-meta-env"], | ||||
| }; | ||||
							
								
								
									
										27
									
								
								package.json
									
										
									
									
									
								
							
							
						
						
									
										27
									
								
								package.json
									
										
									
									
									
								
							|  | @ -13,7 +13,8 @@ | |||
|     "lint:js": "eslint --max-warnings 0 src", | ||||
|     "lint:types": "tsc", | ||||
|     "i18n": "node_modules/i18next-parser/bin/cli.js", | ||||
|     "i18n:check": "node_modules/i18next-parser/bin/cli.js --fail-on-warnings --fail-on-update" | ||||
|     "i18n:check": "node_modules/i18next-parser/bin/cli.js --fail-on-warnings --fail-on-update", | ||||
|     "test": "jest" | ||||
|   }, | ||||
|   "dependencies": { | ||||
|     "@juggle/resize-observer": "^3.3.1", | ||||
|  | @ -51,8 +52,8 @@ | |||
|     "pako": "^2.0.4", | ||||
|     "postcss-preset-env": "^7", | ||||
|     "re-resizable": "^6.9.0", | ||||
|     "react": "^17.0.0", | ||||
|     "react-dom": "^17.0.0", | ||||
|     "react": "18", | ||||
|     "react-dom": "18", | ||||
|     "react-i18next": "^11.18.6", | ||||
|     "react-json-view": "^1.21.3", | ||||
|     "react-router": "6", | ||||
|  | @ -66,10 +67,13 @@ | |||
|     "@babel/core": "^7.16.5", | ||||
|     "@matrix-org/olm": "https://gitlab.matrix.org/api/v4/projects/27/packages/npm/@matrix-org/olm/-/@matrix-org/olm-3.2.8.tgz", | ||||
|     "@storybook/react": "^6.5.0-alpha.5", | ||||
|     "@testing-library/jest-dom": "^5.16.5", | ||||
|     "@testing-library/react": "^13.4.0", | ||||
|     "@types/request": "^2.48.8", | ||||
|     "@typescript-eslint/eslint-plugin": "^5.22.0", | ||||
|     "@typescript-eslint/parser": "^5.22.0", | ||||
|     "babel-loader": "^8.2.3", | ||||
|     "babel-plugin-transform-vite-meta-env": "^1.0.3", | ||||
|     "eslint": "^8.14.0", | ||||
|     "eslint-config-google": "^0.14.0", | ||||
|     "eslint-config-prettier": "^8.5.0", | ||||
|  | @ -79,6 +83,9 @@ | |||
|     "eslint-plugin-react": "^7.29.4", | ||||
|     "eslint-plugin-react-hooks": "^4.5.0", | ||||
|     "i18next-parser": "^6.6.0", | ||||
|     "identity-obj-proxy": "^3.0.0", | ||||
|     "jest": "^29.2.2", | ||||
|     "jest-environment-jsdom": "^29.2.2", | ||||
|     "prettier": "^2.6.2", | ||||
|     "sass": "^1.42.1", | ||||
|     "storybook-builder-vite": "^0.1.12", | ||||
|  | @ -87,5 +94,19 @@ | |||
|     "vite": "^2.4.2", | ||||
|     "vite-plugin-html-template": "^1.1.0", | ||||
|     "vite-plugin-svgr": "^0.4.0" | ||||
|   }, | ||||
|   "jest": { | ||||
|     "testEnvironment": "jsdom", | ||||
|     "testMatch": [ | ||||
|       "<rootDir>/test/**/*-test.[jt]s?(x)" | ||||
|     ], | ||||
|     "transformIgnorePatterns": [ | ||||
|       "/node_modules/(?!d3)+$", | ||||
|       "/node_modules/(?!internmap)+$" | ||||
|     ], | ||||
|     "moduleNameMapper": { | ||||
|       "\\.(css|less|svg)+$": "identity-obj-proxy", | ||||
|       "./IndexedDBWorker\\?worker": "<rootDir>/test/mocks/workerMock.ts" | ||||
|     } | ||||
|   } | ||||
| } | ||||
|  |  | |||
							
								
								
									
										16
									
								
								src/App.tsx
									
										
									
									
									
								
							
							
						
						
									
										16
									
								
								src/App.tsx
									
										
									
									
									
								
							|  | @ -14,7 +14,9 @@ See the License for the specific language governing permissions and | |||
| limitations under the License. | ||||
| */ | ||||
| 
 | ||||
| import React, { Suspense } from "react"; | ||||
| import Olm from "@matrix-org/olm"; | ||||
| import olmWasmPath from "@matrix-org/olm/olm.wasm?url"; | ||||
| import React, { Suspense, useState } from "react"; | ||||
| import { BrowserRouter as Router, Switch, Route } from "react-router-dom"; | ||||
| import * as Sentry from "@sentry/react"; | ||||
| import { OverlayProvider } from "@react-aria/overlays"; | ||||
|  | @ -28,7 +30,7 @@ import { ClientProvider } from "./ClientContext"; | |||
| import { usePageFocusStyle } from "./usePageFocusStyle"; | ||||
| import { SequenceDiagramViewerPage } from "./SequenceDiagramViewerPage"; | ||||
| import { InspectorContextProvider } from "./room/GroupCallInspector"; | ||||
| import { CrashView } from "./FullScreenView"; | ||||
| import { CrashView, LoadingView } from "./FullScreenView"; | ||||
| 
 | ||||
| const SentryRoute = Sentry.withSentryRouting(Route); | ||||
| 
 | ||||
|  | @ -37,10 +39,20 @@ interface AppProps { | |||
| } | ||||
| 
 | ||||
| export default function App({ history }: AppProps) { | ||||
|   const [loadingOlm, setLoadingOlm] = useState(false); | ||||
| 
 | ||||
|   usePageFocusStyle(); | ||||
| 
 | ||||
|   // TODO: https://gitlab.matrix.org/matrix-org/olm/-/issues/10
 | ||||
|   window.OLM_OPTIONS = {}; | ||||
|   Olm.init({ locateFile: () => olmWasmPath }).then(() => setLoadingOlm(false)); | ||||
| 
 | ||||
|   const errorPage = <CrashView />; | ||||
| 
 | ||||
|   if (loadingOlm) { | ||||
|     return <LoadingView />; | ||||
|   } | ||||
| 
 | ||||
|   return ( | ||||
|     <Router history={history}> | ||||
|       <Suspense fallback={null}> | ||||
|  |  | |||
|  | @ -1,5 +1,3 @@ | |||
| import Olm from "@matrix-org/olm"; | ||||
| import olmWasmPath from "@matrix-org/olm/olm.wasm?url"; | ||||
| import { IndexedDBStore } from "matrix-js-sdk/src/store/indexeddb"; | ||||
| import { MemoryStore } from "matrix-js-sdk/src/store/memory"; | ||||
| import { IndexedDBCryptoStore } from "matrix-js-sdk/src/crypto/store/indexeddb-crypto-store"; | ||||
|  | @ -72,10 +70,6 @@ export async function initClient( | |||
|   clientOptions: ICreateClientOpts, | ||||
|   restore: boolean | ||||
| ): Promise<MatrixClient> { | ||||
|   // TODO: https://gitlab.matrix.org/matrix-org/olm/-/issues/10
 | ||||
|   window.OLM_OPTIONS = {}; | ||||
|   await Olm.init({ locateFile: () => olmWasmPath }); | ||||
| 
 | ||||
|   let indexedDB: IDBFactory; | ||||
| 
 | ||||
|   try { | ||||
|  |  | |||
							
								
								
									
										1
									
								
								test/mocks/workerMock.ts
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								test/mocks/workerMock.ts
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1 @@ | |||
| module.exports = jest.fn(); | ||||
|  | @ -17,5 +17,10 @@ | |||
|       } | ||||
|     ] | ||||
|   }, | ||||
|   "include": ["./src/**/*.ts", "./src/**/*.tsx"] | ||||
|   "include": [ | ||||
|     "./src/**/*.ts",  | ||||
|     "./src/**/*.tsx", | ||||
|     "./test/**/*.ts", | ||||
|     "./test/**/*.tsx" | ||||
|   ] | ||||
| } | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue