Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Testing] Improve testing capabilities for Web #521

Merged
merged 28 commits into from
May 28, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
d1c0b50
feat(testing): add testing package
RobertBroersma May 8, 2020
a800bd2
fix(core): configure jest to work nicely with testing package
RobertBroersma May 8, 2020
82dad34
Apply suggestions from code review
RobertBroersma May 17, 2020
e91dd44
Include router mock in testing package
RobertBroersma May 17, 2020
d57e587
Merge remote-tracking branch 'origin/rb-testing' into rb-testing
RobertBroersma May 17, 2020
7b86ca9
Rely on dynamic import instead of weird import and add some comments
RobertBroersma May 17, 2020
f8a6728
Merge branch 'master' into rb-testing
RobertBroersma May 17, 2020
9b36d4a
Replace MockedProvider in render by doc explaining how to mock
RobertBroersma May 18, 2020
1ae2a66
Convert routes-auto-loader to Babel plugin
RobertBroersma May 23, 2020
a9c92c5
Move fileMock to testing package
RobertBroersma May 23, 2020
22dcc46
Add README.md according to new guidelines
RobertBroersma May 23, 2020
b2e4aff
Merge branch 'master' into rb-testing
RobertBroersma May 23, 2020
482ee70
Update and resolve @types/react and @types/react-dom
RobertBroersma May 23, 2020
0440885
Simplify import string
RobertBroersma May 25, 2020
95b6ef6
But with the .routes of course
RobertBroersma May 25, 2020
3e34a4b
And without the src
RobertBroersma May 25, 2020
c22124d
Merge branch 'master' into rb-testing
RobertBroersma May 25, 2020
f1587ca
Merge branch 'master' into rb-testing
RobertBroersma May 26, 2020
e57a239
Rename routerMock and implement all exports.
peterp May 28, 2020
0924992
Mock router.
peterp May 28, 2020
c112004
Add a description.
peterp May 28, 2020
a25e05a
Remove Apollo Mock export.
peterp May 28, 2020
abcfbd2
Add comments.
peterp May 28, 2020
9ecba60
Remove testing-library imports.
peterp May 28, 2020
edbac9e
Update README.
peterp May 28, 2020
3637d5c
Fix tests.
peterp May 28, 2020
5ea27e3
Merge pull request #1 from redwoodjs/rb-testing
RobertBroersma May 28, 2020
55b6ca4
Merge branch 'master' into rb-testing
peterp May 28, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/core/config/fileMock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = 'fileMock'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think this file could be part of @redwoodjs/testing

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it could. Do you think it would be a good idea to move other testing stuff like Jest config and the setup files to that @redwoodjs/testing as well? And have the testing package sort of dogfood the rest of the monorepo?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would like to keep configuration in core. In my mind the "core" package is what a user's requires to develop and build a redwood project and the configurations are part of that.

The file mock feels like something that should belong to test, whereas this configuration is something that's using "@redwoodjs/testing" - that distinction may seem a bit loosey-goosey and I'll try to clarify it with better language.

RobertBroersma marked this conversation as resolved.
Show resolved Hide resolved
18 changes: 18 additions & 0 deletions packages/core/config/jest.config.web.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,29 @@

const path = require('path')

const { getPaths } = require('@redwoodjs/internal')

const redwoodPaths = getPaths()

module.exports = {
resolver: 'jest-directory-named-resolver',
rootDir: process.cwd(),
globals: {
__REDWOOD__API_PROXY_PATH: '/',
},
setupFilesAfterEnv: [path.resolve(__dirname, './jest.setup.web.js')],
RobertBroersma marked this conversation as resolved.
Show resolved Hide resolved
moduleNameMapper: {
'^react$': path.resolve(redwoodPaths.base, 'node_modules', 'react'),
'^react-dom$': path.resolve(redwoodPaths.base, 'node_modules', 'react-dom'),
'^@apollo/react-common': path.resolve(
redwoodPaths.base,
'node_modules',
'@apollo/react-common'
),
RobertBroersma marked this conversation as resolved.
Show resolved Hide resolved
'\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga|css)$': path.resolve(
__dirname,
'fileMock.js'
),
'~/web/Routes': '<rootDir>/src/Routes',
},
}
1 change: 1 addition & 0 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"@redwoodjs/dev-server": "^0.6.0",
"@redwoodjs/eslint-config": "^0.6.0",
"@redwoodjs/internal": "^0.6.0",
"@redwoodjs/testing": "*",
"@testing-library/jest-dom": "^5.3.0",
"@testing-library/react": "^10.0.1",
"@types/jest": "^25.1.4",
Expand Down
1 change: 1 addition & 0 deletions packages/testing/.babelrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = { extends: '../../babel.config.js' }
21 changes: 21 additions & 0 deletions packages/testing/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "@redwoodjs/testing",
"version": "0.6.0",
"files": [
"dist"
],
"main": "dist/index.js",
"license": "MIT",
"peerDependencies": {
"@redwoodjs/router": "^0.6.0",
"react": "*"
},
"dependencies": {
"@apollo/react-testing": "^3.1.4",
"@redwoodjs/web": "^0.6.0",
"@testing-library/react": "^10.0.4"
},
"scripts": {
"build": "yarn cross-env NODE_ENV=production babel src -d dist --delete-dir-on-start --extensions \".js,.ts\" --source-maps inline"
}
}
3 changes: 3 additions & 0 deletions packages/testing/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from '@testing-library/react'

export { customRender as render } from './render'
RobertBroersma marked this conversation as resolved.
Show resolved Hide resolved
22 changes: 22 additions & 0 deletions packages/testing/src/render.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import React from 'react'
import { render } from '@testing-library/react'
import { MockedProvider } from '@apollo/react-testing'

import Routes from '~/web/Routes'
RobertBroersma marked this conversation as resolved.
Show resolved Hide resolved

const AllTheProviders = ({ mocks, children }) => {
return (
<MockedProvider mocks={mocks} addTypename={false}>
RobertBroersma marked this conversation as resolved.
Show resolved Hide resolved
<>
<Routes />
{children}
</>
</MockedProvider>
)
}

export const customRender = (ui, options = {}) =>
render(ui, {
wrapper: (props) => <AllTheProviders mocks={options.mocks} {...props} />,
...options,
})
RobertBroersma marked this conversation as resolved.
Show resolved Hide resolved
62 changes: 62 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@
ts-invariant "^0.4.4"
tslib "^1.10.0"

"@apollo/react-common@^3.1.4":
version "3.1.4"
resolved "https://registry.yarnpkg.com/@apollo/react-common/-/react-common-3.1.4.tgz#ec13c985be23ea8e799c9ea18e696eccc97be345"
integrity sha512-X5Kyro73bthWSCBJUC5XYQqMnG0dLWuDZmVkzog9dynovhfiVCV4kPSdgSIkqnb++cwCzOVuQ4rDKVwo2XRzQA==
dependencies:
ts-invariant "^0.4.4"
tslib "^1.10.0"

"@apollo/react-components@^3.1.3":
version "3.1.3"
resolved "https://registry.yarnpkg.com/@apollo/react-components/-/react-components-3.1.3.tgz#8f6726847cd9b0eb4b22586b1a038d29aa8b1da4"
Expand All @@ -60,6 +68,15 @@
ts-invariant "^0.4.4"
tslib "^1.10.0"

"@apollo/react-testing@^3.1.4":
version "3.1.4"
resolved "https://registry.yarnpkg.com/@apollo/react-testing/-/react-testing-3.1.4.tgz#f2e1b9b65a0bd773facf54db4fdb5995d162a72a"
integrity sha512-1eKjN36UfIAnBVmfLbl12vQ/eCjTqYdaU95chGIQzT2uHd5BnasJu0z+MwXBrEs57A9WY9mFvLZxdjzQJXaacA==
dependencies:
"@apollo/react-common" "^3.1.4"
fast-json-stable-stringify "^2.0.0"
tslib "^1.10.0"

"@apollographql/apollo-tools@^0.4.3":
version "0.4.3"
resolved "https://registry.yarnpkg.com/@apollographql/apollo-tools/-/apollo-tools-0.4.3.tgz#938a50aea0935973a75155a73417f2f6fc7ac2ef"
Expand Down Expand Up @@ -967,6 +984,13 @@
dependencies:
regenerator-runtime "^0.13.4"

"@babel/runtime@^7.9.6":
version "7.9.6"
resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.9.6.tgz#a9102eb5cadedf3f31d08a9ecf294af7827ea29f"
integrity sha512-64AF1xY3OAkFHqOb9s4jpgk1Mm5vDZ4L3acHvAml+53nO1XbXLuDodsVpO4OIUsmemlUHMxNdYMNJmsvOwLrvQ==
dependencies:
regenerator-runtime "^0.13.4"

"@babel/template@^7.7.4", "@babel/template@^7.8.3", "@babel/template@^7.8.6":
version "7.8.6"
resolved "https://registry.yarnpkg.com/@babel/template/-/template-7.8.6.tgz#86b22af15f828dfb086474f964dcc3e39c43ce2b"
Expand Down Expand Up @@ -2335,6 +2359,17 @@
dom-accessibility-api "^0.4.2"
pretty-format "^25.1.0"

"@testing-library/dom@^7.2.2":
version "7.2.2"
resolved "https://registry.yarnpkg.com/@testing-library/dom/-/dom-7.2.2.tgz#30ab09cca132fe49b2ca61ccd9ed785c5f0a6fc5"
integrity sha512-g+gT//COYh2FgRrlgcgdkifkjqSk7wQIS7F8jbrf6yoEsh85PJUJ/QtO0bJ9QU7pQPYQgKcgqNJsOs0dlyFYag==
dependencies:
"@babel/runtime" "^7.9.2"
"@types/testing-library__dom" "^7.0.0"
aria-query "^4.0.2"
dom-accessibility-api "^0.4.2"
pretty-format "^25.1.0"

"@testing-library/jest-dom@^5.3.0":
version "5.3.0"
resolved "https://registry.yarnpkg.com/@testing-library/jest-dom/-/jest-dom-5.3.0.tgz#2ae813b8b0eb69e8808f75d3af8efa3f0dc4d7ec"
Expand All @@ -2359,6 +2394,15 @@
"@testing-library/dom" "^7.0.2"
"@types/testing-library__react" "^9.1.3"

"@testing-library/react@^10.0.4":
version "10.0.4"
resolved "https://registry.yarnpkg.com/@testing-library/react/-/react-10.0.4.tgz#8e0e299cd91acc626d81ed8489fdc13df864c31d"
integrity sha512-2e1B5debfuiIGbvUuiSXybskuh7ZTVJDDvG/IxlzLOY9Co/mKFj9hIklAe2nGZYcOUxFaiqWrRZ9vCVGzJfRlQ==
dependencies:
"@babel/runtime" "^7.9.6"
"@testing-library/dom" "^7.2.2"
"@types/testing-library__react" "^10.0.1"

"@tootallnate/once@1":
version "1.1.2"
resolved "https://registry.yarnpkg.com/@tootallnate/once/-/once-1.1.2.tgz#ccb91445360179a04e7fe6aff78c00ffc1eeaf82"
Expand Down Expand Up @@ -2772,6 +2816,15 @@
dependencies:
"@types/jest" "*"

"@types/testing-library__react@^10.0.1":
version "10.0.1"
resolved "https://registry.yarnpkg.com/@types/testing-library__react/-/testing-library__react-10.0.1.tgz#92bb4a02394bf44428e35f1da2970ed77f803593"
integrity sha512-RbDwmActAckbujLZeVO/daSfdL1pnjVqas25UueOkAY5r7vriavWf0Zqg7ghXMHa8ycD/kLkv8QOj31LmSYwww==
dependencies:
"@types/react-dom" "*"
"@types/testing-library__dom" "*"
pretty-format "^25.1.0"

"@types/testing-library__react@^9.1.3":
version "9.1.3"
resolved "https://registry.yarnpkg.com/@types/testing-library__react/-/testing-library__react-9.1.3.tgz#35eca61cc6ea923543796f16034882a1603d7302"
Expand Down Expand Up @@ -3903,6 +3956,15 @@ babel-plugin-tester@^9.0.0:
prettier "^2.0.1"
strip-indent "^3.0.0"

babel-plugin-tester@^9.0.1:
version "9.0.1"
resolved "https://registry.yarnpkg.com/babel-plugin-tester/-/babel-plugin-tester-9.0.1.tgz#9e975a7fe278a49b3bd4b02bd3a77004819863ee"
integrity sha512-q5GXJowxsRefBDhgiZVyNPgIIHsfxtZNnMABxq+vtuoYP2JW8qaiIBBAG9/I0PgRGRpjUDXnn0IhGHGGn7UOcA==
dependencies:
lodash.mergewith "^4.6.2"
prettier "^2.0.1"
strip-indent "^3.0.0"

babel-preset-jest@^25.2.1:
version "25.2.1"
resolved "https://registry.yarnpkg.com/babel-preset-jest/-/babel-preset-jest-25.2.1.tgz#4ccd0e577f69aa11b71806edfe8b25a5c3ac93a2"
Expand Down