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
- Husky for running tasks via git hooks
- Hygen for component and util generators
- Jest for unit tests
- Loki for visual testing
- Prettier for code formatting (π¨ DO NOT enable the VS Code Prettier pluginβESLint runs it for you under the hood. π)
- Storybook for component playground (and used by Loki)
- TypeScript for Static Typing in JavaScript (Learn)
Run these commands from project root.
- Install NVM (Node Version Manager)
nvm install
(in new sessions runnvm use
to load version specified in.nvmrc
unless aliased to default)npm i -g npm@latest
(npm@v7+ required)npm i
(install project dependencies)- Install the ESLint plugin for
your editorVS Code and enable "Fix on Save" insettings.json
:{ "editor.codeActionsOnSave": { "source.fixAll.eslint": true } }
Go to settings (
β + ,
), searchcodeActionsOnSave
and click "Edit in settings.json", then add"editor.codeActionsOnSave": {...}
within the existing JSON object."But I don't use VS Code." That's fine but you're on your own. π
π¨ DO NOT enable the VS Code Prettier plugin for this projectβESLint runs it for you under the hood. π
- Install Docker Desktop
Run the following scripts with npm run <SCRIPT_HERE>
:
start
- start appnew:component
- generate a new componentnew:util
- generate a new util(ity)new:type
- generate a new typetest: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 (requiresgraphviz
to be installed on your device)deps:report
- run dependency validation and generate an HTML report
These scripts are located in
package.json
and do not represent the entirety of available scripts, but are the most commonly used.
Below is the project's file-tree with notes added as inline comments.
Uninteresting info is denoted by
...
.
βββ .github # π PR/Issue Templates, workflows, and Renovate config
βββ .loki # π Loki provides visual regression testing of Storybook files
β βββ current # π Images from current test run
β β βββ chrome_App_Example.png
β βββ difference # π Differences from current test run
β βββ reference # π Approved reference images
β β βββ chrome_App_Example.png
β βββ .gitignore # π `./current` and `./difference` are not tracked
βββ .storybook # π Storybook config
βββ cypress # π Cypress integration testing
β βββ fixtures # π Test data
β β βββ example.json
β βββ integration # π Tests go here
β β βββ sample_spec.ts
β βββ ...
βββ public # π Static files
βββ src
β βββ assets # π fonts, images, etc.
β β βββ logo.svg
β βββ components # π Use `npm run new:component` to generate
β β βββ App
β β β βββ README.md # π Every component has a README
β β β βββ index.tsx # π Contains main implementation
β β β βββ stories.tsx # π Component stories; use `npm run test:playground` to run
β β β βββ styles.css # π Component styles (not included in generated code)
β β β βββ test.tsx # π Component tests; use `npm run test:unit` to run
β β βββ README.md # π Every top-level directory in `src` has a README.md
β βββ types # π Type definitions go here; use `npm run new:type` to generate
β β βββ README.md
β βββ utils # π Utilities go here; use `npm run new:util` to generate
β β βββ README.md
β βββ index.css # π Root styles
β βββ index.tsx # π Root application file
β βββ react-app-env.d.ts # π Extends react-scripts TypeScript definitions
β βββ reportWebVitals.ts # π Useful, but not required
β βββ serviceWorker.ts # π Useful, but not required
β βββ setupTests.ts # π Top-level setup for Jest test runs
βββ .dependency-cruiser.js # π Dependency Cruiser config
βββ .eslintrc.js # π ESLint - Run Commands
βββ .gitattributes # π Git meta information
βββ .gitignore # π Git ignore patterns
βββ .nvmrc # π Node Version Manager - Run Commands
βββ .prettierrc.js # π Prettier - Run Commands
βββ LICENSE # π LICENSE π
βββ README.md # π π π YOU ARE HERE
βββ cypress.json # π Cypress config
βββ package-lock.json
βββ package.json
βββ tsconfig.json # π TypeScript config and extends
- Use the code generators:
npm run new:component
npm run new:type
npm run new:util
- Fill out the
README.md
to describe what your code does - Run your unit tests
npm run test:unit
while working to see immediate feedback - If you get stuck at any point, just log an issue and we'll figure it out together π.