Xcov19 / mycovidconnect

Automated 911 for Patients
GNU Affero General Public License v3.0
10 stars 55 forks source link

Add Jest testing framework with Babel support #107

Open codecakes opened 3 years ago

codecakes commented 3 years ago

Is your feature request related to a problem? Please describe. We have various github actions to check for integrity, ci and lint checks. What's missing is thorough unit test coverage which tests code logic.

Features like #106 must be testable.

Describe the solution you'd like Add jest testing framework;

See; https://jestjs.io/docs/en/getting-started.html ; In the deps in package.json add ONLY latest versions "dependencies": { "babel-core" "babel-jest" "babel-preset-env" "jest" }

Add presents like:


// babel.config.js
module.exports = {
  presets: [
    ['@babel/preset-env', {targets: {node: 'current'}}],
+    '@babel/preset-typescript',
  ],
};

Make sure to follow our README guide and see how to run tsc runner once you have set this up;

Describe alternatives you've considered alternatives considered were karma, jasmine. but jest has a good OSS backing as well and looks easy to use.

Additional context We need to make sure developer productivity is not hindered while adopting a new test framework.

Xrevolutions commented 3 years ago

I would like to work on this, if it's still available

codecakes commented 3 years ago

Go ahead and send a pr

Xrevolutions commented 3 years ago

Forgive my ignorance, but i can see project is already using create-react-app via react-scripts. which means it already has support for jest and coverage through jest. Also providing custom babel config via .babelrc or babel.config.js is not directly supported by create react app ( AFAIK )

andyderek commented 3 years ago

Yes. I think React-testing-library is built using jest. So Jest should already be in the dependencies. You should be able to use both for testing.

Xrevolutions commented 3 years ago

Just raised a PR #108 , not sure if it's any useful. Since most of the stuff it out of the box. Another observation: There is no need of invoking tsc explicitly for compiling typescript code. react-scripts (CRA) takes care of transpiling

codecakes commented 3 years ago

Just raised a PR #108 , not sure if it's any useful. Since most of the stuff it out of the box. Another observation: There is no need of invoking tsc explicitly for compiling typescript code. react-scripts (CRA) takes care of transpiling

file an issue regarding this. tsc transpiles jsdocs and needs babel 7 for that

codecakes commented 3 years ago

@ksr89 can u look at the comments?

Xrevolutions commented 3 years ago

CRA comes with babel 7 support and we can't change the babel version without ejecting from CRA. There are tools like https://github.com/SoftwareBrothers/better-docs Which supports jsdoc generation for TS as well as JS files

ksr89 commented 3 years ago

@andyderek @Xrevolutions We don't need to use jsdoc for type check, we can use PropTypes for validating the type of the props. https://reactjs.org/docs/typechecking-with-proptypes.html We can use better-docs only to generate documentation from jsdoc.

codecakes commented 3 years ago

@vasynizami make those changes