To capture code coverage on your backend server, you need to run it using our Node.js test listener agent.
Unix: ./node_modules/.bin/slnodejs run --tokenfile /path/to/sltoken.txt --buildsessionidfile buildSessionId [--labid <Lab ID>] --workspacepath "." --useinitialcolor true -- /your/backend/server/command Windows: call .\node_modules\.bin\slnodejs run --tokenfile \path\to\sltoken.txt --buildsessionidfile buildSessionId [--labid <Lab ID>] --workspacepath "." --useinitialcolor true -- \your\backend\server\command
Note the /your/backend/server/command
from above refers to "./server/app.js"
in the example of command below:
./node_modules/.bin/slnodejs run --tokenfile ./sltoken.txt --buildsessionidfile buildSessionId --labid "LAB_ID_2" --workspacepath "./server" --useinitialcolor true --useslnode2 -- "./server/app.js"
When the application is up and running and the Sealights Listener agent configured, you can see it properly running as a new entry in the Cockpit -> Live Agents Monitor screen.
You also have the ability to validate the startup parameters in use with your application via the following commands
Linux:
ps -ef | grep slnodejs
Windows:
C:\\Windows\\System32\\wbem\\WMIC.exe process where "name like '%slnodejs%'" get commandline,processid
(CMD prompt)
For distributed Test Runner & Test Listener, we recommend using the Lab ID parameter in order to link between the two.
If the lab ID is not provided, the session ID will be used as a Lab ID
See 'Node.js Command Reference - Running backend server' for full parameter details
Running backend server using SeaLights agent and preload.js
To run your backend service with Sealights without changing the startup command, use the preload.js
file and the NODE_OPTIONS
environment variable. This is a common practice in docker containers where the ENTRYPOINT
cannot be modified.
The agent contains a
preload.js
file undernode_modules/slnodejs/lib/preload.js
. You use it by setting the environment variable:NODE_OPTIONS="--require ./node_modules/slnodejs/lib/preload.js"
In the current working directory, the agent will search for the token in the file
sltoken.txt
and the build session ID in the filebuildSessionId
.Other parameters can be passed to the agent using the following syntax:
SL_
+ {command line flag}. For instance, to pass the lab ID, you can setSL_labId=my_lab_id
Sample docker file:
ENV SL_labId=integ_test_otel ENV NODE_OPTIONS="--require ./node_modules/slnodejs/lib/preload.js" ENTRYPOINT [ "node", "--require", "./tracing.js", "index.js" ]