From cecbf58e8fc7645b84b20abbfb46c5fe2059cb3b Mon Sep 17 00:00:00 2001 From: Edward Bramanti Date: Thu, 24 Jun 2021 01:50:14 -0600 Subject: [PATCH] Fix Jest test runner - Update @project-serum/sol-wallet-adapter to latest * Fixes superstruct dependency mismatch - Remove manual types - Fix typings in Jest tests * Load typeRoots from node_modules - Add global mocks for testing-library rendering - Update test to check for text that exists --- package.json | 10 +++++++++- src/App.test.tsx | 11 +++++++++-- src/setupTests.ts | 10 ++++++++++ src/types/sol-wallet-adapter.d.ts | 4 ---- tsconfig.json | 2 +- yarn.lock | 8 ++++---- 6 files changed, 33 insertions(+), 12 deletions(-) delete mode 100644 src/types/sol-wallet-adapter.d.ts diff --git a/package.json b/package.json index 45951fc84..47fb711a3 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "@craco/craco": "^5.7.0", "@ledgerhq/hw-transport-webusb": "^5.41.0", "@project-serum/serum": "^0.13.34", - "@project-serum/sol-wallet-adapter": "^0.2.0", + "@project-serum/sol-wallet-adapter": "^0.2.4", "@solana/spl-token": "0.1.3", "@solana/spl-token-registry": "^0.2.64", "@solana/spl-token-swap": "0.1.0", @@ -74,5 +74,13 @@ "arweave-deploy": "^1.9.1", "gh-pages": "^3.1.0", "prettier": "^2.1.2" + }, + "jest": { + "transform": { + "(@project-serum/sol-wallet-adapter).+\\.js$": "/node_modules/react-scripts/node_modules/babel-jest" + }, + "transformIgnorePatterns": [ + "/node_modules/(?!@project-serum/sol-wallet-adapter)" + ] } } diff --git a/src/App.test.tsx b/src/App.test.tsx index 352d7b8ff..78f1bfb9a 100644 --- a/src/App.test.tsx +++ b/src/App.test.tsx @@ -2,8 +2,15 @@ import React from "react"; import { render } from "@testing-library/react"; import App from "./App"; -test("renders learn react link", () => { +jest.mock("./components/Identicon", () => { + return { + __esModule: true, + Identicon: () => null, + }; +}); + +test("renders balances text", () => { const { getByText } = render(); - const linkElement = getByText(/learn react/i); + const linkElement = getByText(/Your balances/i); expect(linkElement).toBeInTheDocument(); }); diff --git a/src/setupTests.ts b/src/setupTests.ts index 5fdf00169..46e158eb6 100644 --- a/src/setupTests.ts +++ b/src/setupTests.ts @@ -3,3 +3,13 @@ // expect(element).toHaveTextContent(/react/i) // learn more: https://github.com/testing-library/jest-dom import "@testing-library/jest-dom/extend-expect"; + +Object.defineProperty(window, 'matchMedia', { + value: () => { + return { + matches: false, + addListener: () => {}, + removeListener: () => {} + }; + } +}) diff --git a/src/types/sol-wallet-adapter.d.ts b/src/types/sol-wallet-adapter.d.ts deleted file mode 100644 index 6464233b3..000000000 --- a/src/types/sol-wallet-adapter.d.ts +++ /dev/null @@ -1,4 +0,0 @@ -declare module "@project-serum/sol-wallet-adapter" { - const adapter: any; - export = adapter; -} diff --git a/tsconfig.json b/tsconfig.json index c30c01798..fd01e0a7e 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -13,7 +13,7 @@ "downlevelIteration": true, "resolveJsonModule": true, "noEmit": true, - "typeRoots": ["./types"], + "typeRoots": ["./types", "./node_modules/@types"], "jsx": "react", "isolatedModules": true }, diff --git a/yarn.lock b/yarn.lock index edc91b01e..98f318bf0 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1518,10 +1518,10 @@ bn.js "^5.1.2" buffer-layout "^1.2.0" -"@project-serum/sol-wallet-adapter@^0.2.0": - version "0.2.0" - resolved "https://registry.yarnpkg.com/@project-serum/sol-wallet-adapter/-/sol-wallet-adapter-0.2.0.tgz#e1fa5508bf13110429bf26e10b818182015f2161" - integrity sha512-ed7wZwlDqjF88VCq7eHVO8njHqdUkBxBL8WEVOnB47ooLO4btOJt6GBdkKpKqKX86c86LiEROJclcdW8e7kIjg== +"@project-serum/sol-wallet-adapter@^0.2.4": + version "0.2.4" + resolved "https://registry.yarnpkg.com/@project-serum/sol-wallet-adapter/-/sol-wallet-adapter-0.2.4.tgz#205adc303aea38d6c2043cb644fd70ba2fa758e0" + integrity sha512-NlFD5FumLddrHsRB1Dco7adiproUvXFC8kRxNg8ptEMD7k9p5gr8iKf6t06eARZAWQ7r90Bq1gEJc9GHlZ0c4Q== dependencies: bs58 "^4.0.1" eventemitter3 "^4.0.4"