|
| 1 | +## Unit Tests |
| 2 | + |
| 3 | + |
| 4 | + |
| 5 | + |
| 6 | + |
| 7 | + |
| 8 | +Unit testing is handled using Jest. Code coverage for unit tests must remain above 90%. |
| 9 | + |
| 10 | +Run unit tests via `npm test`. |
| 11 | + |
| 12 | +A coverage report is shown in the inline test results. A browseable coverage report is also output to `./coverage/lcov-report/index.html` |
| 13 | + |
| 14 | +When running unit tests from a CICD pipline, the environment variable `CI` should be set to `true` before executing the test. |
| 15 | +`CI=true npm test` |
| 16 | + |
| 17 | +## Code Formatting |
| 18 | + |
| 19 | +[](https://github.com/prettier/prettier) |
| 20 | + |
| 21 | +Code styling is managed with [Prettier](https://github.com/prettier/prettier) to reduce churn from developers using different coding styles. Code will be automatically formatted on commit as long as you have run `npm install` after checking out the repo. Rules are exposed to code editors and validation tools using [ESLint](https://www.npmjs.com/package/eslint) |
| 22 | + |
| 23 | +Plugins: |
| 24 | + |
| 25 | +- `eslint` - Defines code linting rules |
| 26 | +- `babel-eslint` - Best practices for projects using babel |
| 27 | +- `eslint-config-airbnb` - AirBnB rules for React and Prettier |
| 28 | +- `eslint-plugin-react` - React-specific rules |
| 29 | +- `eslint-plugin-import` - Consistent module import rules |
| 30 | +- `eslint-config-prettier` - Turn off ESLint rules that conflict with Prettier |
| 31 | +- `eslint-plugin-jsx-a11y` - Ensure developers are considering accessibility when writing code |
| 32 | +- `eslint-plugin-react-hooks` - Follow best practices for using React hooks |
| 33 | +- `prettier` - opinionated code styling |
| 34 | +- `pretty-quick` - format code on commit |
| 35 | + |
| 36 | +To ensure your editor will style code automatically, make sure you have support installed for `.editorconfig` and `.eslint`. For example, VSCode has both plugins for both [editorconfig](https://marketplace.visualstudio.com/items?itemName=EditorConfig.EditorConfig) and [ESLint](https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint) that will pick up the respective configuration files and assist you in formatting your code. |
| 37 | + |
| 38 | +## Commit Messages |
| 39 | + |
| 40 | +Commit messages shouldn't be just "_fixing x_" or "_adding y_". They should explain **why** a change was made so that it is useful for future developers looking at the history. Include links to relevant documents or external library bug reports, and include ticket numbers where appropriate. |
| 41 | + |
| 42 | +### Commit Message Syntax |
| 43 | + |
| 44 | +In order to facilitate [automated changelogs and versionsing](#releases) all git commits are expected to follow the [Angular commit syntax](https://gist.github.com/stephenparish/9941e89d80e2bc58a153). This is enforced using `commitlint` triggered by `husky`. |
| 45 | + |
| 46 | +``` |
| 47 | +<prefix>(<scope>):<subject> |
| 48 | +
|
| 49 | +<longer message> |
| 50 | +
|
| 51 | +<footer> |
| 52 | +``` |
| 53 | + |
| 54 | +Valid prefixes: |
| 55 | + |
| 56 | +- `fix`: Bugfixes (avoid mixing bugfixes and features in the same commit) |
| 57 | +- `docs`: Documentation |
| 58 | +- `feat`: Features and new functionality |
| 59 | +- `test`: Adding unit tests without functional code changes |
| 60 | +- `style`: Changes to code styling only (eg. single vs double quotes, spaces vs tabs). **Do not confuse this with CSS styling** |
| 61 | +- `refactor`: Internal changes (non-functional) only. Should have no changes to unit tests |
| 62 | +- `chore`: Project maintenance |
| 63 | + |
| 64 | +**When a commit contains a breaking change, the footer must begin with: `BREAKING CHANGE:`** so that release versions can properly reflect semantic versioning rules. Breaking changes should also document what other developers will need to do in order to accomidate the change. Breaking changes are those that are not backwards compatible, and change how this project is consumed (APIs, paths to includable libraries, run commands, etc). |
| 65 | + |
| 66 | +#### Skipping CICD pipelines |
| 67 | + |
| 68 | +Automated CICD Pipelines can be skipped on a particular commit by appending the flag `[skip-ci]`. This normally should only be done when the pipelines themselves make commits in order to prevent runaway builds. |
| 69 | + |
| 70 | +## Releases |
| 71 | + |
| 72 | +[](https://github.com/semantic-release/semantic-release) |
| 73 | +This project follows [Semantic Versioning](https://docs.npmjs.com/about-semantic-versioning) guidelines for release numbers. |
| 74 | + |
| 75 | +New versions of the project are automaticaly released via the CI/CD pipeline, which runs Semantic Release via the command `npm run semantic-release` |
| 76 | + |
| 77 | +This automates several tasks in the release process via plugins: |
| 78 | + |
| 79 | +- `@semantic-release/commit-analyzer` - Analyzes commit syntax to determine versioning and changelog |
| 80 | +- `@semantic-release/release-notes-generator` - Builds the release notes from the commit messages |
| 81 | +- `@semantic-release/changelog` - Generates changelog |
| 82 | +- `@semantic-release/git` - Tags the releaase in the git repo |
| 83 | +- `@semantic-release/github` - Adds a release version and changelog notes to a GitHub project |
| 84 | +- `@semantic-release/npm` - Updates the version number in package.json (and pushes to NPM if `npmPublish` is not set to `false`) |
| 85 | + |
| 86 | +### Publishing releases |
| 87 | + |
| 88 | +#### Releasing from local |
| 89 | + |
| 90 | +The versioning and release process is automated using `semantic-release`. The following command should be run only by the CICD pipeline, and only on the latest commit on the `master` branch: |
| 91 | + |
| 92 | +`GITHUB_TOKEN=<insert github token> NPM_TOKEN=<insert npm token> npm run test:badges && npm run semantic-release` |
| 93 | + |
| 94 | +#### Release from CICD pipelines |
| 95 | + |
| 96 | +The CICD server must provide the following environment variables: |
| 97 | + |
| 98 | +- `GITHUB_TOKEN` - API Token from Github provisioned with API scope |
| 99 | +- `NPM_TOKEN` - API Token from NPM with permissions to publish on this registry |
| 100 | + |
0 commit comments