Skip to content

Commit

Permalink
Check for console.log() in CI (#1156)
Browse files Browse the repository at this point in the history
* Check for console.log() in CI

DEFRA/water-abstraction-team#94

During development, we constantly use `console.log()` to print out and check for expected results. Although they are useful during the development process,
it is very common that we forget to remove them, leading to requested changes during pull requests 😪.

Currently, we use checks within our CI to catch mistakes similar to this such as `.only()` on `describe` and `it` blocks within our unit tests.

```yaml
      # Before we do anything, check we haven't accidentally left any `describe.only()` or `it.only(` statements in the
      # tests
      #
      # Reworking of https://stackoverflow.com/a/21788642/6117745
      - name: Temporary tag check
        run: |
          ! grep -R 'describe.only(\|it.only(' test
```

Aside from the accidental `console.log()` present, there is one instance we do not want the CI to flag. Within `app/server.js` there is a `console.log()`
that is there to log unhandled exceptions. In this case we can change it to 'console.error()' to get around this.

This PR is focused on implementing the checks for `console.log()` when pushing code and changing the `console.log()` within `app/server.js` to `console.error()`.
  • Loading branch information
rvsiyad authored Jul 3, 2024
1 parent d788a7c commit e40ae73
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
8 changes: 8 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,14 @@ jobs:
run: |
! grep -R 'describe.only(\|it.only(' test
# Alongside this, check we haven't accidentally left any `console.log()` while checking results in app and tests
- name: Temporary log check
run: |
if grep -R 'console.log(' ./app/ ./test/; then
echo "console.log statement found. Please remove it."
exit 1
fi
- name: Install Node
uses: actions/setup-node@v4
with:
Expand Down
3 changes: 2 additions & 1 deletion app/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,14 @@ const init = async () => {

const start = async () => {
const server = await init()

await server.start()

return server
}

process.on('unhandledRejection', (err) => {
console.log(err)
console.error(err)
process.exit(1)
})

Expand Down

0 comments on commit e40ae73

Please sign in to comment.