Skip to content
This repository was archived by the owner on Mar 5, 2022. It is now read-only.

Commit b1cca0f

Browse files
committed
feat: support testing React components that use hooks
breaking change: requires Cypress v4.5.0 with experimental component testing flag, and the mounting API has changed. Squashed commit of the following: commit 7636302 Author: Gleb Bahmutov <[email protected]> Date: Tue Apr 28 17:48:42 2020 -0400 update style test commit 6eab8b0 Author: Gleb Bahmutov <[email protected]> Date: Tue Apr 28 17:33:41 2020 -0400 use Cypress v4.5.0 commit 78e2b63 Author: Gleb Bahmutov <[email protected]> Date: Tue Apr 28 11:24:04 2020 -0400 fix: add link to example, remove stray console.log commit 7b7460d Author: Gleb Bahmutov <[email protected]> Date: Mon Apr 27 14:58:40 2020 -0400 fix: upgrade find-webpack commit f7ff96e Author: Gleb Bahmutov <[email protected]> Date: Mon Apr 27 14:56:11 2020 -0400 fix: remove dupicate code commit 106e658 Author: Gleb Bahmutov <[email protected]> Date: Mon Apr 27 12:38:22 2020 -0400 add more lines to the table commit 53046a7 Author: Gleb Bahmutov <[email protected]> Date: Mon Apr 27 11:32:14 2020 -0400 update Jest vs cypress-react-unit-test table in the README commit fd67ac7 Author: Gleb Bahmutov <[email protected]> Date: Mon Apr 27 10:33:10 2020 -0400 point plugins at index file commit a16c802 Author: Gleb Bahmutov <[email protected]> Date: Mon Apr 27 10:18:38 2020 -0400 slightly better console log commit ffcc1ee Author: Gleb Bahmutov <[email protected]> Date: Mon Apr 27 09:56:46 2020 -0400 fix: add math random to component key prop on mount commit 222b6c2 Author: Gleb Bahmutov <[email protected]> Date: Mon Apr 27 09:53:04 2020 -0400 fix: cypress-jsdom -> cypress-root commit 9d49151 Author: Gleb Bahmutov <[email protected]> Date: Mon Apr 27 08:50:53 2020 -0400 add counter with hooks spec commit 5d7b3e2 Author: Gleb Bahmutov <[email protected]> Date: Mon Apr 27 08:41:31 2020 -0400 add demo animated gif commit c17f88e Author: Gleb Bahmutov <[email protected]> Date: Mon Apr 27 08:38:51 2020 -0400 change babelrc recipe to use explicit plugins file commit c130dc4 Author: Gleb Bahmutov <[email protected]> Date: Fri Apr 24 16:33:30 2020 -0400 add link commit efe88d6 Author: Gleb Bahmutov <[email protected]> Date: Fri Apr 24 16:19:39 2020 -0400 downgraded to testing-library cypress 5 commit 11e610c Author: Gleb Bahmutov <[email protected]> Date: Fri Apr 24 16:15:46 2020 -0400 upgrade cypress to v4.4.1 commit b1a7f1b Author: Gleb Bahmutov <[email protected]> Date: Fri Apr 24 14:35:16 2020 -0400 lock file update commit 7d733c1 Author: Gleb Bahmutov <[email protected]> Date: Fri Apr 24 14:33:44 2020 -0400 feat: add babelrc preprocessor, closes #149 commit 79f2130 Author: Gleb Bahmutov <[email protected]> Date: Fri Apr 24 12:42:54 2020 -0400 add visual testing link commit a6eb6d8 Author: Gleb Bahmutov <[email protected]> Date: Fri Apr 24 12:41:45 2020 -0400 add note about testing library commit 95caa6a Author: Gleb Bahmutov <[email protected]> Date: Fri Apr 24 08:23:50 2020 -0400 add react-loading-skeleton example link commit 1c9a99f Author: Gleb Bahmutov <[email protected]> Date: Thu Apr 23 14:19:24 2020 -0400 add lodash/fp spec commit 9f77d37 Author: Gleb Bahmutov <[email protected]> Date: Thu Apr 23 08:50:08 2020 -0400 add storybook-code-coverage link commit 00ff13b Author: Gleb Bahmutov <[email protected]> Date: Wed Apr 22 16:56:59 2020 -0400 add full list of advanced examples commit 8d719da Author: Gleb Bahmutov <[email protected]> Date: Wed Apr 22 16:32:18 2020 -0400 expand list of basic examples commit 2c35076 Author: Gleb Bahmutov <[email protected]> Date: Wed Apr 22 15:36:47 2020 -0400 more doc tweaks commit f9b0c05 Author: Gleb Bahmutov <[email protected]> Date: Wed Apr 22 15:06:29 2020 -0400 split long readme into docs files commit 85e73cb Author: Gleb Bahmutov <[email protected]> Date: Mon Apr 20 16:57:55 2020 -0400 renderless example commit 615bd04 Author: Gleb Bahmutov <[email protected]> Date: Thu Apr 16 22:53:04 2020 -0400 feat: respect log false commit ad51a71 Author: Gleb Bahmutov <[email protected]> Date: Thu Apr 16 22:44:43 2020 -0400 feat: reset the styles better commit fffd891 Author: Gleb Bahmutov <[email protected]> Date: Thu Apr 16 22:17:25 2020 -0400 clean up any injected styles before each test commit 298725f Author: Gleb Bahmutov <[email protected]> Date: Thu Apr 16 15:51:11 2020 -0400 feat: add css aliases to mounting options commit 9d06119 Author: Gleb Bahmutov <[email protected]> Date: Thu Apr 16 15:36:27 2020 -0400 fix: force return value commit 4dbee03 Author: Gleb Bahmutov <[email protected]> Date: Thu Apr 16 14:03:50 2020 -0400 fix: encode image commit a62fc22 Author: Gleb Bahmutov <[email protected]> Date: Thu Apr 16 13:44:04 2020 -0400 feat: if serving outside resource, serve base64 image commit b5686c3 Author: Gleb Bahmutov <[email protected]> Date: Thu Apr 16 13:29:38 2020 -0400 feat: add image rule for both plugins commit 12d859e Author: Gleb Bahmutov <[email protected]> Date: Thu Apr 16 10:17:32 2020 -0400 feat: redirect images to __root commit 6fb6fc2 Author: Gleb Bahmutov <[email protected]> Date: Tue Apr 14 10:36:02 2020 -0400 link v2 issues commit 22eec19 Author: Gleb Bahmutov <[email protected]> Date: Tue Apr 14 10:08:59 2020 -0400 fix: take default object from loaded webpack config commit e64620f Author: Gleb Bahmutov <[email protected]> Date: Tue Apr 14 08:36:49 2020 -0400 link to resource issue commit 584da55 Author: Gleb Bahmutov <[email protected]> Date: Mon Apr 13 18:13:14 2020 -0400 update README commit ea4aaf8 Author: Gleb Bahmutov <[email protected]> Date: Mon Apr 13 18:03:45 2020 -0400 second rename commit 56132ff Author: Gleb Bahmutov <[email protected]> Date: Mon Apr 13 18:02:41 2020 -0400 rename component test folder commit 61d95fb Author: Gleb Bahmutov <[email protected]> Date: Mon Apr 13 17:56:30 2020 -0400 add TSX component example commit d1aece8 Author: Gleb Bahmutov <[email protected]> Date: Thu Apr 9 14:52:49 2020 -0400 feat: update style options and document them well commit 1d2c411 Author: Gleb Bahmutov <[email protected]> Date: Thu Apr 9 14:17:40 2020 -0400 chore: refactor style injection commit 0f2defa Author: Gleb Bahmutov <[email protected]> Date: Wed Apr 8 09:19:59 2020 -0400 comment out import syntax commit f72b7d3 Author: Gleb Bahmutov <[email protected]> Date: Wed Apr 8 09:14:48 2020 -0400 feat: correctly clean up webpack for react-scripts for lazy dynamic imports commit 3bee1e2 Author: Gleb Bahmutov <[email protected]> Date: Wed Apr 8 08:43:00 2020 -0400 feat: support lazy-loaded components by forcing all into 1 chunk commit 5bbcc69 Author: Gleb Bahmutov <[email protected]> Date: Mon Apr 6 20:04:19 2020 -0400 feat: allow loading webpack config by filename commit b5fcf70 Author: Gleb Bahmutov <[email protected]> Date: Mon Apr 6 16:32:33 2020 -0400 move webpack clean up to find-webpack commit 62ff7c5 Author: Gleb Bahmutov <[email protected]> Date: Mon Apr 6 16:02:27 2020 -0400 fix the require commit 60fa438 Author: Gleb Bahmutov <[email protected]> Date: Mon Apr 6 16:00:15 2020 -0400 feat: use new code coverage version commit ddbdbe2 Author: Gleb Bahmutov <[email protected]> Date: Sun Apr 5 22:47:44 2020 -0400 feat: use find-webpack to handle ejected react-scripts too commit 33a5353 Author: Gleb Bahmutov <[email protected]> Date: Sun Apr 5 19:20:22 2020 -0400 add link to react animations example commit 1ee7668 Author: Gleb Bahmutov <[email protected]> Date: Sun Apr 5 18:46:31 2020 -0400 remove commit again commit f7678b8 Author: Gleb Bahmutov <[email protected]> Date: Sun Apr 5 18:07:19 2020 -0400 fix: update code coverage with better filtering commit ed33d6a Author: Gleb Bahmutov <[email protected]> Date: Sun Apr 5 18:05:22 2020 -0400 add links to more projects and full cypress json file commit e9773d9 Author: Gleb Bahmutov <[email protected]> Date: Sat Apr 4 17:20:31 2020 -0400 fix: new code coverage plugin version commit cc90fea Author: Gleb Bahmutov <[email protected]> Date: Sat Apr 4 16:34:46 2020 -0400 fix: support file should load hooks commit 1715052 Author: Gleb Bahmutov <[email protected]> Date: Sat Apr 4 16:17:48 2020 -0400 remove release plugins again commit 5f4856c Author: Gleb Bahmutov <[email protected]> Date: Sat Apr 4 15:55:42 2020 -0400 feat: include code-coverage plugin for react-scripts commit c379d01 Author: Gleb Bahmutov <[email protected]> Date: Sat Apr 4 16:11:40 2020 -0400 updated package lock commit 3e12870 Author: Gleb Bahmutov <[email protected]> Date: Sat Apr 4 14:33:37 2020 -0400 feat: add built-in code instrumentation commit fbd07b1 Author: Gleb Bahmutov <[email protected]> Date: Fri Apr 3 17:29:51 2020 -0400 feat: support cssFile style commit 796d248 Author: Gleb Bahmutov <[email protected]> Date: Fri Apr 3 13:18:24 2020 -0400 fix: include dist/hooks commit df33cab Author: Gleb Bahmutov <[email protected]> Date: Fri Apr 3 12:58:44 2020 -0400 fix: include plugins and support in dist commit 53483df Author: Gleb Bahmutov <[email protected]> Date: Fri Apr 3 12:11:11 2020 -0400 chore: remove commit plugins commit 04f1db4 Author: Gleb Bahmutov <[email protected]> Date: Fri Apr 3 11:33:57 2020 -0400 feat: add plugins and support for react-scripts commit a44405e Author: Gleb Bahmutov <[email protected]> Date: Fri Apr 3 11:19:37 2020 -0400 chore: update dependencies commit 1afb662 Author: Gleb Bahmutov <[email protected]> Date: Thu Apr 2 16:38:08 2020 -0400 remove unnecessary flag commit dd92d56 Author: Gleb Bahmutov <[email protected]> Date: Thu Apr 2 15:56:24 2020 -0400 feat: change to experimental mount mode to support React Hooks BREAKING CHANGE: the plugin's API has changed. commit be59374 Author: Gleb Bahmutov <[email protected]> Date: Thu Apr 2 15:45:30 2020 -0400 hmm commit 2b3f6fb Author: Gleb Bahmutov <[email protected]> Date: Thu Apr 2 15:33:57 2020 -0400 try assigning channel and reusing this branch name commit 67d44cb Author: Gleb Bahmutov <[email protected]> Date: Thu Apr 2 15:11:16 2020 -0400 change branch name commit 8857c99 Author: Gleb Bahmutov <[email protected]> Date: Thu Apr 2 14:58:43 2020 -0400 disable PR check for semantic release commit 98fcc6b Author: Gleb Bahmutov <[email protected]> Date: Thu Apr 2 14:48:46 2020 -0400 disable new tests for now commit 95feb07 Merge: ba6b20c d29901e Author: Gleb Bahmutov <[email protected]> Date: Thu Apr 2 14:36:04 2020 -0400 merge master into this branch commit ba6b20c Author: Gleb Bahmutov <[email protected]> Date: Thu Apr 2 14:18:36 2020 -0400 no module for now commit d29901e Author: Gleb Bahmutov <[email protected]> Date: Thu Apr 2 13:37:12 2020 -0400 remove emoji from circle job names commit 5ea2b4a Author: Gleb Bahmutov <[email protected]> Date: Thu Apr 2 12:04:37 2020 -0400 chore: add comments to circle file commit 34e1072 Author: Gleb Bahmutov <[email protected]> Date: Thu Apr 2 10:30:41 2020 -0400 feat: allow passing just cssFile path to inject style commit 72799e2 Author: Gleb Bahmutov <[email protected]> Date: Thu Apr 2 10:18:34 2020 -0400 feat: add style option commit a7916c3 Author: Gleb Bahmutov <[email protected]> Date: Wed Apr 1 15:22:43 2020 -0400 fix: handle bare div mount (#118) commit 8a23f96 Author: Gleb Bahmutov <[email protected]> Date: Wed Apr 1 14:50:38 2020 -0400 Upgrade webpack preprocessor (#117) * install new webpack preprocessor v4 * remove old code * Node 8 commit 4e2f899 Author: Neale Upstone <[email protected]> Date: Wed Apr 1 19:28:39 2020 +0100 feat: allow consuming projects to use noImplicitAny and fix JSX * tsc: Enable noImplicitAny and fix type issues that showed up * Replace Symbol with JSXElement to address JSX.Element -> Symbol errors (#55) * tsc: Enable strictNullChecks and fix type issues that showed for some users * remove stray JSX Co-authored-by: Gleb Bahmutov <[email protected]> commit 93e0fef Author: Gleb Bahmutov <[email protected]> Date: Wed Apr 1 14:15:18 2020 -0400 use newer Node for semantic release job commit c4eb69b Author: Gleb Bahmutov <[email protected]> Date: Wed Apr 1 14:09:18 2020 -0400 add semantic release job commit a7967a9 Author: Gleb Bahmutov <[email protected]> Date: Wed Apr 1 14:07:49 2020 -0400 chore: set up semantic release commit 38e0640 Author: Gleb Bahmutov <[email protected]> Date: Wed Apr 1 14:05:38 2020 -0400 remove old semantic-action commit ac53220 Author: Gleb Bahmutov <[email protected]> Date: Wed Apr 1 14:00:06 2020 -0400 upgrade Cypress to v4.3.0 commit c274025 Author: Gleb Bahmutov <[email protected]> Date: Wed Apr 1 13:53:14 2020 -0400 add cirlce commit 3c3e9d3 Author: Gleb Bahmutov <[email protected]> Date: Wed Apr 1 00:01:57 2020 -0400 add full material ui list demo commit 962ea87 Author: Gleb Bahmutov <[email protected]> Date: Tue Mar 31 23:54:16 2020 -0400 move emotion to dev dependency commit cbd83da Author: Gleb Bahmutov <[email protected]> Date: Tue Mar 31 23:40:07 2020 -0400 singular commit dc5d983 Author: Gleb Bahmutov <[email protected]> Date: Wed Feb 26 09:52:59 2020 -0500 disable a test commit 7a609dd Author: Gleb Bahmutov <[email protected]> Date: Thu Feb 13 21:44:02 2020 -0500 add react-router v6 alpha test commit ca3b232 Author: Gleb Bahmutov <[email protected]> Date: Tue Jan 28 15:18:22 2020 -0500 update comments commit 0207966 Author: Gleb Bahmutov <[email protected]> Date: Tue Jan 28 14:57:26 2020 -0500 looking at window reference commit 8963ab4 Author: Gleb Bahmutov <[email protected]> Date: Fri Jan 17 15:03:27 2020 -0500 all tests from react soft book commit 6a32d35 Author: Gleb Bahmutov <[email protected]> Date: Thu Jan 16 19:34:00 2020 -0500 autocomplete material component commit 9736a5c Author: Gleb Bahmutov <[email protected]> Date: Thu Jan 16 19:23:30 2020 -0500 test ratings component commit 8d817a2 Author: Gleb Bahmutov <[email protected]> Date: Thu Jan 16 19:11:51 2020 -0500 allow injecting styles and stylesheets commit 0e2a699 Author: Gleb Bahmutov <[email protected]> Date: Mon Jan 13 18:12:12 2020 -0500 update xhr test a little commit 7ba50de Author: Gleb Bahmutov <[email protected]> Date: Mon Jan 13 17:56:46 2020 -0500 add react book tests commit 3a4c7e0 Author: Gleb Bahmutov <[email protected]> Date: Fri Jan 10 15:26:56 2020 -0500 add example commit 96f339e Author: Gleb Bahmutov <[email protected]> Date: Fri Jan 10 15:24:02 2020 -0500 add example of unit testing tic tac toe win logic commit 92b3d28 Author: Gleb Bahmutov <[email protected]> Date: Fri Jan 10 11:47:44 2020 -0500 add unmount function commit 30bf202 Author: Gleb Bahmutov <[email protected]> Date: Fri Jan 10 11:32:34 2020 -0500 add timers tests commit b2b10fe Author: Gleb Bahmutov <[email protected]> Date: Fri Jan 10 11:10:17 2020 -0500 try snapshot plugins commit e2093ca Author: Gleb Bahmutov <[email protected]> Date: Fri Jan 10 10:54:22 2020 -0500 full tutorial with css commit 237ff76 Author: Gleb Bahmutov <[email protected]> Date: Fri Jan 10 10:27:26 2020 -0500 add react tutorial specs commit dde0331 Author: Gleb Bahmutov <[email protected]> Date: Wed Jan 8 14:01:12 2020 -0500 reorganize tests commit 38237bf Author: Gleb Bahmutov <[email protected]> Date: Mon Jan 6 09:36:07 2020 -0500 add component interaction commit 0bfae9c Author: Gleb Bahmutov <[email protected]> Date: Sun Jan 5 15:37:45 2020 -0500 check for spec type to be component instead of mount mode commit 8b4cd7a Author: Gleb Bahmutov <[email protected]> Date: Sun Jan 5 12:53:12 2020 -0500 set custom VSCode color commit 62e2199 Author: Gleb Bahmutov <[email protected]> Date: Sun Jan 5 12:52:03 2020 -0500 move component tests to component subfolder commit 949376e Author: Gleb Bahmutov <[email protected]> Date: Sun Jan 5 12:45:08 2020 -0500 format and lint on commit hook commit 7f40b07 Author: Gleb Bahmutov <[email protected]> Date: Sun Jan 5 12:43:44 2020 -0500 format all cypress subfolders commit 6f4ba52 Author: Gleb Bahmutov <[email protected]> Date: Sun Jan 5 12:43:18 2020 -0500 format lib ts files commit b53b736 Author: Gleb Bahmutov <[email protected]> Date: Sun Jan 5 12:42:43 2020 -0500 format integration files commit 2173720 Author: Gleb Bahmutov <[email protected]> Date: Sun Jan 5 12:41:50 2020 -0500 formatting src jsx commit e324d29 Author: Gleb Bahmutov <[email protected]> Date: Sun Jan 5 12:41:42 2020 -0500 formatting src jsx commit 60d4c32 Author: Gleb Bahmutov <[email protected]> Date: Sun Jan 5 12:40:10 2020 -0500 adding prettier commit 8078bea Author: Gleb Bahmutov <[email protected]> Date: Thu Jan 2 16:21:28 2020 -0500 tried two examples from material ui commit 0be1aa3 Author: Gleb Bahmutov <[email protected]> Date: Fri Dec 27 11:07:29 2019 -0500 example mocking named ES6 imports commit e55433d Author: Gleb Bahmutov <[email protected]> Date: Fri Dec 27 10:07:31 2019 -0500 rename commit 311b456 Author: Gleb Bahmutov <[email protected]> Date: Thu Dec 26 12:59:55 2019 -0500 working mocking module commit 60976e8 Author: Gleb Bahmutov <[email protected]> Date: Wed Dec 25 00:05:00 2019 -0500 toggle example test commit 0c1d115 Author: Gleb Bahmutov <[email protected]> Date: Tue Dec 24 23:57:08 2019 -0500 example unfinished of mocking modules commit 7791727 Author: Gleb Bahmutov <[email protected]> Date: Tue Dec 24 23:42:05 2019 -0500 add mocking fetch example commit 4f471b2 Author: Gleb Bahmutov <[email protected]> Date: Tue Dec 24 23:22:11 2019 -0500 add example from react testing docs commit 36e8976 Author: Gleb Bahmutov <[email protected]> Date: Tue Dec 24 23:16:24 2019 -0500 test unmount commit a836bd3 Author: Gleb Bahmutov <[email protected]> Date: Tue Dec 24 14:48:45 2019 -0500 complete example, svg and styles commit 894436d Author: Gleb Bahmutov <[email protected]> Date: Tue Dec 24 14:31:00 2019 -0500 add example with set timeout commit b08f16c Author: Gleb Bahmutov <[email protected]> Date: Tue Dec 24 14:06:18 2019 -0500 tried cy stub example commit f24784b Author: Gleb Bahmutov <[email protected]> Date: Tue Dec 24 10:39:52 2019 -0500 add cypress-testing-lib commands to check commit 2616a30 Author: Gleb Bahmutov <[email protected]> Date: Tue Dec 24 10:33:35 2019 -0500 test equivalent to react-testing lib example commit cbe2e77 Author: Gleb Bahmutov <[email protected]> Date: Mon Dec 23 17:32:58 2019 -0500 add React Context example test commit dce046b Author: Gleb Bahmutov <[email protected]> Date: Mon Dec 23 17:22:00 2019 -0500 add more examples from React tutorial commit a7e7b38 Author: Gleb Bahmutov <[email protected]> Date: Mon Dec 23 16:38:43 2019 -0500 another emotion example commit 4c0c1db Author: Gleb Bahmutov <[email protected]> Date: Mon Dec 23 16:23:02 2019 -0500 add another hooks example with useEffect commit f70af39 Author: Gleb Bahmutov <[email protected]> Date: Mon Dec 23 08:47:55 2019 -0500 package lock commit c029c4a Author: Dmitriy Kovalenko <[email protected]> Date: Wed Dec 18 16:17:31 2019 +0200 Remove .log file commit fea1996 Author: Dmitriy Kovalenko <[email protected]> Date: Wed Dec 18 16:16:45 2019 +0200 Fix error boundary example commit d4ef1af Author: Dmitriy Kovalenko <[email protected]> Date: Wed Dec 18 15:57:26 2019 +0200 Move hooks out commit f1e7580 Author: Dmitriy Kovalenko <[email protected]> Date: Wed Dec 18 15:00:52 2019 +0200 Add portal test commit d4be565 Author: Dmitriy Kovalenko <[email protected]> Date: Wed Dec 18 15:00:49 2019 +0200 Fix emotion test commit 574cc62 Author: Dmitriy Kovalenko <[email protected]> Date: Wed Dec 18 15:00:37 2019 +0200 Do not delete loaded scripts when prepearing to ReactDom.render commit 928d102 Author: Dmitriy Kovalenko <[email protected]> Date: Mon Dec 16 16:10:07 2019 +0200 Add emotion test commit f6f1197 Author: Dmitriy Kovalenko <[email protected]> Date: Mon Dec 16 15:10:33 2019 +0200 Unmount components after tests commit 20c1e7a Author: Dmitriy Kovalenko <[email protected]> Date: Sun Dec 15 15:02:20 2019 +0200 Rewrite spec files commit 26eb3ea Author: Dmitriy Kovalenko <[email protected]> Date: Sun Dec 15 14:24:20 2019 +0200 Use mount mode to render components
1 parent 3e1f085 commit b1cca0f

File tree

197 files changed

+23127
-10700
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

197 files changed

+23127
-10700
lines changed

.babelrc

Lines changed: 0 additions & 9 deletions
This file was deleted.

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ public/
22
node_modules/
33
dist
44
cypress/videos
5+
cypress/screenshots

.prettierrc.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"trailingComma": "all",
3+
"tabWidth": 2,
4+
"semi": false,
5+
"singleQuote": true
6+
}

.travis.yml

Lines changed: 0 additions & 31 deletions
This file was deleted.

.vscode/settings.json

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,28 @@
11
{
22
"git.ignoreLimitWarning": true,
3-
"eslint.enable": false
4-
}
3+
"eslint.enable": false,
4+
"editor.defaultFormatter": "esbenp.prettier-vscode",
5+
"editor.formatOnSave": true,
6+
"editor.formatOnPaste": false,
7+
"workbench.colorCustomizations": {
8+
"activityBar.background": "#a7cf00",
9+
"activityBar.activeBackground": "#a7cf00",
10+
"activityBar.activeBorder": "#00819f",
11+
"activityBar.foreground": "#15202b",
12+
"activityBar.inactiveForeground": "#15202b99",
13+
"activityBarBadge.background": "#00819f",
14+
"activityBarBadge.foreground": "#e7e7e7",
15+
"titleBar.activeBackground": "#7e9c00",
16+
"titleBar.inactiveBackground": "#7e9c0099",
17+
"titleBar.activeForeground": "#15202b",
18+
"titleBar.inactiveForeground": "#15202b99",
19+
"statusBar.background": "#7e9c00",
20+
"statusBarItem.hoverBackground": "#556900",
21+
"statusBar.foreground": "#15202b",
22+
"statusBar.border": "#7e9c00",
23+
"titleBar.border": "#7e9c00"
24+
},
25+
"peacock.color": "#7e9c00",
26+
"javascript.updateImportsOnFileMove.enabled": "never",
27+
"typescript.updateImportsOnFileMove.enabled": "never"
28+
}

README.md

Lines changed: 157 additions & 124 deletions
Large diffs are not rendered by default.

babel.config.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
module.exports = {
2+
presets: [
3+
'@babel/preset-env',
4+
'@babel/preset-react',
5+
'@babel/preset-typescript',
6+
],
7+
plugins: [
8+
// allow lazy loaded components with dynamic "import(...)"
9+
// https://babeljs.io/docs/en/babel-plugin-syntax-dynamic-import/
10+
'@babel/plugin-syntax-dynamic-import',
11+
'@babel/plugin-proposal-class-properties',
12+
// https://babeljs.io/docs/en/babel-plugin-transform-modules-commonjs
13+
// loose ES6 modules allow us to dynamically mock imports during tests
14+
[
15+
'@babel/plugin-transform-modules-commonjs',
16+
{
17+
loose: true,
18+
},
19+
],
20+
[
21+
'module-resolver',
22+
{
23+
alias: {
24+
'cypress-react-unit-test': './dist',
25+
},
26+
},
27+
],
28+
],
29+
}

circle.yml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
version: 2.1
2+
orbs:
3+
cypress: cypress-io/cypress@1
4+
workflows:
5+
build:
6+
jobs:
7+
# install and cache dependencies in this job
8+
# AND build the library once
9+
# then the workspace will be passed to other jobs
10+
- cypress/install:
11+
name: Install
12+
build: npm run transpile
13+
post-steps:
14+
- run:
15+
name: Show info 📺
16+
command: npx cypress info
17+
- run:
18+
name: Linting code 🧹
19+
command: npm run lint
20+
21+
# the test job automatically attaches the workspace
22+
# created by the install job, so it is ready to test
23+
- cypress/run:
24+
name: Test
25+
requires:
26+
- Install
27+
# notice a trick to avoid re-installing dependencies
28+
# in this job - a do-nothing "install-command" parameter
29+
install-command: echo 'Nothing to install in this job'
30+
# we are not going to use results from this job anywhere else
31+
no-workspace: true
32+
record: false
33+
34+
# this job attaches the workspace left by the install job
35+
# so it is ready to run Cypress tests
36+
# only we will run semantic release script instead
37+
- cypress/run:
38+
name: NPM release
39+
# we need newer Node for semantic release
40+
executor: cypress/base-12-6-0
41+
requires:
42+
- Install
43+
- Test
44+
install-command: echo 'Nothing to install in this job'
45+
no-workspace: true
46+
# instead of "cypress run" do NPM release 😁
47+
# clear environment variables to trick semantic-release
48+
# into thinking this is NOT a pull request.
49+
# (under the hood the module env-ci is used to check if this is a PR)
50+
command: |
51+
CIRCLE_PR_NUMBER= \
52+
CIRCLE_PULL_REQUEST= \
53+
CI_PULL_REQUEST= \
54+
npm run semantic-release

cypress.json

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
{
2-
"viewportWidth": 300,
3-
"viewportHeight": 100,
2+
"viewportWidth": 400,
3+
"viewportHeight": 400,
44
"video": false,
55
"projectId": "z9dxah",
6-
"ignoreTestFiles": "*.css",
6+
"testFiles": "**/*spec.{js,jsx,ts,tsx}",
77
"env": {
88
"cypress-react-unit-test": {
99
"react": "node_modules/react/umd/react.development.js",
1010
"react-dom": "node_modules/react-dom/umd/react-dom.development.js"
1111
}
12-
}
12+
},
13+
"ignoreTestFiles": [
14+
"**/__snapshots__/*",
15+
"**/__image_snapshots__/*"
16+
],
17+
"experimentalComponentTesting": true
1318
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Example showing how a component exposes a reference from its constructor, allowing the test to interact with the component's internals.
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/// <reference types="cypress" />
2+
import React from 'react'
3+
import { mount } from 'cypress-react-unit-test'
4+
import { Counter } from './counter.jsx'
5+
6+
/* eslint-env mocha */
7+
describe('Counter with access', () => {
8+
it('works', () => {
9+
mount(<Counter />)
10+
cy.contains('count: 0')
11+
.click()
12+
.contains('count: 1')
13+
.click()
14+
.contains('count: 2')
15+
})
16+
17+
it('allows access via reference', () => {
18+
mount(<Counter />)
19+
20+
// the window.counter was set from the Counter's constructor
21+
cy.window()
22+
.should('have.property', 'counter')
23+
.its('state')
24+
.should('deep.equal', { count: 0 })
25+
// let's change the state of the component
26+
cy.window()
27+
.its('counter')
28+
.invoke('setState', {
29+
count: 101,
30+
})
31+
// the UI should update to reflect the new count
32+
cy.contains('count: 101').should('be.visible')
33+
})
34+
})
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import React from 'react'
2+
3+
export class Counter extends React.Component {
4+
constructor(props) {
5+
super(props)
6+
this.state = {
7+
count: 0,
8+
}
9+
10+
if (window.Cypress) {
11+
// if this component is mounted from inside Cypress Test Runner
12+
// then expose the reference to this instance
13+
// to allow controlling it from tests
14+
console.log(
15+
'set window.counter to this component in window',
16+
window.location.pathname,
17+
)
18+
window.counter = this
19+
} else {
20+
console.log('running outside Cypress')
21+
}
22+
}
23+
24+
click = () => {
25+
this.setState({
26+
count: this.state.count + 1,
27+
})
28+
}
29+
30+
render() {
31+
return <p onClick={this.click}>count: {this.state.count}</p>
32+
}
33+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import React from 'react'
2+
3+
// Context lets us pass a value deep into the component tree
4+
// without explicitly threading it through every component.
5+
// Create a context for the current theme (with "light" as the default).
6+
const ThemeContext = React.createContext('light')
7+
8+
export default class App extends React.Component {
9+
render() {
10+
// Use a Provider to pass the current theme to the tree below.
11+
// Any component can read it, no matter how deep it is.
12+
// In this example, we're passing "dark" as the current value.
13+
return (
14+
<ThemeContext.Provider value="dark">
15+
<Toolbar />
16+
</ThemeContext.Provider>
17+
)
18+
}
19+
}
20+
21+
// A component in the middle doesn't have to
22+
// pass the theme down explicitly anymore.
23+
function Toolbar(props) {
24+
return (
25+
<div>
26+
<ThemedButton />
27+
</div>
28+
)
29+
}
30+
31+
function Button(props) {
32+
return <button>{props.theme}</button>
33+
}
34+
35+
class ThemedButton extends React.Component {
36+
// Assign a contextType to read the current theme context.
37+
// React will find the closest theme Provider above and use its value.
38+
// In this example, the current theme is "dark".
39+
static contextType = ThemeContext
40+
render() {
41+
return <Button theme={this.context} />
42+
}
43+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import React from 'react'
2+
import { mount } from 'cypress-react-unit-test'
3+
import App from './context-example.jsx'
4+
5+
describe('Context example', () => {
6+
it('renders', () => {
7+
mount(<App />)
8+
// the label "dark" was passed through React context
9+
cy.contains('button', 'dark').should('be.visible')
10+
})
11+
})
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import React from 'react'
2+
3+
const Button = React.forwardRef(({ children, ...rest }, ref) => (
4+
<button {...rest} ref={ref}>
5+
{children}
6+
</button>
7+
))
8+
9+
export default Button
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/// <reference types="cypress" />
2+
/// <reference types="../../lib" />
3+
4+
import React from 'react'
5+
import ReactDom from 'react-dom'
6+
import { mount } from 'cypress-react-unit-test'
7+
import Button from './forward-ref.jsx'
8+
9+
/* eslint-env mocha */
10+
describe('Button component', function() {
11+
it('works', function() {
12+
mount(<Button>Hello, World</Button>)
13+
cy.contains('Hello, World')
14+
})
15+
16+
it('forwards refs as expected', function() {
17+
const ref = React.createRef()
18+
19+
mount(
20+
<Button className="testing" ref={ref}>
21+
Hello, World
22+
</Button>,
23+
)
24+
expect(ref).to.have.property('current')
25+
// expect(ref.current).not.be.null;
26+
})
27+
})
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import React from 'react'
2+
3+
export default function CounterWithHooks({ initialCount = 0 }) {
4+
const [count, setCount] = React.useState(initialCount)
5+
6+
const handleCountIncrement = React.useCallback(() => {
7+
setCount(count + 1)
8+
}, [count])
9+
10+
return (
11+
<>
12+
<div className="counter">{count}</div>
13+
<button id="increment" onClick={handleCountIncrement}>
14+
+
15+
</button>
16+
</>
17+
)
18+
}

0 commit comments

Comments
 (0)