The goal of this lab is to create the first stage in our CD pipeline, the test step. We will use what we learnt in lab 2 and replace our hello world pipeline for something more useful.
Given that our application code is not in the root folder, we need to tell GH Actions where to run the commands from. Lets specify that the NPM commands needs to be run from the modern-web-app directory.
defaults:
run:
working-directory: modern-web-app
We also need to tell one of the GH Actions we will use wich version of Node.js we need. We can do that by declaring an environment variable that we can reference later on.
env:
NODE_VERSION: "14.17"
The next step is to simply specify the test job and add it to the pipeline definition:
jobs:
test:
name: Test
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Setup Node.js ${{ env.NODE_VERSION }}
uses: actions/setup-node@v1
with:
node-version: ${{ env.NODE_VERSION }}
- name: Run unit tests
run: |
npm ci
npm run test:unit
- env: To specify environment variables that can be reused across the pipeline definition.
- working-directory: To change the directory from which GH Actions will execute the run commands
- uses: To sepecify already defined GH Actions. You can think of these as reusable actions that you can incorporate in your pipeline, e.g. checkout, setup-node...
- with: To pass parameters to already defined GH Actions.
Once the changes are commited and pushed, the pipeline should run automatically as it is especified to run on push.
git add .
git commit -m "Add test stage to the CI pipeline"
git push
What is continuous testing? Continuous testing is the practice of running many different types of tests—both manual and automated—continually throughout the delivery process with the goal of finding problems as soon as possible.
What is test automation? Test automation is the practices of automating test tasks to make sure the application is ready to be deployed and it meets the pre-defined quality standards.
- Read the instructions
- Replace the hello world job with the new test job
- Push the changes and check the pipeline execution in the Actions tab
- Break the tests, commit and push the changes. Check what happens.