Continuous integration of the AWS web application

Note

This is an advanced topic that is closely tied with the further development and customization of the nRF Asset Tracker for your purposes. See the GitHub project page of the nRF Asset Tracker Web Application for AWS for an implementation of the process outlined in this section.

Every change to the project is tested using a head-less browser with the Playwright framework. This ensures that all dependencies of the web application work as intended and present the data in the correct way.

Running end-to-end tests during development

The end-to-end tests run against an instance of the nRF Asset Tracker for AWS.

Use either the credentials you created, when setting up the solution, or enable the Web App CI feature and use the dedicated credentials created for this task. The latter option is the recommended approach since it limits the permissions to only the ones needed. You can also use the credentials to run the end-to-end tests on GitHub Actions.

  1. Add the following environment variables to your .envrc file:

    # add to .envrc
    export AWS_REGION="your preferred AWS region"
    export AWS_ACCESS_KEY_ID="value of Access key ID"
    export AWS_SECRET_ACCESS_KEY="value of Secret access key"
    export WEBAPP_STACK_NAME="name of your web application stack"
  2. Run the following command to allow the changed .envrc file:

    direnv allow
    
  3. You can then run the tests using the following command:

    npx playwright test
    

Playwright Inspector

For developing tests, it is helpful to run the Playwright Inspector.

To enable the inspector during the tests, run:

PWDEBUG=1 npx playwright test

Running end-to-end tests using GitHub Actions

The Test and Release workflow runs the end-to-end tests for every commit. For this to work, you need a running instance of nRF Asset Tracker for AWS. The tests run against this instance. Typically, it is the production instance, to ensure that the web application works with the current production setup. Follow the Getting started guide to set up the instance to be used for the tests.

The test runner needs to interact with the instance to retrieve the application configuration and to provide test data. You need to configure AWS credentials as GitHub environment secrets.

  1. Enable the web application CI of the nRF Asset Tracker for AWS:

    ./cli.sh configure context stack web-app-ci 1
    
  2. Acquire the secrets using the nRF Asset Tracker for AWS CLI:

    ./cli.sh web-app-ci
    
  3. Set the secrets:

  • Set the secrets using the GitHub UI:

    Set the following secrets to an environment called production in your fork of the nRF Asset Tracker for AWS:

    • AWS_REGION

    • AWS_ROLE

    • WEBAPP_STACK_NAME

  • Alternatively, set the secrets using the GitHub CLI:

    You can use the GitHub CLI with the environment settings from above (make sure to create the production deployment environment in your repository first):

    gh secret set AWS_REGION --env production --body "${AWS_REGION}"
    gh secret set AWS_ACCESS_KEY_ID --env production --body "${AWS_ROLE}"
    gh secret set WEBAPP_STACK_NAME --env production --body "${WEBAPP_STACK_NAME}"