diff --git a/.github/workflows/ci-build.yaml b/.github/workflows/ci-build.yaml index f98c454..ee2fc68 100644 --- a/.github/workflows/ci-build.yaml +++ b/.github/workflows/ci-build.yaml @@ -23,7 +23,11 @@ jobs: runs-on: ubuntu-latest steps: - name: 'Checkout' - uses: actions/checkout@v2 + uses: actions/checkout@v4 + + - uses: actions/setup-node@v4 + with: + node-version: '20.x' - name: 'Run linting' run: make lint @@ -33,7 +37,7 @@ jobs: - name: 'Run tests' run: | - sleep 10 + sleep 5 make test-report - name: 'Test reporting' @@ -41,7 +45,7 @@ jobs: id: test-report if: success() || failure() with: - name: Unit Test Report + name: Integration Test Report path: test-results.xml reporter: java-junit fail-on-error: false @@ -50,9 +54,10 @@ jobs: name: 'Build & push image' needs: test runs-on: ubuntu-latest + if: github.ref == 'refs/heads/master' && github.event_name == 'push' steps: - name: 'Checkout' - uses: actions/checkout@v2 + uses: actions/checkout@v4 # Nicer than using github runid, I think, will be picked up automatically by make - name: 'Create datestamp image tag' @@ -63,7 +68,6 @@ jobs: # Only when pushing to default branch (e.g. master or main), then push image to registry - name: 'Push to container registry' - if: github.ref == 'refs/heads/master' && github.event_name == 'push' run: | echo ${{ secrets.GITHUB_TOKEN }} | docker login $IMAGE_REG -u $GITHUB_ACTOR --password-stdin make push diff --git a/README.md b/README.md index a43edd4..508fc4d 100644 --- a/README.md +++ b/README.md @@ -53,9 +53,8 @@ push ๐Ÿ“ค Push container image to registry run ๐Ÿƒ Run locally using Node.js deploy ๐Ÿš€ Deploy to Azure Container App undeploy ๐Ÿ’€ Remove from Azure -test ๐ŸŽฏ Unit tests with Jest -test-report ๐Ÿคก Unit tests with Jest & Junit output -test-api ๐Ÿšฆ Run integration API tests, server must be running +test ๐Ÿšฆ Run integration tests, server must be running +test-report ๐Ÿคก Tests but with JUnit output, server must be running clean ๐Ÿงน Clean up project ``` @@ -93,6 +92,23 @@ A set of GitHub Actions workflows are included for CI / CD. Automated builds for [![](https://img.shields.io/github/workflow/status/benc-uk/nodejs-demoapp/CI%20Build%20App)](https://github.com/benc-uk/nodejs-demoapp/actions?query=workflow%3A%22CI+Build+App%22) [![](https://img.shields.io/github/workflow/status/benc-uk/nodejs-demoapp/CD%20Release%20-%20AKS?label=release-kubernetes)](https://github.com/benc-uk/nodejs-demoapp/actions?query=workflow%3A%22CD+Release+-+AKS%22) +# Testing + +This project uses a HTTP files located in `src/tests/` that can be used a few different ways, you can instal the [VSCode REST CLient](https://marketplace.visualstudio.com/items?itemName=humao.rest-client) or [httpYac](https://marketplace.visualstudio.com/items?itemName=anweber.vscode-httpyac), [httpYac](https://httpyac.github.io/) is preferred as it supports many more features. + +You can interactively run & send the requests in the `src/tests` file using these extensions, but the main reason to use _httpYac_, is it has a much richer language & the support of assertions which can turn the request files into integration tests too ๐Ÿ‘Œ + +For example: + +```http +GET http://localhost:8000/info + +?? status == 200 +?? body contains Memory +``` + +_httpYac_ has a command line tool for running tests and .http files which forms the basis of the `make test` and `make test-report` makefile targets. It also natively supports .env files, so will load variables from a .env file if one is found. + # Optional Features The app will start up and run with zero configuration, however the only features that will be available will be the INFO and TOOLS views. The following optional features can be enabled: diff --git a/src/tests/base-tests.http b/src/tests/base-tests.http index 081bd38..81261fe 100644 --- a/src/tests/base-tests.http +++ b/src/tests/base-tests.http @@ -4,7 +4,7 @@ GET {{baseUrl}}/ ?? status == 200 -?? body contains Ben Coleman +?? body contains Ben ZZZZZZZZZColeman ### Base - Info page diff --git a/src/tests/readme.md b/src/tests/readme.md new file mode 100644 index 0000000..4a31a38 --- /dev/null +++ b/src/tests/readme.md @@ -0,0 +1,16 @@ +### ๐Ÿงช Testing + +This project uses HTTP files located in `src/tests/` that can be used a few different ways, you can instal the [VSCode REST CLient](https://marketplace.visualstudio.com/items?itemName=humao.rest-client) or [httpYac](https://marketplace.visualstudio.com/items?itemName=anweber.vscode-httpyac), [httpYac](https://httpyac.github.io/) is preferred as it supports many more features. + +You can interactively run & send the requests in the `src/tests` file using these extensions, but the main reason to use _httpYac_, is it has a much richer language & the support of assertions which can turn the request files into integration tests too ๐Ÿ‘Œ + +For example + +```http +GET http://localhost:8000/info + +?? status == 200 +?? body contains Memory +``` + +_httpYac_ has a command line tool for running tests and .http files which forms the basis of the `make test` and `make test-report` makefile targets. It also natively supports .env files, so will load variables from a .env file if one is found.