Running Tests using AVA framework
Gathering coverage and test information using the SeaLights Node.jsTest Listener is done in a few steps:
See 'Generating an Agent token' for instructions on how to generate a token
Starting the Test Listener
First the SeaLights server needs to be notified that a test stage is starting.
Unix:
npx slnodejs start --tokenfile /path/to/sltoken.txt --buildsessionidfile buildSessionId --teststage "Unit Tests"
Windows:
call npx slnodejs start --tokenfile \path\to\sltoken.txt --buildsessionidfile buildSessionId --teststage "Unit Tests"
Running your tests
Functional Tests
Before running your functional tests you need to set up the backend server to receive the test footprints. See 'Using Node.js Agents - Running backend server using SeaLights agent'.
Once set up you now run your tests normally while generating one or more JUnit xml result files to be reported to the SeaLights server.
Unit Tests
In order to report the test and coverage information to SeaLights you need to run AVA while producing coverage information and a junit results file.
For the junit results file, you can use the --tap option of AVA and pipe it into the tap-xunit converter, then finaly redirect this into a junit.xml file. See https://www.npmjs.com/package/tap-xunit for details.
For the coverage you need to run AVA with nyc and the --reporter=json option.
Upload report files
Coverage files
Once done running the unit tests you upload the coverage report files to the SeaLights server using the nycReport option
Unix:
npx slnodejs nycReport --tokenfile /path/to/sltoken.txt --buildsessionidfile buildSessionId
Windows:
call npx slnodejs nycReport --tokenfile \path\to\sltoken.txt --buildsessionidfile buildSessionId
Test results files
Once done running the tests you upload the test results file to the SeaLights server using the uploadReports option
Unix:
npx slnodejs uploadReports --tokenfile /path/to/sltoken.txt --buildsessionidfile buildSessionId --reportFile junit.xml
Windows:
call npx slnodejs uploadReports --tokenfile \path\to\sltoken.txt --buildsessionidfile buildSessionId --reportFile junit.xml
Ending the Test Stage
Finally notify the server that a test stage has ended.
Unix:
npx slnodejs end --tokenfile /path/to/sltoken.txt --buildsessionidfile buildSessionId
Windows:
call npx slnodejs end --tokenfile \path\to\sltoken.txt --buildsessionidfile buildSessionId
Sample
#Install the project dependancies
npm install
# Install nyc and the tap-xunit converter
npm install nyc
npm install tap-xunit
# Install the SeaLights agents
npm i slnodejs
# Scan the source files to provide SeaLights the structure of the project
npx slnodejs scan --tokenfile sltoken.txt --buildsessionidfile buildSessionId.txt --workspacepath "src" --scm git --es6Modules
# Notify SeaLights the Unit Tests are starting
npx slnodejs start --tokenfile sltoken.txt --buildsessionidfile buildSessionId.txt --testStage "Unit Tests"
#Run the unit tests with nyc and creating the junit.xml report file
ENV=test npx nyc --reporter=json ./node_modules/.bin/ava --tap | ./node_modules/.bin/tap-xunit > junit.xml
# Upload the coverage and tests results to SeaLights
npx slnodejs nycReport --tokenfile sltoken.txt --buildsessionidfile buildSessionId.txt
npx slnodejs uploadReports --tokenfile sltoken.txt --buildsessionidfile buildSessionId.txt --reportFile junit.xml
# Notify SeaLights the Unit Tests have finished
npx slnodejs end --tokenfile sltoken.txt --buildsessionidfile buildSessionId.txt