From e40ae736a37e5b429bc4a4b48defe2f3c07c4aed Mon Sep 17 00:00:00 2001 From: Roble Date: Wed, 3 Jul 2024 09:26:38 +0100 Subject: [PATCH] Check for console.log() in CI (#1156) * Check for console.log() in CI https://github.com/DEFRA/water-abstraction-team/issues/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 :sleepy:. 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()`. --- .github/workflows/ci.yml | 8 ++++++++ app/server.js | 3 ++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9a13d16dae..c6e1bebb95 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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: diff --git a/app/server.js b/app/server.js index a2f8c7c9be..e295548aa8 100644 --- a/app/server.js +++ b/app/server.js @@ -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) })