diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 47eeeb4c..b82a617d 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -26,6 +26,6 @@ jobs: - name: Install Dependencies run: yarn install - name: Test code - run: yarn test --passWithNoTests + run: yarn test - name: Build run: yarn build diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 90abd4e9..a30ee2b7 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -19,6 +19,6 @@ yarn install To verify setup, run the Storybook with `yarn dev`. You can develop new or existing components and verify functionality in the Storybook. -Unit tests are run with `yarn test`. +Run all unit tests with `yarn test`. Run unit tests on only the package you're working on with `yarn test packages/`. We use `husky` for pre-commit hooks to verify files are properly linted prior to committing. This will run automatically whenever adding or amending a commit. diff --git a/jest.config.js b/jest.config.js new file mode 100644 index 00000000..df67c75f --- /dev/null +++ b/jest.config.js @@ -0,0 +1,29 @@ +module.exports = { + preset: "ts-jest/presets/js-with-ts", + testMatch: [ + "/packages/*/src/**/__tests__/**/*.{js,jsx,ts,tsx}", + "/packages/*/src/**/?(*.)(spec|test).{js,jsx,ts,tsx}", + ], + coveragePathIgnorePatterns: [ + "/node_modules/", + "dist/", + "/packages/components/src/index.ts", + "/packages/componentssrc/components/index.ts", + ], + collectCoverageFrom: [ + "/packages/*/src/**/*.{js,ts,tsx,jsx}", + "!/packages/*/src/**/*.stories.*", + ], + moduleNameMapper: { + "\\.s?css$": "identity-obj-proxy", + }, + coverageThreshold: { + global: { + branches: 90, + functions: 90, + lines: 90, + statements: 90, + }, + }, + setupFilesAfterEnv: ["/utils/setupTests.ts"], +}; diff --git a/package.json b/package.json index 3a97da66..b630b0e4 100644 --- a/package.json +++ b/package.json @@ -18,10 +18,18 @@ "build:components": "yarn workspace @web3-ui/components build", "build:hooks": "yarn workspace @web3-ui/hooks build", "build": "yarn build:components && yarn build:hooks", - "test": "yarn workspace @web3-ui/components test", + "test": "jest", + "test:watch": "yarn test --watch", + "test:coverage": "jest --coverage --colors", "storybook:components": "yarn workspace @web3-ui/components storybook", "storybook:hooks": "yarn workspace @web3-ui/hooks storybook" }, + "devDependencies": { + "@testing-library/jest-dom": "^5.15.1", + "@testing-library/react": "^12.1.2", + "jest": "^26.6.3", + "ts-jest": "^26.4.4" + }, "lint-staged": { "*.{ts,tsx,json,js,jsx}": "yarn format" } diff --git a/packages/components/jest.config.js b/packages/components/jest.config.js deleted file mode 100644 index 7c4f1094..00000000 --- a/packages/components/jest.config.js +++ /dev/null @@ -1,25 +0,0 @@ -module.exports = { - preset: 'ts-jest/presets/js-with-ts', - testMatch: [ - '/src/**/__tests__/**/*.{js,jsx,ts,tsx}', - '/src/**/?(*.)(spec|test).{js,jsx,ts,tsx}', - ], - coveragePathIgnorePatterns: [ - '/node_modules/', - 'dist/', - '/src/index.ts', - '/src/components/index.ts', - ], - collectCoverageFrom: ['/src/**/*.{js,ts,tsx,jsx}', '!/src/**/*.stories.*'], - moduleNameMapper: { - '\\.s?css$': 'identity-obj-proxy', - }, - coverageThreshold: { - global: { - branches: 90, - functions: 90, - lines: 90, - statements: 90, - }, - }, -}; diff --git a/packages/components/package.json b/packages/components/package.json index d8c1ae27..0416e385 100644 --- a/packages/components/package.json +++ b/packages/components/package.json @@ -23,9 +23,6 @@ "format": "prettier --write \"src/**/*.{ts,tsx,json,js,jsx}\"", "format:check": "prettier --list-different \"src/**/*.{ts,tsx,json,js,jsx}\"", "storybook": "start-storybook -p 9001 -s ./src/assets -c .storybook", - "test": "jest --maxWorkers=2", - "test:watch": "yarn test --watch", - "test:coverage": "jest --coverage --colors --maxWorkers=2", "pre-commit-hook": "yarn lint-staged" }, "main": "dist/index.js", @@ -48,7 +45,6 @@ "@rollup/plugin-commonjs": "^16.0.0", "@rollup/plugin-node-resolve": "^10.0.0", "@storybook/react": "^6.3.12", - "@testing-library/react": "^12.1.2", "@types/classnames": "^2.2.11", "@types/jest": "^26.0.15", "@types/node": "^16.11.9", @@ -59,7 +55,6 @@ "classnames": "^2.2.6", "husky": "^7.0.0", "identity-obj-proxy": "^3.0.0", - "jest": "^26.6.3", "lint-staged": "^12.1.2", "prettier": "^2.2.0", "react": "^17.0.2", @@ -70,7 +65,6 @@ "rollup-plugin-postcss": "^3.1.8", "rollup-plugin-terser": "7.0.2", "rollup-plugin-typescript2": "^0.29.0", - "ts-jest": "^26.4.4", "ts-loader": "^8.0.11", "typescript": "^4.1.0", "webpack": "^4.42.1" diff --git a/packages/components/src/components/Address/Address.test.tsx b/packages/components/src/components/Address/Address.test.tsx new file mode 100644 index 00000000..b19cc991 --- /dev/null +++ b/packages/components/src/components/Address/Address.test.tsx @@ -0,0 +1,11 @@ +import React from 'react'; +import { render } from '@testing-library/react'; + +import { Address } from './Address'; + +describe('Address', () => { + it('renders without throwing', () => { + const { container } = render(
); + expect(container).toBeInTheDocument(); + }); +}); diff --git a/packages/components/tsconfig.json b/tsconfig.json similarity index 93% rename from packages/components/tsconfig.json rename to tsconfig.json index 9afce24a..a6189ab6 100644 --- a/packages/components/tsconfig.json +++ b/tsconfig.json @@ -19,5 +19,5 @@ "target": "es5" }, "exclude": ["node_modules"], - "include": ["./src"] + "include": ["./packages/*/src"] } diff --git a/utils/setupTests.ts b/utils/setupTests.ts new file mode 100644 index 00000000..d0de870d --- /dev/null +++ b/utils/setupTests.ts @@ -0,0 +1 @@ +import "@testing-library/jest-dom"; diff --git a/yarn.lock b/yarn.lock index e40a192e..3fa379e6 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1070,7 +1070,15 @@ pirates "^4.0.0" source-map-support "^0.5.16" -"@babel/runtime@^7.0.0", "@babel/runtime@^7.10.2", "@babel/runtime@^7.12.13", "@babel/runtime@^7.12.5", "@babel/runtime@^7.13.10", "@babel/runtime@^7.14.0", "@babel/runtime@^7.14.8", "@babel/runtime@^7.3.1", "@babel/runtime@^7.5.0", "@babel/runtime@^7.5.5", "@babel/runtime@^7.7.2", "@babel/runtime@^7.7.6", "@babel/runtime@^7.8.4": +"@babel/runtime-corejs3@^7.10.2": + version "7.16.3" + resolved "https://registry.yarnpkg.com/@babel/runtime-corejs3/-/runtime-corejs3-7.16.3.tgz#1e25de4fa994c57c18e5fdda6cc810dac70f5590" + integrity sha512-IAdDC7T0+wEB4y2gbIL0uOXEYpiZEeuFUTVbdGq+UwCcF35T/tS8KrmMomEwEc5wBbyfH3PJVpTSUqrhPDXFcQ== + dependencies: + core-js-pure "^3.19.0" + regenerator-runtime "^0.13.4" + +"@babel/runtime@^7.0.0", "@babel/runtime@^7.10.2", "@babel/runtime@^7.12.13", "@babel/runtime@^7.12.5", "@babel/runtime@^7.13.10", "@babel/runtime@^7.14.0", "@babel/runtime@^7.14.8", "@babel/runtime@^7.3.1", "@babel/runtime@^7.5.0", "@babel/runtime@^7.5.5", "@babel/runtime@^7.7.2", "@babel/runtime@^7.7.6", "@babel/runtime@^7.8.4", "@babel/runtime@^7.9.2": version "7.16.3" resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.16.3.tgz#b86f0db02a04187a3c17caa77de69840165d42d5" integrity sha512-WBwekcqacdY2e9AF/Q7WLFUWmdJGJTkbjqTjoMDgXkVZ3ZRUvOPsLb5KdwISoQVsbP+DQzVZW4Zhci0DvpbNTQ== @@ -3467,6 +3475,21 @@ lz-string "^1.4.4" pretty-format "^27.0.2" +"@testing-library/jest-dom@^5.15.1": + version "5.15.1" + resolved "https://registry.yarnpkg.com/@testing-library/jest-dom/-/jest-dom-5.15.1.tgz#4c49ba4d244f235aec53f0a83498daeb4ee06c33" + integrity sha512-kmj8opVDRE1E4GXyLlESsQthCXK7An28dFWxhiMwD7ZUI7ZxA6sjdJRxLerD9Jd8cHX4BDc1jzXaaZKqzlUkvg== + dependencies: + "@babel/runtime" "^7.9.2" + "@types/testing-library__jest-dom" "^5.9.1" + aria-query "^4.2.2" + chalk "^3.0.0" + css "^3.0.0" + css.escape "^1.5.1" + dom-accessibility-api "^0.5.6" + lodash "^4.17.15" + redent "^3.0.0" + "@testing-library/react@^12.1.2": version "12.1.2" resolved "https://registry.yarnpkg.com/@testing-library/react/-/react-12.1.2.tgz#f1bc9a45943461fa2a598bb4597df1ae044cfc76" @@ -3612,6 +3635,14 @@ dependencies: "@types/istanbul-lib-report" "*" +"@types/jest@*": + version "27.0.3" + resolved "https://registry.yarnpkg.com/@types/jest/-/jest-27.0.3.tgz#0cf9dfe9009e467f70a342f0f94ead19842a783a" + integrity sha512-cmmwv9t7gBYt7hNKH5Spu7Kuu/DotGa+Ff+JGRKZ4db5eh8PnKS4LuebJ3YLUoyOyIHraTGyULn23YtEAm0VSg== + dependencies: + jest-diff "^27.0.0" + pretty-format "^27.0.0" + "@types/jest@^26.0.15": version "26.0.24" resolved "https://registry.yarnpkg.com/@types/jest/-/jest-26.0.24.tgz#943d11976b16739185913a1936e0de0c4a7d595a" @@ -3790,6 +3821,13 @@ resolved "https://registry.yarnpkg.com/@types/tapable/-/tapable-1.0.8.tgz#b94a4391c85666c7b73299fd3ad79d4faa435310" integrity sha512-ipixuVrh2OdNmauvtT51o3d8z12p6LtFW9in7U79der/kwejjdNchQC5UMn5u/KxNoM7VHHOs/l8KS8uHxhODQ== +"@types/testing-library__jest-dom@^5.9.1": + version "5.14.1" + resolved "https://registry.yarnpkg.com/@types/testing-library__jest-dom/-/testing-library__jest-dom-5.14.1.tgz#014162a5cee6571819d48e999980694e2f657c3c" + integrity sha512-Gk9vaXfbzc5zCXI9eYE9BI5BNHEp4D3FWjgqBE/ePGYElLAP+KvxBcsdkwfIVvezs605oiyd/VrpiHe3Oeg+Aw== + dependencies: + "@types/jest" "*" + "@types/uglify-js@*": version "3.13.1" resolved "https://registry.yarnpkg.com/@types/uglify-js/-/uglify-js-3.13.1.tgz#5e889e9e81e94245c75b6450600e1c5ea2878aea" @@ -4458,6 +4496,14 @@ aria-hidden@^1.1.1: dependencies: tslib "^1.0.0" +aria-query@^4.2.2: + version "4.2.2" + resolved "https://registry.yarnpkg.com/aria-query/-/aria-query-4.2.2.tgz#0d2ca6c9aceb56b8977e9fed6aed7e15bbd2f83b" + integrity sha512-o/HelwhuKpTj/frsOsbNLNgnNGVIFsVP/SW2BSF14gVl7kAfMOJ6/8wUAUvG1R1NHKrfG+2sHZTu0yauT1qBrA== + dependencies: + "@babel/runtime" "^7.10.2" + "@babel/runtime-corejs3" "^7.10.2" + aria-query@^5.0.0: version "5.0.0" resolved "https://registry.yarnpkg.com/aria-query/-/aria-query-5.0.0.tgz#210c21aaf469613ee8c9a62c7f86525e058db52c" @@ -5448,6 +5494,14 @@ chalk@^1.1.3: strip-ansi "^3.0.0" supports-color "^2.0.0" +chalk@^3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/chalk/-/chalk-3.0.0.tgz#3f73c2bf526591f574cc492c51e2456349f844e4" + integrity sha512-4D3B6Wf41KOYRFdszmDqMCGq5VV/uMAB273JILmO+3jAlh8X4qDtdtgCR3fxtbLEMzSx22QdhnDcJvu2u1fVwg== + dependencies: + ansi-styles "^4.1.0" + supports-color "^7.1.0" + chalk@^4.0.0, chalk@^4.1.0, chalk@^4.1.1: version "4.1.2" resolved "https://registry.yarnpkg.com/chalk/-/chalk-4.1.2.tgz#aac4e2b7734a740867aeb16bf02aad556a1e7a01" @@ -5965,7 +6019,7 @@ core-js-compat@^3.18.0, core-js-compat@^3.19.1, core-js-compat@^3.8.1: browserslist "^4.17.6" semver "7.0.0" -core-js-pure@^3.8.1, core-js-pure@^3.8.2: +core-js-pure@^3.19.0, core-js-pure@^3.8.1, core-js-pure@^3.8.2: version "3.19.1" resolved "https://registry.yarnpkg.com/core-js-pure/-/core-js-pure-3.19.1.tgz#edffc1fc7634000a55ba05e95b3f0fe9587a5aa4" integrity sha512-Q0Knr8Es84vtv62ei6/6jXH/7izKmOrtrxH9WJTHLCMAVeU+8TF8z8Nr08CsH4Ot0oJKzBzJJL9SJBYIv7WlfQ== @@ -6243,6 +6297,20 @@ css-what@^5.0.0: resolved "https://registry.yarnpkg.com/css-what/-/css-what-5.1.0.tgz#3f7b707aadf633baf62c2ceb8579b545bb40f7fe" integrity sha512-arSMRWIIFY0hV8pIxZMEfmMI47Wj3R/aWpZDDxWYCPEiOMv6tfOrnpDtgxBYPEQD4V0Y/958+1TdC3iWTFcUPw== +css.escape@^1.5.1: + version "1.5.1" + resolved "https://registry.yarnpkg.com/css.escape/-/css.escape-1.5.1.tgz#42e27d4fa04ae32f931a4b4d4191fa9cddee97cb" + integrity sha1-QuJ9T6BK4y+TGktNQZH6nN3ul8s= + +css@^3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/css/-/css-3.0.0.tgz#4447a4d58fdd03367c516ca9f64ae365cee4aa5d" + integrity sha512-DG9pFfwOrzc+hawpmqX/dHYHJG+Bsdb0klhyi1sDneOgGOXy9wQIC8hzyVp1e4NRYDBdxcylvywPkkXCHAzTyQ== + dependencies: + inherits "^2.0.4" + source-map "^0.6.1" + source-map-resolve "^0.6.0" + cssesc@^3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/cssesc/-/cssesc-3.0.0.tgz#37741919903b868565e1c09ea747445cd18983ee" @@ -6539,6 +6607,11 @@ diff-sequences@^26.6.2: resolved "https://registry.yarnpkg.com/diff-sequences/-/diff-sequences-26.6.2.tgz#48ba99157de1923412eed41db6b6d4aa9ca7c0b1" integrity sha512-Mv/TDa3nZ9sbc5soK+OoA74BsS3mL37yixCvUAQkiuA4Wz6YtwP/K47n2rv2ovzHZvoiQeA5FTQOschKkEwB0Q== +diff-sequences@^27.0.6: + version "27.0.6" + resolved "https://registry.yarnpkg.com/diff-sequences/-/diff-sequences-27.0.6.tgz#3305cb2e55a033924054695cc66019fd7f8e5723" + integrity sha512-ag6wfpBFyNXZ0p8pcuIDS//D8H062ZQJ3fzYxjpmeKjnz8W4pekL3AI8VohmyZmsWW2PWaHgjsmqR6L13101VQ== + diffie-hellman@^5.0.0: version "5.0.3" resolved "https://registry.yarnpkg.com/diffie-hellman/-/diffie-hellman-5.0.3.tgz#40e8ee98f55a2149607146921c63e1ae5f3d2875" @@ -6574,7 +6647,7 @@ doctrine@^3.0.0: dependencies: esutils "^2.0.2" -dom-accessibility-api@^0.5.9: +dom-accessibility-api@^0.5.6, dom-accessibility-api@^0.5.9: version "0.5.10" resolved "https://registry.yarnpkg.com/dom-accessibility-api/-/dom-accessibility-api-0.5.10.tgz#caa6d08f60388d0bb4539dd75fe458a9a1d0014c" integrity sha512-Xu9mD0UjrJisTmv7lmVSDMagQcU9R5hwAbxsaAE/35XPnPLJobbuREfV/rraiSaEj/UOvgrzQs66zyTWTlyd+g== @@ -9403,6 +9476,16 @@ jest-diff@^26.0.0, jest-diff@^26.6.2: jest-get-type "^26.3.0" pretty-format "^26.6.2" +jest-diff@^27.0.0: + version "27.3.1" + resolved "https://registry.yarnpkg.com/jest-diff/-/jest-diff-27.3.1.tgz#d2775fea15411f5f5aeda2a5e02c2f36440f6d55" + integrity sha512-PCeuAH4AWUo2O5+ksW4pL9v5xJAcIKPUPfIhZBcG1RKv/0+dvaWTQK1Nrau8d67dp65fOqbeMdoil+6PedyEPQ== + dependencies: + chalk "^4.0.0" + diff-sequences "^27.0.6" + jest-get-type "^27.3.1" + pretty-format "^27.3.1" + jest-docblock@^26.0.0: version "26.0.0" resolved "https://registry.yarnpkg.com/jest-docblock/-/jest-docblock-26.0.0.tgz#3e2fa20899fc928cb13bd0ff68bd3711a36889b5" @@ -9451,6 +9534,11 @@ jest-get-type@^26.3.0: resolved "https://registry.yarnpkg.com/jest-get-type/-/jest-get-type-26.3.0.tgz#e97dc3c3f53c2b406ca7afaed4493b1d099199e0" integrity sha512-TpfaviN1R2pQWkIihlfEanwOXK0zcxrKEE4MlU6Tn7keoXdN6/3gK/xl0yEh8DOunn5pOVGKf8hB4R9gVh04ig== +jest-get-type@^27.3.1: + version "27.3.1" + resolved "https://registry.yarnpkg.com/jest-get-type/-/jest-get-type-27.3.1.tgz#a8a2b0a12b50169773099eee60a0e6dd11423eff" + integrity sha512-+Ilqi8hgHSAdhlQ3s12CAVNd8H96ZkQBfYoXmArzZnOfAtVAJEiPDBirjByEblvG/4LPJmkL+nBqPO3A1YJAEg== + jest-haste-map@^26.6.2: version "26.6.2" resolved "https://registry.yarnpkg.com/jest-haste-map/-/jest-haste-map-26.6.2.tgz#dd7e60fe7dc0e9f911a23d79c5ff7fb5c2cafeaa" @@ -11851,7 +11939,7 @@ pretty-format@^26.0.0, pretty-format@^26.6.2: ansi-styles "^4.0.0" react-is "^17.0.1" -pretty-format@^27.0.2: +pretty-format@^27.0.0, pretty-format@^27.0.2, pretty-format@^27.3.1: version "27.3.1" resolved "https://registry.yarnpkg.com/pretty-format/-/pretty-format-27.3.1.tgz#7e9486365ccdd4a502061fa761d3ab9ca1b78df5" integrity sha512-DR/c+pvFc52nLimLROYjnXPtolawm+uWDxr4FjuLDLUn+ktWnSN851KoHwHzzqq6rfCOjkzN8FLgDrSub6UDuA== @@ -12476,6 +12564,14 @@ recursive-readdir@2.2.2: dependencies: minimatch "3.0.4" +redent@^3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/redent/-/redent-3.0.0.tgz#e557b7998316bb53c9f1f56fa626352c6963059f" + integrity sha512-6tDA8g98We0zd0GvVeMT9arEOnTw9qM03L9cJXaCjrip1OO764RDBLBfrB4cwzNGDj5OA5ioymC9GkizgWJDUg== + dependencies: + indent-string "^4.0.0" + strip-indent "^3.0.0" + refractor@^3.1.0: version "3.5.0" resolved "https://registry.yarnpkg.com/refractor/-/refractor-3.5.0.tgz#334586f352dda4beaf354099b48c2d18e0819aec" @@ -13310,6 +13406,14 @@ source-map-resolve@^0.5.0: source-map-url "^0.4.0" urix "^0.1.0" +source-map-resolve@^0.6.0: + version "0.6.0" + resolved "https://registry.yarnpkg.com/source-map-resolve/-/source-map-resolve-0.6.0.tgz#3d9df87e236b53f16d01e58150fc7711138e5ed2" + integrity sha512-KXBr9d/fO/bWo97NXsPIAW1bFSBOuCnjbNTBMO7N59hsv5i9yzRDfcYwwt0l04+VqnKC+EwzvJZIP/qkuMgR/w== + dependencies: + atob "^2.1.2" + decode-uri-component "^0.2.0" + source-map-support@^0.5.16, source-map-support@^0.5.6, source-map-support@~0.5.12, source-map-support@~0.5.20: version "0.5.21" resolved "https://registry.yarnpkg.com/source-map-support/-/source-map-support-0.5.21.tgz#04fe7c7f9e1ed2d662233c28cb2b35b9f63f6e4f"