@cap-js/cds-test
Test support for CAP Node.js, installed as a dev dependency: it starts the project's server for the test, hands the test an HTTP client bound to it, and carries the assertions.
The code that starts a CAP server for a test, points an HTTP client at it and carries the assertions used to ship inside @sap/cds@sap/cdsThe CAP Node.js runtime, which compiles the CDS model, serves the services declared in it, answers generic requests before any handler runs, and loads every cds-plugin.sap official, cap. It is this package now, added as a dev dependency and reached from a test file through cds.test(), which launches the project under test and returns helpers already bound to its URL and port. It covers the service boundary, so a handler and a query can be asserted in the same test without a deployed system. It picks no test runner: capire names Vitest, Jest, Mocha and Node's own runner, and a project keeps whichever it has. Driving a UI, and anything needing a real BTP binding, stays outside it.
Facts
Where it sits
Who is behind it
In the atlas: maintains 34@cap-jsmaintainerBob den OsContributes to this
In the atlas: contributes to 13@BobdenOsChristian GeorgiContributes to this
In the atlas: maintains 1, contributes to 53@chgeoChristian SchüringsContributes to this
In the atlas: contributes to 25@cschueringsDaniel HutzelContributes to this
In the atlas: contributes to 32, wrote 3@danjoaJohannes VogelContributes to this
In the atlas: contributes to 25@johannes-vogelMauricio LaufferContributes to this
In the atlas: maintains 16, contributes to 41, wrote 4@mauriciolaufferPatrice BenderContributes to this
In the atlas: contributes to 11@patricebenderPaulContributes to this
In the atlas: contributes to 12@PDT42sjvansContributes to this
In the atlas: contributes to 45@sjvansStefan RudiContributes to this
In the atlas: contributes to 13, wrote 5@stefanrudi10 contributors
What it declares
Every artifact
- Type
- Package
- Origin
- By SAP
- Runtime
- Node.js
As a package
- Declared for
- >=9.8
- Where it runs
- does not say
- Distributed through
- npm
Connections
Proving a service still does what it did, without a deployment
Download
Install
npm add @cap-js/cds-testDerived from the package name. No recipe recorded; the README has the configuration.
README
quoted from cap-js/cds-test under Apache-2.0, readTest Support for CAP Node.js
About this project
This is a library with test utilities for CAP Node.js applications, like
- Starting and stopping a CAP server before and after tests
- A bound HTTP client for the server
chai-like assertion helpers
Requirements and Setup
In your application project, just install the package as dev dependency:
npm add -D @cap-js/cds-test
Usage
Add a simple test file test/bookshop.test.js with this content:
const cds = require('@sap/cds')
const { GET, expect } = cds.test (__dirname+'/..')
describe('Sample tests', () => {
it('serves Books', async () => {
const { data } = await GET `/odata/v4/catalog/Books`
expect(data.value.length).to.be.greaterThanOrEqual(5)
})
})
Run it with Vitest, for example:
npx vitest
Or with Jest:
npx jest
node --test, and mocha runners are supported, too, though with less coverage in real-life projects.
Documentation
See the CAP documentation on cds.test for more.
Support, Feedback, Contributing
This project is open to feature requests/suggestions, bug reports etc. via GitHub issues. Contribution and feedback are encouraged and always welcome. For more information about how to contribute, the project structure, as well as additional contribution information, see our Contribution Guidelines.
Security / Disclosure
If you find any bug that may be a security problem, please follow our instructions at in our security policy on how to report it. Please do not create GitHub issues for security-related doubts or problems.
Code of Conduct
We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone. By participating in this project, you agree to abide by its Code of Conduct at all times.
Licensing
Copyright 2024-2026 SAP SE or an SAP affiliate company and cds-test contributors. Please see our LICENSE for copyright and license information. Detailed information including third-party components and their licensing/copyright information is available via the REUSE tool.
History
Fixes 3
Notes
Fixed
Bufferrequest bodies are no longer serialized viaJSON.stringify()- In
chest-powered tests,inspectPortconfiguration will be passed tonode:test.run(...)when debugging - In
chest-powered tests,concurrencyofnode:test.run(...)will be limitted to1to enable debugging
Fixes 1
Notes
Fixed
cds-testno longer fails to find test files if it encounters a symlinked directory.
Removed 1, Features 3, Changed 3, Fixes 2
Notes
Changed
-
Usage of
axioshas been removed in favor of the Fetch API, which is available in Node.js 18 and later. This change allows for a more modern and native approach to making HTTP requests, eliminating the need for an external dependency. For compatibility, if it's is installed explicitly, theaxioslibrary will used. -
When running in Jest, the
expectfromcds.testnow returns a built-in implementation which covers the most common matchers with the common chai API. In other runners, theexpectfromcds.testreturns thechai.expectimplementation as before. -
Assertion stack traces no longer contain frames of cds-test's own implementation.
Removed
- Dependencies to
axios-> install it yourself if you want to useaxios.
Added
- Support for the Vitest test runner.
- Property
cds.test.defaultsas a shortcut forcds.test.axios.defaults, which is deprecated now. - Property
cds.test.defaults.pathto set a common path prefix for subsequent requests.
Fixed
cds.testcan now be used in combination with ESM modules without issues.cds.testcan now be used in combination withchai6 andchai-as-promised8.
-
Fixes 2
Notes
Fixed
it.each()only uses the first entry of nested arrays- Non-axios variant returns response
statusfield also ascode.
Fixed
Features 2
Notes
Added
- Support for
err.causeinAxioserrors - Experimental support for
fetchinstead ofAxios
- Support for
Features 1, Changed 1, Fixes 1
Notes
Added
- add
toBeNullmatcher to Jest expectations
Changed
- Many changes to the experimental test runner.
Fixed
- Prevent jest and mocha from giving random timeout errors if
cds.test.data.resetis used.
- add
Others providing
Compare all 8 on the Testing page →- com.sap.cds:cds-services-bomcom.sap.cds:cds-services-bomThe Maven bill of materials for CAP Java, pinning every com.sap.cds module in a release, from the API and core runtime to the Spring Boot starters and the CQN engine, to the same version.sap official, capMaven bill of materials pinning CAP Java module versionsfrom CAP
- cds-cucumbercds-cucumberBehaviour-driven tests for CAP applications: Gherkin scenarios that drive a running service rather than assertions written against handlers.community org, capGherkin scenarios driving a running CAP servicefrom CAP
- sapbrunosapbrunoA terminal UI that runs Bruno collections against a CAP service, fetching an OAuth2 client_credentials token before each run so collections that fail with 401 under bru run work in CI.independent, capTerminal UI running Bruno collections against a CAP servicefrom CAP
- cds-launchpad-plugincds-launchpad-pluginIndexes every SAPUI5 application in a workspace into one sandbox launchpad served by the CDS server, so all of them can be opened from a single page while developing.independent, capSandbox launchpad for all SAPUI5 apps in a CAP workspacefrom CAP
- enforce-export-coverageenforce-export-coverageA static-analysis command line that checks every exported TypeScript function has a corresponding test, without running the test suite.independent, generalStatic check that each exported TypeScript function has a testfrom General
- @sap-ux/fe-mockserver-plugin-cds@sap-ux/fe-mockserver-plugin-cdsLets the Fiori Elements mock server take a CDS file as its metadata source, so a UI is developed against the real model before a service exists.sap official, capFiori Elements mock server plugin taking a CDS file as metadatafrom CAP
- @saptools/bruno@saptools/brunoA command line that runs Bruno collections against XSUAA-protected apps on Cloud Foundry, fetching the app's token and writing it into the selected environment file before each run.independent, btpRunner for Bruno collections against XSUAA-protected CF appsfrom BTP/BAIP
Details
Sources
Sources are graph entities: the same page may back several entries, and an unreachable source flags every row that rests on it.
Compatibility and provenance
Flavors
“Test Support for CAP Node.js” — cap-js/cds-test — repository
Contributors
History in the atlas
- First seen.
For your agent
- Ref
artifact:cap-js-cds-test- JSON
- /artifacts/cap-js-cds-test.json
- MCP
- Connecting an agent