npm install
npm start
npm run build
- build H5Web for productionnpm run storybook:build
- build the component library's Storybook documentation site
npm run lint
- run all linting and code formatting commandsnpm run lint:eslint
- lint all TS and JS files with ESLintnpm run lint:tsc
- type-check the whole project, test files includednpm run lint:prettier
- check that all files have been formatted with Prettiernpm run analyze
- inspect the size and content of the JS bundles (afternpm run build
)
npm run lint:eslint -- --fix
- auto-fix linting issuesnpm run lint:prettier -- --write
- format all files with Prettier
Most editors support fixing and formatting files automatically on save. The configuration for VSCode is provided out of the box, so all you need to do is install the recommended extensions.
npm test
- run unit and feature tests with Jestnpm run cypress
- open the Cypress end-to-end test runner (local dev server must be running in separate terminal)npm run cypress:run
- run end-to-end tests once (local dev server must be running in separate terminal)npm run storybook
- manually test components in isolation in Storybook, at http://localhost:6006
Cypress is used for end-to-end testing but also for visual regression testing. The idea is to take a screenshot (or "snapshot") of the app in a known state and compare it with a previously approved "reference snapshot". If any pixel has changed, the test fails and a diff image highlighting the differences is created.
Taking consistent screenshots across platforms is impossible because the exact
rendering of the app depends on the GPU. For this reason, visual regression
tests are run only on the CI. This is done through an environment variable
called CYPRESS_TAKE_SNAPSHOTS
.
Visual regression tests may fail in the CI, either expectedly (e.g. when implementing a new feature) or unexpectedly (when detecting a regression). When this happens, the diff images and debug screenshots that Cypress generates are uploaded as artifacts of the workflow, which can be downloaded and reviewed.
If the visual regressions are expected, the version-controlled reference
snapshots can be updated by posting a comment in the Pull Request with this
exact text: /approve
. This triggers the Approve snapshots workflow, which
runs Cypress again but this time telling it to update the reference snapshots
when it finds differences and to pass the tests. Once Cypress has updated the
reference snapshots, the workflow automatically opens a PR to merge the new
and/or updated snapshots into the working branch. After this PR is merged, the
visual regression tests in the working branch succeed and the branch can be
merged into main
.
Here is the summarised workflow (also described with screenshots in PR #306):
- Push your working branch and open a PR.
- If the
e2e
job of the Lint & Test CI workflow fails, check out the logs. - If the fail is caused by a visual regression (i.e. if a test fails on a
cy.matchImageSnapshot()
call), download the workflow's artifacts. - Review the snapshot diffs. If the visual regression is unexpected: fix the bug, push it and start from step 2 again. If the visual regression is expected: continue to step 5.
- In the PR, post a comment with
/approve
. - Go to the Actions page and wait for the Approve snapshots workflow to complete.
- Go to the newly opened PR titled Update Cypress reference snapshots.
- Review the new reference snapshots once more and merge the PR.
- Go back to your main PR and wait for the jobs of the Lint & Test workflow to succeed.
- The project's
main
branch is continuously deployed to https://h5web.panosc.eu/ with Netlify. - The component library's Storybook documentation site is deployed to GitHub Pages on every release: https://h5web-docs.panosc.eu
The src/packages
folder contains entry points for the packages published to
NPM: @h5web/lib and
@h5web/app.
To release a new version:
- Check out
main
and pull the latest changes. - Make sure your working tree doesn't have uncommitted changes and that the
latest commit on
main
has passed the CI. - Run
npm version [ patch | minor | major | <new-version> ]
This command bumps the version number in package.json
, commits the change and
then tags the commit with the same version number. The postversion
script then
runs automatically and pushes the new commit and the new tag. This, in turn,
triggers the Release workflow on the CI, which builds and publishes the
packages to NPM and deploys the Storybook site. The workflow is detailed in
issue #358.
Once the Release workflow has completed:
- Make sure the new package versions are available on NPM and that the live Storybook site still works as expected.
- Upgrade and test the packages in apps and code sandboxes, as required.
- Write and publish release notes on GitHub.
To build the packages, run the following commands:
cd packages
npm install
npm run build
To test a package locally, build the packages then run the following commands:
cd lib/dist
npm link
cd /your/test/app
npm link @h5web/lib
If you see an "invalid hook call" error, you may need to alias the
react
andreact-dom
imports to point to your test app'snode_modules
folder.
H5Web uses the Feather icon set.
Icons can be imported as React components from react-icons/fi
.