This project includes configuration and tooling that conforms to Crema's baseline best-practices for a Web Application.
π§° Tools Used
- Create React App for simple configuration π
- Cypress for end-to-end testing
- ESLint for code linting
- Hygen for component and util generators
- Jest for unit tests
- Loki for visual testing
- Prettier for code formatting (via ESLint plugin)
- Storybook for component playground (and used by Loki)
- TypeScript for Static Typing in JavaScript (Learn)
- Install Node/NPM
- Install NVM (Node Version Manager)
nvm install 'lts/*' && nvm usenpm i(install project dependencies)- Install the ESLint plugin for
your editorVS Code - Enable "Auto-Fix on Save" in
settings.json:
// There will likely be other settings within this JSON object...
{
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
},
"eslint.validate": [
"javascript",
"javascriptreact",
"typescript",
"typescriptreact"
]
}
Run the following scripts with npm run <SCRIPT_HERE>:
start- start appnew:component- generate a new componentnew:util- generate a new util(ity)test:analyze- run bundle analyzertest:deps- run dependency validation teststest:e2e- run end-to-end teststest:lint:fix- run linter and fix if possibletest:lint- run lintertest:playground- run component playground (storybook)test:unit:coverage- run unit tests with coveragetest:unit- run unit teststest:visual:approve- approve visual changestest:visual:update- update or create visual referencestest:visual- run visual tests (loki)deps:graph- run dependency validation and generate an SVG representing the dependency graph (requiresgraphvizto be installed on your device)deps:report- run dependency validation and generate an HTML report
These scripts are located in
package.jsonand do not represent the entirety of available scripts, but are the most commonly used.
The src directory is where the meat of your app is located. Below is a printout of its file-tree with a description for each part.
src
βββ assets // Fonts, Images, Etc.
βΒ Β βββ logo.svg
βββ components // Create a new one with `npm run new:component`
βΒ Β βββ App
βΒ Β βββ __snapshots__ // Generated by Jest from `test.tsx`
βΒ Β βΒ Β βββ test.tsx.snap
βΒ Β βββ README.md // Documentation
βΒ Β βββ index.css // Styles
βΒ Β βββ index.tsx // Main Module Code
βΒ Β βββ stories.tsx // Playground stories (npm run test:playground)
βΒ Β βββ test.tsx // Unit Tests (Jest)
βββ types // Centralize Type Definitions
βΒ Β βββ Entity.ts // Base Type
βΒ Β βββ EntityThing.ts // A Sub-Type
βΒ Β βββ Id.ts // A Type Alias of `string`
βΒ Β βββ MapStateToProps.ts // Includes our `State`
βΒ Β βββ State.ts // Redux state interface
βΒ Β βββ Thing.ts // Silly example used by `EntityThing`
βββ utils // Create a new one with `npm run new:util`
βΒ Β βββ mySpecialUtil
βΒ Β βΒ Β βββ __snapshots__ // Generated by Jest from `test.ts`
βΒ Β βΒ Β βΒ Β βββ test.tsx.snap
βΒ Β βΒ Β βββ README.md // Documentation
βΒ Β βΒ Β βββ index.tsx // Main Module Code
βΒ Β βΒ Β βββ test.tsx // Unit Tests (Jest)
βΒ Β βββ decoratorCentered // Used in stories.tsx
βΒ Β βββ shallowRender // Used to render components in test.tsx
βββ index.css // Root Styles
βββ index.tsx // Root Module
βββ react-app-env.d.ts // Definitions from create-react-app
βββ serviceWorker.ts // Documentation
- Use the code generators:
npm run new:componentnpm run new:util- When prompted for a name, prefer
camelCasefor utils andCamelCasefor components
- Fill out the
README.mdto describe what your code does - Run your unit tests
npm run test:unitwhile working to see immediate feedback - If you get stuck at any point, just log an issue and we'll figure it out together π.