/
Using Node.js Agents - Scanning and running a ts-node project

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 variable SL_fileExtensions

  • scan the application files with the workspacepath parameter pointing to the source files directory (.ts)

Unix

export SL_fileExtensions=".ts,.tsx" npx slnodejs scan --tokenfile /path/to/sltoken.txt --buildsessionidfile buildSessionId --workspacepath "./src" --scm git

Windows

set SL_fileExtensions=".ts,.tsx" call npx 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

npx 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

call npx 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>

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"

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 identifier (stored in the buildSessionId file) will be used as the Lab ID value by default.

 

Related content