To capture code coverage on your backend server, you need to run it using our Node.js test listener agent.
Code Block |
---|
Unix: ./node_modules/.bin/npx slnodejs run --tokenfile ./path/to/sltoken.txt --buildsessionidfile buildSessionId [--labid <Lab ID>] --workspacepath "." --useinitialcolor true --useslnode2 -- /your/backend/server/command Windows: call .\node_modules\.bin\slnodejs run --tokenfile \path\to\sltoken.txt --buildsessionidfile buildSessionId [--labid <Lab ID>] --workspacepath "." --useinitialcolor true --useslnode2 -- \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/npx slnodejs run --tokenfile ./sltoken.txt --buildsessionidfile buildSessionId --labid "LAB_ID_2" --workspacepath "./server" --useinitialcolor true --useslnode2 -- "./server/app.js"
...
Info |
---|
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:
Code Block |
---|
ENV SL_labId=integ_test_otel
ENV NODE_OPTIONS="--require ./node_modules/slnodejs/lib/preload.js"
ENTRYPOINT [ "node", "--require", "./tracing.js", "index.js" ] |