SeaLights Node.js agent - Scanning and Instrumentation of a Front-End app
The SeaLights Node.js agent can be used to scan and test the Front-end code as well.
See 'Generating an Agent token' for instructions on how to generate a token prior to executing the commands.
See 'Using Node.js Agent - Generating a session ID' for instructions on how to generate a session ID
Prerequisites
In case your front-end Javascript application is minified and/or uglified as part of its build process, you’ll need to ensure the Source Map files (*.js.map) are available to the Sealights agent inside the application folder - next to the application’s JS files -, pointing to the right source folder and including column information (also known as column-mapping). This will allow the Sealights agent to retrieve the real names of your methods from your source code and not their “obfuscated” version. Please refer to the following page for more information: Javascript and Node.js Source Map Files.
Scanning and Instrumentation
First, the front-end code must be scanned and instrumented to provide the needed information to the SeaLights server.
Unix/Linux | npx slnodejs scan --tokenfile /path/to/sltoken.txt --buildsessionidfile buildSessionId [--labid <Lab ID>] --instrumentForBrowsers --workspacepath dist --outputpath sl_dist --scm git |
---|---|
Windows (CMD) | call npx slnodejs scan --tokenfile \path\to\sltoken.txt --buildsessionidfile buildSessionId [--labid <Lab ID>] --instrumentForBrowsers --workspacepath dist --outputpath sl_dist --scm git |
After a successful scan
command execution, you should expect:
A line in your console log showing a line similar to
NodeJS-Agent: Scanned X methods and Y branches in Z files.
A new entry in your Sealights' dashboard for the specific application’s version, and the coverage report to show the content of your application (source code)
A new folder in the project directory called
sl_dist
(or the name provided as a value to the--outputpath
parameter)
In case your command execution does not produce the expected results, you can use the dryRun
command to validate your configuration, see https://sealights.atlassian.net/l/cp/iBBCh8ct .
For React applications you should add the flag:
--babylonPlugins jsx
For "
JavaScript heap out of memory
" errors while running scan, see: NodeJS - JavaScript heap out of memoryIn order to ignore specific files or folders during the Scan operation, please refer to https://sealights.atlassian.net/l/c/n6GuFwok
This will generate a new folder ('sl_dist' in the command above) with the instrumented code: a few Sealights-specific API calls will be added to your JS file to report coverage dynamically as illustrated in the picture below.
The content of this Sealights' generated folder needs to be deployed instead of your original code - on the application server - for the client browser to work against during your testing stages, but not in your production environment.
For distributed Test Runner & Test Listener, we recommend using the Lab ID parameter in order to link between the two.
For Front-End instrumented code, this parameter needs to be passed already as part of the the build command.
If the lab ID is not provided, the session ID will be used as a Lab ID
Note that if Sealights inline scripts are being blocked by CSP (Content-Security-Policy) headers then our dashboard will need to be whitelisted.
See Content-Security-Policy (CSP) Header Quick Reference as a good resource to how to handle this
In some cases, its possible to add a meta tag to do this as well, see: Content-Security-Policy Meta http-equiv Example
See 'Node.js Command Reference - Scanning a build' for full parameter details
Front-end application as part of an Integration Build
If you are reporting a front-end application as part of an integration build, you'll need to add the -labid <string>
parameter to your command and ensure the value used is the same across all the components.
For more details, please refer to Reporting an Integration Build to Sealights
Running tests
Running the tests is done the same as when running Unit or function tests; just here between the start and end steps you run your Front-end tests - See Using Node.js Agent - Running Tests