Scanning Your Application
Scan your build with slnodejs scan: what to scan for each kind of code, source maps, monorepos, integration builds, excluding files, and source control data.
slnodejs scan reports the structure of a build (files, methods and branches) to SeaLights, so that coverage collected later can be attributed to the right code. Run it once per build, after your build produces its output and before the code runs in tests.
Prerequisites
These prerequisites apply to every page that follows (runtime coverage, tests).
slnodejsinstalled; see Installing the Node.js Agent.An agent token in a file (
sltoken.txt); see Configuration → Token.A build session ID from
config; see Generating a Session ID.For source control data: a Git checkout with history (in CI, a full clone, for example
fetch-depth: 0in GitHub Actions).
What to scan
Scan the files that actually run. Runtime coverage is matched to the scan by file path and by the position of each method in the file. If the files that run differ from the files you scanned, coverage cannot be matched.
Plain JavaScript (CommonJS) that runs as is
The source folder
--scanDir src (or . with a .slignore)
ES modules ("type": "module" or .mjs)
The source folder
add --es6Modules
TypeScript or Babel compiled to an output folder
The output folder, with source maps
--scanDir dist; see TypeScript and transpiled code
TypeScript run with ts-node or a TypeScript loader
The .ts source folder
SL_fileExtensions=.ts, --scanDir src
Front-end bundles (webpack, Vite, Rollup, esbuild, Angular CLI)
The bundle output folder, with source maps that include column information
--scanDir dist --es6Modules, usually with --instrumentForBrowsers; see Front-end builds
Scan a back-end build
To scan the project root, use --scanDir . and exclude node_modules, tests and build tooling in a .slignore file.
TypeScript and transpiled code
Compiled before it runs (tsc, Babel, SWC): scan the output folder, with source maps, so that SeaLights reports methods on your original .ts files.
Use the same --projectRoot (default: the working directory) for the scan and for the test listener that runs the code. If coverage stays at 0% while the agent sends data, a project root mismatch is the most likely cause; see Troubleshooting → Coverage is missing or low.
Run directly with ts-node (or another TypeScript loader): scan the .ts files.
SL_fileExtensions replaces the list of scanned extensions. Include every extension you need, for example SL_fileExtensions=.ts,.js.
Scan a front-end build
Front-end code is bundled and often minified, so SeaLights needs source maps with column information to map the bundles back to your source files. Line-only ("cheap") source maps are not enough.
Valid source maps:
are available at scan time, next to the bundles (inline or as
.mapfiles) in--scanDir;list in
sourcesthe files that are in your repository;use correct relative paths to those source files.
To check them, open the application in the browser developer tools: the original sources must be listed and readable. Without column information, the SeaLights dashboard shows the warning Detected source-maps without column information. Source maps information might be incorrect and may result in inaccurate coverage. dryRun reports the same problem as Column information.
Then scan and instrument in one step. This writes an instrumented copy to --outputPath, which you deploy to the test environment instead of the original:
--excludeSourceMapFiles skipCopykeeps the source maps out ofsl_dist, so they are not deployed.skipAndDeletealso deletes them fromdist.If you instrument later or once per environment with the
instrumentcommand, scan with--useRelativeSlMapping(and without--instrumentForBrowsers).Lab ID, Collector, token exposure and the other instrumentation options are described in Frontend Instrumentation (static).
Monorepo and multi-module builds
To report several directories as one build, scan each one into the same build session with its own --moduleName, then report the end of the build once with completeScan.
Without
--moduleName, a build session can be scanned only once; a second scan fails.Module names are case-sensitive and must stay the same between builds.
Add
--useModulePrefixwhen two modules contain files with the same relative path.
For server-side rendering frameworks, see Next.js (Multi-Module Scan).
Integration builds
An integration build is made of the builds of other applications (for example the microservices of a release). It has no code of its own: pass the components instead of --scanDir.
To change the components later, use componentUpdate and componentDelete. See Integration Build.
Exclude files
Exclude tests, vendor bundles, generated code and build tooling, so that coverage percentages reflect the code your team maintains. Use a .slignore file (.gitignore syntax) in the scanned directory or one of its parents:
.slignore.instrument and .slignore.generated, and a known issue with --excludeFiles, are described in Configuration → Ignore files.
Source control data
With --scmType git, the scan reports commits and contributors from the local Git repository. Without it, no source control data is sent.
The checkout has no origin remote, or its URL is not browsable
--repositoryUrl https://github.com/my-org/my-app
Bitbucket or GitLab
--scmProvider Bitbucket or --scmProvider Gitlab
On-premises SCM server
--scmVersion <server version>
The scan does not run in a Git checkout
--commit <sha> and leave out --scmType
Check the scan before CI
Run dryRun locally to see which files are scanned and how source maps resolve, without reporting a build:
Report the end of the build
After all scans of the build session, report that the build is complete:
Use --failed instead of --ok when the build failed.
Key flags
--scanDir
Always (except integration builds). The folder of the code that runs.
--scmType git
Whenever the scan runs in a Git checkout.
--es6Modules
ES module code and most front-end bundles.
--babylonPlugins jsx / decorators-legacy
Scanning JSX or decorator syntax that is not transpiled.
--projectRoot
When the scan runs from another directory than the test listener.
--instrumentForBrowsers --outputPath
Web applications.
--useRelativeSlMapping
When you instrument later with the instrument command.
--moduleName
Several scans in one build session.
--rawCoverage
Lightweight V8 coverage mode.
--awsConfigure
AWS Lambda functions.
--failOnError true
When a failed scan must fail the pipeline.
Every flag is in the Command Reference → scan.
Troubleshooting
The scan reports 0 files or files are missing
--scanDir points to the wrong folder, or files are excluded by .slignore or the NYC exclude patterns. Run dryRun and check included-files.json. See also JS: Files Missing from Build Scan.
Module already exists
The build session was already scanned. Create a new build session with a unique --buildName, or give each scan its own --moduleName.
Front-end methods are reported on bundle files or with wrong names
Source maps are missing or line-only. Generate full source maps, keep them next to the bundles during the scan.
Parse errors
The code uses syntax the parser does not expect: add --es6Modules, or --babylonPlugins jsx / decorators-legacy.
JavaScript heap out of memory
Exclude vendor and generated files; see NodeJS - JavaScript heap out of memory.
The command fails but the pipeline passes
By default slnodejs exits with 0. Add --failOnError true.
More in Troubleshooting.
Next step
Make the application report coverage: Capturing Runtime Coverage. For unit tests only, go to Capturing Tests.
Last updated
Was this helpful?

