From e3dc50ffe0dc1f29d0f4ab01c8926726f2ed098c Mon Sep 17 00:00:00 2001 From: Peter Pistorius Date: Wed, 18 Mar 2020 23:29:00 +0100 Subject: [PATCH 1/9] Switch router and web from esm to cjs. --- babel.config.js | 1 - packages/router/package.json | 2 +- packages/web/package.json | 2 +- 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/babel.config.js b/babel.config.js index aeef1f7d98f6..054c2f6db609 100644 --- a/babel.config.js +++ b/babel.config.js @@ -61,7 +61,6 @@ module.exports = { targets: { browsers: TARGETS_BROWSERS, }, - modules: false, }, ], ], diff --git a/packages/router/package.json b/packages/router/package.json index bca0fae003f5..97c4bb462ffa 100644 --- a/packages/router/package.json +++ b/packages/router/package.json @@ -4,7 +4,7 @@ "files": [ "dist" ], - "module": "dist/index.js", + "main": "dist/index.js", "license": "MIT", "dependencies": { "core-js": "3.6.4" diff --git a/packages/web/package.json b/packages/web/package.json index 47dfe82c024c..c768d7fef919 100644 --- a/packages/web/package.json +++ b/packages/web/package.json @@ -4,7 +4,7 @@ "files": [ "dist" ], - "module": "dist/index.js", + "main": "dist/index.js", "license": "MIT", "dependencies": { "@apollo/react-components": "^3.1.3", From 6ed0487a600405ea5156a6189de6f27a3575ceb5 Mon Sep 17 00:00:00 2001 From: Peter Pistorius Date: Thu, 19 Mar 2020 18:50:10 +0100 Subject: [PATCH 2/9] Fix imports. --- babel.config.js | 19 +++++++++++++++++++ package.json | 10 +++++++--- packages/router/package.json | 3 +++ packages/web/package.json | 4 ++++ 4 files changed, 33 insertions(+), 3 deletions(-) diff --git a/babel.config.js b/babel.config.js index 054c2f6db609..0ae4e22accad 100644 --- a/babel.config.js +++ b/babel.config.js @@ -64,6 +64,25 @@ module.exports = { }, ], ], + plugins: [ + [ + 'babel-plugin-auto-import', + { + declarations: [ + { + // import { React } from 'react' + default: 'React', + path: 'react', + }, + { + // import { PropTypes } from 'prop-types' + default: 'PropTypes', + path: 'prop-types', + }, + ], + }, + ], + ], }, ], // Do not build tests or mocks in production. diff --git a/package.json b/package.json index 1a635f14df4c..d63b874fcdc2 100644 --- a/package.json +++ b/package.json @@ -10,10 +10,11 @@ "@babel/node": "^7.8.3", "@babel/plugin-proposal-class-properties": "^7.8.3", "@babel/plugin-transform-runtime": "^7.8.3", - "@babel/runtime-corejs3": "^7.8.4", "@babel/preset-env": "^7.8.4", "@babel/preset-react": "^7.8.3", "@babel/preset-typescript": "^7.8.3", + "@babel/runtime-corejs3": "^7.8.4", + "babel-plugin-auto-import": "^1.0.5", "babel-plugin-module-resolver": "^4.0.0", "jest": "^25.1.0", "lerna": "^3.20.2", @@ -23,11 +24,14 @@ "eslintConfig": { "extends": "@redwoodjs/eslint-config" }, - "eslintIgnore": ["dist", "packages/api/importAll.macro.js"], + "eslintIgnore": [ + "dist", + "packages/api/importAll.macro.js" + ], "scripts": { "build": "NODE_ENV=production lerna run build", "test": "lerna run test --stream -- --colors", "lint": "yarn eslint './packages/'", "lint:fix": "yarn eslint --fix './packages/'" } -} \ No newline at end of file +} diff --git a/packages/router/package.json b/packages/router/package.json index 97c4bb462ffa..c4fd6c96b00c 100644 --- a/packages/router/package.json +++ b/packages/router/package.json @@ -9,6 +9,9 @@ "dependencies": { "core-js": "3.6.4" }, + "peerDependencies": { + "react": "*" + }, "scripts": { "build": "yarn clean && babel src -d dist", "build:watch": "nodemon --ignore dist --exec 'yarn build'", diff --git a/packages/web/package.json b/packages/web/package.json index c768d7fef919..3a7696dc92b5 100644 --- a/packages/web/package.json +++ b/packages/web/package.json @@ -20,6 +20,10 @@ "proptypes": "^1.1.0", "react-hook-form": "^4.10.1" }, + "peerDependencies": { + "react": "*", + "prop-types": "*" + }, "scripts": { "build": "yarn clean && babel src -d dist", "build:watch": "nodemon --ignore dist --exec 'yarn build'", From 876bfc7774f735c7c611d4e4246c54dbe75bf5a8 Mon Sep 17 00:00:00 2001 From: Peter Pistorius Date: Thu, 19 Mar 2020 19:04:06 +0100 Subject: [PATCH 3/9] Emulate globals. --- packages/core/config/jest.config.web.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/core/config/jest.config.web.js b/packages/core/config/jest.config.web.js index 33522bd25bd6..e761d84d9dc9 100644 --- a/packages/core/config/jest.config.web.js +++ b/packages/core/config/jest.config.web.js @@ -3,4 +3,7 @@ module.exports = { resolver: 'jest-directory-named-resolver', rootDir: process.cwd(), + globals: { + __REDWOOD__API_PROXY_PATH: '/', + }, } From fad3360338085d73b4d325d4d1eae31279b3b25d Mon Sep 17 00:00:00 2001 From: Peter Pistorius Date: Thu, 19 Mar 2020 19:50:44 +0100 Subject: [PATCH 4/9] Add jest-dom. --- packages/core/package.json | 1 + yarn.lock | 70 +++++++++++++++++++++++++++++++------- 2 files changed, 58 insertions(+), 13 deletions(-) diff --git a/packages/core/package.json b/packages/core/package.json index 74cddde93aa3..87f6341283ff 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -42,6 +42,7 @@ "html-webpack-plugin": "^3.2.0", "jest": "^25.1.0", "jest-directory-named-resolver": "^0.3.0", + "@testing-library/jest-dom": "^5.1.1", "lodash.escaperegexp": "^4.1.2", "mini-css-extract-plugin": "^0.9.0", "prisma2": "2.0.0-preview023", diff --git a/yarn.lock b/yarn.lock index 37b496a99261..dd447eff5bb9 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1089,7 +1089,7 @@ dependencies: regenerator-runtime "^0.13.2" -"@babel/runtime@^7.7.4", "@babel/runtime@^7.8.4": +"@babel/runtime@^7.7.4", "@babel/runtime@^7.8.3", "@babel/runtime@^7.8.4": version "7.8.7" resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.8.7.tgz#8fefce9802db54881ba59f90bb28719b4996324d" integrity sha512-+AATMUFppJDw6aiR5NVPHqIQBlV/Pj8wY/EZH+lmvRdUo9xBaz/rF3alAwFJQavvKfeOlPE7oaaDHVbcySbCsg== @@ -1173,7 +1173,7 @@ integrity sha512-v9kIhKwjeZThiWrLmj0y17CWoyddASLj9O2yvbZkbvw/N3rWOYy9zkV66ursAoVr0mV15bL8g0c4QZUE6cdDoQ== dependencies: exec-sh "^0.3.2" - minimist "^1.2.5" + minimist "^1.2.0" "@evocateur/libnpmaccess@^3.1.2": version "3.1.2" @@ -2453,6 +2453,22 @@ pretty-format "^25.1.0" wait-for-expect "^3.0.2" +"@testing-library/jest-dom@^5.1.1": + version "5.1.1" + resolved "https://registry.yarnpkg.com/@testing-library/jest-dom/-/jest-dom-5.1.1.tgz#e88a5c08f9b9f36b384f948a0532eae2abbc8204" + integrity sha512-7xnmBFcUmmUVAUhFiZ/u3CxFh1e46THAwra4SiiKNCW4By26RedCRwEk0rtleFPZG0wlTSNOKDvJjWYy93dp0w== + dependencies: + "@babel/runtime" "^7.8.3" + "@types/testing-library__jest-dom" "^5.0.0" + chalk "^3.0.0" + css "^2.2.4" + css.escape "^1.5.1" + jest-diff "^25.1.0" + jest-matcher-utils "^25.1.0" + lodash "^4.17.15" + pretty-format "^25.1.0" + redent "^3.0.0" + "@testing-library/react@^9.5.0": version "9.5.0" resolved "https://registry.yarnpkg.com/@testing-library/react/-/react-9.5.0.tgz#71531655a7890b61e77a1b39452fbedf0472ca5e" @@ -2670,6 +2686,14 @@ "@types/istanbul-lib-coverage" "*" "@types/istanbul-lib-report" "*" +"@types/jest@*": + version "25.1.4" + resolved "https://registry.yarnpkg.com/@types/jest/-/jest-25.1.4.tgz#9e9f1e59dda86d3fd56afce71d1ea1b331f6f760" + integrity sha512-QDDY2uNAhCV7TMCITrxz+MRk1EizcsevzfeS6LykIlq2V1E5oO4wXG8V2ZEd9w7Snxeeagk46YbMgZ8ESHx3sw== + dependencies: + jest-diff "^25.1.0" + pretty-format "^25.1.0" + "@types/jest@^25.1.3": version "25.1.3" resolved "https://registry.yarnpkg.com/@types/jest/-/jest-25.1.3.tgz#9b0b5addebccfb631175870be8ba62182f1bc35a" @@ -2862,6 +2886,13 @@ dependencies: pretty-format "^24.3.0" +"@types/testing-library__jest-dom@^5.0.0": + version "5.0.2" + resolved "https://registry.yarnpkg.com/@types/testing-library__jest-dom/-/testing-library__jest-dom-5.0.2.tgz#89b782e0f187fe1e80d6375133da74182ba02065" + integrity sha512-dZP+/WHndgCSmdaImITy0KhjGAa9c0hlGGkzefbtrPFpnGEPZECDA0zyvfSp8RKhHECJJSKHFExjOwzo0rHyIA== + dependencies: + "@types/jest" "*" + "@types/testing-library__react@^9.1.2": version "9.1.3" resolved "https://registry.yarnpkg.com/@types/testing-library__react/-/testing-library__react-9.1.3.tgz#35eca61cc6ea923543796f16034882a1603d7302" @@ -4531,7 +4562,7 @@ check-node-version@^4.0.2: dependencies: chalk "^3.0.0" map-values "^1.0.1" - minimist "^1.2.5" + minimist "^1.2.0" object-filter "^1.0.2" run-parallel "^1.1.4" semver "^6.3.0" @@ -5284,7 +5315,12 @@ css-what@2.1: resolved "https://registry.yarnpkg.com/css-what/-/css-what-2.1.3.tgz#a6d7604573365fe74686c3f311c56513d88285f2" integrity sha512-a+EPoD+uZiNfh+5fxw2nO9QwFa6nJe2Or35fGY6Ipw1R3R4AGz1d1TEZrCegvw2YTmZ0jXirGYlzxxpYSHwpEg== -css@2.2.4: +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@2.2.4, css@^2.2.4: version "2.2.4" resolved "https://registry.yarnpkg.com/css/-/css-2.2.4.tgz#c646755c73971f2bba6a601e2cf2fd71b1298929" integrity sha512-oUnjmWpy0niI3x/mPL8dVEI1l7MnG3+HHyRPHf+YFSbK+svOhXpmSOcDURUh2aOCgl2grzrOPt1nHLuCVFULLw== @@ -8783,14 +8819,14 @@ json5@^1.0.1: resolved "https://registry.yarnpkg.com/json5/-/json5-1.0.1.tgz#779fb0018604fa854eacbf6252180d83543e3dbe" integrity sha512-aKS4WQjPenRxiQsC93MNfjx+nbF4PAdYzmd/1JIj8HYzqfbu86beTuNgXDzPknWk0n0uARlyewZo4s++ES36Ow== dependencies: - minimist "^1.2.5" + minimist "^1.2.0" json5@^2.1.0: version "2.1.1" resolved "https://registry.yarnpkg.com/json5/-/json5-2.1.1.tgz#81b6cb04e9ba496f1c7005d07b4368a2638f90b6" integrity sha512-l+3HXD0GEI3huGq1njuqtzYK8OYJyXMkOLtQ53pjWh89tvWS2h6l+1zMkYWqlb57+SiQodKZyvMEFb2X+KrFhQ== dependencies: - minimist "^1.2.5" + minimist "^1.2.0" jsonfile@^4.0.0: version "4.0.0" @@ -9441,7 +9477,7 @@ meow@^3.3.0: decamelize "^1.1.2" loud-rejection "^1.0.0" map-obj "^1.0.1" - minimist "^1.2.5" + minimist "^1.1.3" normalize-package-data "^2.3.4" object-assign "^4.0.1" read-pkg-up "^1.0.1" @@ -9456,7 +9492,7 @@ meow@^4.0.0: camelcase-keys "^4.0.0" decamelize-keys "^1.0.0" loud-rejection "^1.0.0" - minimist "^1.2.5" + minimist "^1.1.3" minimist-options "^3.0.1" normalize-package-data "^2.3.4" read-pkg-up "^3.0.0" @@ -9691,7 +9727,7 @@ mkdirp@^0.5.0, mkdirp@^0.5.1: resolved "https://registry.yarnpkg.com/mkdirp/-/mkdirp-0.5.1.tgz#30057438eac6cf7f8c4767f38648d6697d75c903" integrity sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM= dependencies: - minimist "0.2.1" + minimist "0.0.8" modify-values@^1.0.0: version "1.0.1" @@ -10282,7 +10318,7 @@ optimist@^0.6.1: resolved "https://registry.yarnpkg.com/optimist/-/optimist-0.6.1.tgz#da3ea74686fa21a19a111c326e90eb15a0196686" integrity sha1-2j6nRob6IaGaERwybpDrFaAZZoY= dependencies: - minimist "~0.2.1" + minimist "~0.0.1" wordwrap "~0.0.2" optionator@^0.8.1, optionator@^0.8.3: @@ -11189,7 +11225,7 @@ rc@^1.0.1, rc@^1.1.6: dependencies: deep-extend "^0.6.0" ini "~1.3.0" - minimist "^1.2.5" + minimist "^1.2.0" strip-json-comments "~2.0.1" react-hook-form@^4.10.1: @@ -11401,6 +11437,14 @@ redent@^2.0.0: indent-string "^3.0.0" strip-indent "^2.0.0" +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" + regenerate-unicode-properties@^8.1.0: version "8.1.0" resolved "https://registry.yarnpkg.com/regenerate-unicode-properties/-/regenerate-unicode-properties-8.1.0.tgz#ef51e0f0ea4ad424b77bf7cb41f3e015c70a3f0e" @@ -11819,7 +11863,7 @@ sane@^4.0.3: execa "^1.0.0" fb-watchman "^2.0.0" micromatch "^3.1.4" - minimist "^1.2.5" + minimist "^1.1.1" walker "~1.0.5" sax@>=0.6.0: @@ -12558,7 +12602,7 @@ strong-log-transformer@^2.0.0: integrity sha512-B3Hgul+z0L9a236FAUC9iZsL+nVHgoCJnqCbN588DjYxvGXaXaaFbfmQ/JhvKjZwsOukuR72XbHv71Qkug0HxA== dependencies: duplexer "^0.1.1" - minimist "^1.2.5" + minimist "^1.2.0" through "^2.3.4" style-loader@^1.1.3: From fe1aab50593e77a722bae646d66901ccb5be4d9f Mon Sep 17 00:00:00 2001 From: Peter Pistorius Date: Thu, 19 Mar 2020 20:36:56 +0100 Subject: [PATCH 5/9] Configure jest-dom. --- packages/core/config/jest.config.web.js | 5 ++++- packages/core/config/jest.setup.web.js | 1 + packages/core/package.json | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) create mode 100644 packages/core/config/jest.setup.web.js diff --git a/packages/core/config/jest.config.web.js b/packages/core/config/jest.config.web.js index e761d84d9dc9..1fe2e900adf7 100644 --- a/packages/core/config/jest.config.web.js +++ b/packages/core/config/jest.config.web.js @@ -1,9 +1,12 @@ // used by cli `rw test` command -// note: rootDir is a workaround for jest working directory weirdness + +const path = require('path') + module.exports = { resolver: 'jest-directory-named-resolver', rootDir: process.cwd(), globals: { __REDWOOD__API_PROXY_PATH: '/', }, + setupFilesAfterEnv: [path.resolve(__dirname, './jest.setup.web.js')], } diff --git a/packages/core/config/jest.setup.web.js b/packages/core/config/jest.setup.web.js new file mode 100644 index 000000000000..70c547240849 --- /dev/null +++ b/packages/core/config/jest.setup.web.js @@ -0,0 +1 @@ +require('@testing-library/jest-dom') diff --git a/packages/core/package.json b/packages/core/package.json index 87f6341283ff..5c991a507c41 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -20,6 +20,7 @@ "@redwoodjs/dev-server": "^0.2.5", "@redwoodjs/eslint-config": "^0.2.5", "@redwoodjs/internal": "^0.2.5", + "@testing-library/jest-dom": "^5.1.1", "@testing-library/react": "^9.5.0", "@types/jest": "^25.1.3", "@types/node": "^13.7.7", @@ -42,7 +43,6 @@ "html-webpack-plugin": "^3.2.0", "jest": "^25.1.0", "jest-directory-named-resolver": "^0.3.0", - "@testing-library/jest-dom": "^5.1.1", "lodash.escaperegexp": "^4.1.2", "mini-css-extract-plugin": "^0.9.0", "prisma2": "2.0.0-preview023", From a6f6b619206b80e5f6074bcd2f0f37cb610a9124 Mon Sep 17 00:00:00 2001 From: Peter Pistorius Date: Thu, 19 Mar 2020 20:56:07 +0100 Subject: [PATCH 6/9] Add eslint rules for jest dom. --- packages/eslint-config/index.js | 2 ++ packages/eslint-config/package.json | 1 + yarn.lock | 27 ++++++++++++++++++++++----- 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/packages/eslint-config/index.js b/packages/eslint-config/index.js index e9624f368b0d..47ffaa3061f6 100644 --- a/packages/eslint-config/index.js +++ b/packages/eslint-config/index.js @@ -19,6 +19,7 @@ module.exports = { 'jsx-a11y', 'react', 'react-hooks', + 'jest-dom', '@redwoodjs/redwood', ], ignorePatterns: ['node_modules', 'dist'], @@ -26,6 +27,7 @@ module.exports = { 'eslint:recommended', 'plugin:react/recommended', 'plugin:prettier/recommended', + 'plugin:jest-dom/recommended', 'prettier/react', ], overrides: [ diff --git a/packages/eslint-config/package.json b/packages/eslint-config/package.json index a8c4ef9944b9..2383547d88eb 100644 --- a/packages/eslint-config/package.json +++ b/packages/eslint-config/package.json @@ -17,6 +17,7 @@ "eslint-plugin-prettier": "^3.1.2", "eslint-plugin-react": "^7.19.0", "eslint-plugin-react-hooks": "^2.5.0", + "eslint-plugin-jest-dom": "^2.0.1", "prettier": "^1.19.1" }, "gitHead": "2801c132f40263f9fcfbdac8b1750d2e423eb649" diff --git a/yarn.lock b/yarn.lock index dd447eff5bb9..3145d9406183 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6151,6 +6151,13 @@ eslint-plugin-import@^2.20.1: read-pkg-up "^2.0.0" resolve "^1.12.0" +eslint-plugin-jest-dom@^2.0.1: + version "2.0.1" + resolved "https://registry.yarnpkg.com/eslint-plugin-jest-dom/-/eslint-plugin-jest-dom-2.0.1.tgz#6df85a46992a86ac800b23304a9285b8c5d701f5" + integrity sha512-LY2BP5ucZbKO58I71QHnjH18YcL/XFarZEKBB3aQH+BKtMO+Da4t756JfnCpR4ELydYOr5B0DB8hzjgeQlhLBw== + dependencies: + requireindex "~1.2.0" + eslint-plugin-jsx-a11y@^6.2.3: version "6.2.3" resolved "https://registry.yarnpkg.com/eslint-plugin-jsx-a11y/-/eslint-plugin-jsx-a11y-6.2.3.tgz#b872a09d5de51af70a97db1eea7dc933043708aa" @@ -9646,16 +9653,21 @@ minimist-options@^3.0.1: arrify "^1.0.1" is-plain-obj "^1.1.0" -minimist@0.2.1, minimist@~0.2.1: - version "0.2.1" - resolved "https://registry.yarnpkg.com/minimist/-/minimist-0.2.1.tgz#827ba4e7593464e7c221e8c5bed930904ee2c455" - integrity sha512-GY8fANSrTMfBVfInqJAY41QkOM+upUTytK1jZ0c8+3HdHrJxBJ3rF5i9moClXTE8uUSnUo8cAsCoxDXvSY4DHg== +minimist@0.0.8: + version "0.0.8" + resolved "https://registry.yarnpkg.com/minimist/-/minimist-0.0.8.tgz#857fcabfc3397d2625b8228262e86aa7a011b05d" + integrity sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0= -minimist@^1.2.5: +minimist@^1.1.1, minimist@^1.1.3, minimist@^1.2.0: version "1.2.5" resolved "https://registry.yarnpkg.com/minimist/-/minimist-1.2.5.tgz#67d66014b66a6a8aaa0c083c5fd58df4e4e97602" integrity sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw== +minimist@~0.0.1: + version "0.0.10" + resolved "https://registry.yarnpkg.com/minimist/-/minimist-0.0.10.tgz#de3f98543dbf96082be48ad1a0c7cda836301dcf" + integrity sha1-3j+YVD2/lggr5IrRoMfNqDYwHc8= + minipass@^2.3.5, minipass@^2.6.0, minipass@^2.8.6, minipass@^2.9.0: version "2.9.0" resolved "https://registry.yarnpkg.com/minipass/-/minipass-2.9.0.tgz#e713762e7d3e32fed803115cf93e04bca9fcc9a6" @@ -11639,6 +11651,11 @@ require-main-filename@^2.0.0: resolved "https://registry.yarnpkg.com/require-main-filename/-/require-main-filename-2.0.0.tgz#d0b329ecc7cc0f61649f62215be69af54aa8989b" integrity sha512-NKN5kMDylKuldxYLSUfrbo5Tuzh4hd+2E8NPPX02mZtn1VuREQToYe/ZdlJy+J3uCpfaiGF05e7B8W0iXbQHmg== +requireindex@~1.2.0: + version "1.2.0" + resolved "https://registry.yarnpkg.com/requireindex/-/requireindex-1.2.0.tgz#3463cdb22ee151902635aa6c9535d4de9c2ef1ef" + integrity sha512-L9jEkOi3ASd9PYit2cwRfyppc9NoABujTP8/5gFcbERmo5jUoAKovIC3fsF17pkTnGsrByysqX+Kxd2OTNI1ww== + requires-port@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/requires-port/-/requires-port-1.0.0.tgz#925d2601d39ac485e091cf0da5c6e694dc3dcaff" From a75d49105d27839b37996016229e7be80abe92d1 Mon Sep 17 00:00:00 2001 From: Peter Pistorius Date: Thu, 19 Mar 2020 21:28:05 +0100 Subject: [PATCH 7/9] Make tests for cell test the results in dom. --- .../generate/templates/cell/test.js.template | 31 +++++++++++-------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/packages/cli/src/commands/generate/templates/cell/test.js.template b/packages/cli/src/commands/generate/templates/cell/test.js.template index 88343cab33d4..23472092a157 100644 --- a/packages/cli/src/commands/generate/templates/cell/test.js.template +++ b/packages/cli/src/commands/generate/templates/cell/test.js.template @@ -1,4 +1,4 @@ -import { render, cleanup } from '@testing-library/react' +import { render, cleanup, screen } from '@testing-library/react' import { Loading, Empty, Failure, Success } from './${pascalName}Cell' @@ -6,24 +6,29 @@ describe('${pascalName}Cell', () => { afterEach(() => { cleanup() }) + it('Loading renders successfully', () => { - expect(() => { - render() - }).not.toThrow() + render() + // Use screen.debug() to see output. + expect(screen.queryByText('Loading...')).toBeInTheDocument() }) + it('Empty renders successfully', () => { - expect(() => { - render() - }).not.toThrow() + render() + expect(screen.queryByText('Empty')).toBeInTheDocument() }) + it('Failure renders successfully', () => { - expect(() => { - render() - }).not.toThrow() + render() + expect(screen.queryByText('Error: On no!')).toBeInTheDocument() }) + it('Success renders successfully', () => { - expect(() => { - Success({ ${camelName}: { objectKey: 'objectValue' } }) - }).not.toThrow() + render( + + ) + expect( + screen.queryByText('{"${camelName}":{"objectKey":"objectValue"}}') + ).toBeInTheDocument() }) }) From d7356a411db02bf59277515e78a36705dfc1b85b Mon Sep 17 00:00:00 2001 From: Peter Pistorius Date: Fri, 20 Mar 2020 08:03:45 +0100 Subject: [PATCH 8/9] Fix typo. --- .../cli/src/commands/generate/templates/cell/test.js.template | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/cli/src/commands/generate/templates/cell/test.js.template b/packages/cli/src/commands/generate/templates/cell/test.js.template index 23472092a157..c30035e8dfdb 100644 --- a/packages/cli/src/commands/generate/templates/cell/test.js.template +++ b/packages/cli/src/commands/generate/templates/cell/test.js.template @@ -19,8 +19,8 @@ describe('${pascalName}Cell', () => { }) it('Failure renders successfully', () => { - render() - expect(screen.queryByText('Error: On no!')).toBeInTheDocument() + render() + expect(screen.queryByText('Error: Oh no!')).toBeInTheDocument() }) it('Success renders successfully', () => { From 6f77c7a33f24e59466400436d73721fe729710e6 Mon Sep 17 00:00:00 2001 From: Peter Pistorius Date: Fri, 20 Mar 2020 08:55:27 +0100 Subject: [PATCH 9/9] Use args in execa. --- packages/cli/src/commands/test.js | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/packages/cli/src/commands/test.js b/packages/cli/src/commands/test.js index b57e24ba6e10..19bd46a81395 100644 --- a/packages/cli/src/commands/test.js +++ b/packages/cli/src/commands/test.js @@ -16,23 +16,29 @@ export const handler = async ({ app }) => { const execCommands = { api: { cwd: `${BASE_DIR}/api`, - cmd: - 'yarn jest --passWithNoTests --config ../node_modules/@redwoodjs/core/config/jest.config.api.js', + cmd: 'yarn jest', + args: [ + '--passWithNoTests', + '--config ../node_modules/@redwoodjs/core/config/jest.config.api.js', + ], }, web: { cwd: `${BASE_DIR}/web`, - cmd: - 'yarn jest --passWithNoTests --config ../node_modules/@redwoodjs/core/config/jest.config.web.js', + cmd: 'yarn jest', + args: [ + '--passWithNoTests', + '--config ../node_modules/@redwoodjs/core/config/jest.config.web.js', + ], }, } const tasks = new Listr( app.map((appName) => { - const { cwd, cmd } = execCommands[appName] + const { cmd, args, cwd } = execCommands[appName] return { title: `Running '${appName}' jest tests`, task: () => { - return execa(cmd, undefined, { + return execa(cmd, args, { stdio: 'inherit', shell: true, cwd,