Using Node.js Agents - Scanning and running a ts-node project
To collect coverage information, SeaLights agents must scan the javascript files for the build information.
Scanning a ts-node build
Scanning a build in Node.js is done using the Node.js Build scanner with the scan command flag and requires:
explicit type of files (
.ts
and/or.tsx
) in a dedicated environment variableSL_fileExtensions
scan the application files with the
workspacepath
parameter pointing to the source files directory (.ts
)
Unix | export SL_fileExtensions=".ts,.tsx"
./node_modules/.bin/slnodejs scan --tokenfile /path/to/sltoken.txt --buildsessionidfile buildSessionId --workspacepath "./src" --scm git |
Windows | set SL_fileExtensions=".ts,.tsx"
call .\node_modules\.bin\slnodejs scan --tokenfile \path\to\sltoken.txt --buildsessionidfile buildSessionId --workspacepath ".\src" --scm git |
In order to ignore specific files or folders during the Scan operation, please refer to Using Node.js Agent - Ignoring Files or Folders
See 'Node.js Command Reference - Scanning a build' for full parameter details
Running a ts-node backend application
To capture code coverage on your ts-node backend server, you need to run it using our Node.js test listener agent. For that purpose, you need to “wrap” the execution command of your application with our agent.
Please notice that SeaLights agent has been only tested and found compatible with node -r ts-node/register <your_tsnode_backend_server_command>
commands format.
Unix | ./node_modules/.bin/slnodejs run --tokenfile /path/to/sltoken.txt --buildsessionidfile buildSessionId [--labid <Lab ID>] --workspacepath <application_root_folder> --useinitialcolor true --useslnode2 -- -r ts-node/register <your_tsnode_backend_server_command> |
Windows |
In the sample command above, if your startup command is ts-node "./server/app.ts"
or node -r ts-node/register "./server/app.ts"
:
<your_tsnode_backend_server_command>
refers to"./server/app.ts"
.workspacepath
refers to the root folder of the project"./server"