Test and lint adapters
Test files
test/unit/adapterTestUnit.js — contains the adapter unit tests. Unit tests cover the foundational components of the adapter: existing code and configurations in the adapter’s files. They also test most error conditions (such as missing required fields) within adapter.js.
test/integration/adapterTestIntegration.js — contains the adapter integration tests. Integration tests can be run in standalone stub mode (using mock data) or against a live instance of the external system. The only error conditions tested in integration tests are missing mock data and errors returned from the external system.
utils/testRunner.js — a utility for running tests without saving credentials in the test scripts. See Use the test runner below.
package.json — contains the test scripts test:unit, test:integration, test:cover, and test. You can adjust the log level on the test scripts here to get more detailed output during testing.
Run tests
These scripts should not be modified except to change the log level. They are used by pre-commit hooks and CI/CD pipelines.
Use the test runner
The testRunner utility at utils/testRunner.js can run unit tests, standalone integration tests, and true integration tests without requiring credentials to be saved in the test scripts.
When running a true integration test, the runner prompts for credentials, edits the test script, runs the tests, and then restores the script.
The trade-off is that failing tests are harder to debug, because console output and logs are less readable when tests run through the test runner.
Edit test scripts to change log level
You can change the --LOG flag on the test scripts in package.json to control verbosity during testing.
error— logs only errors. Use this for clean baseline runs.debug— logs HTTP request options and the response received. Use this when investigating failures.trace— logs every step the adapter takes. This level is very verbose; use it only to isolate exactly where in the adapter a problem occurs.
Read debug logs during testing
When the adapter runs at debug level, it writes several log entries that are useful for diagnosing issues. These entries appear both when running standalone tests and when the adapter is integrated withItential Platform.
OPTIONS — all HTTP call options. Authentication information is intentionally omitted. This is often the most useful log for diagnosing request issues.
REQUEST — the payload being sent to the external system.
CALL RETURN — the raw response received from the external system.
RESPONSE — the parsed response (first element only, if an array).
Example:
Save mock data from integration tests
When you run a true integration test (stub = false) with isSaveMockData = true in adapterTestIntegration.js, the adapter makes live calls to the external system and automatically saves the responses as mock data files. It also updates the relevant action.json entries to reference the new files.
If schema translation is active and return_raw is not set to true, the saved mock data will be the translated response. You will need to manually reverse the translation to produce accurate raw mock data. Setting return_raw: true in the request properties causes saveMockData to use the pre-translation response instead, which avoids this problem.
See Work with mock data for more detail on the saveMockData method and mock data file formats.
Unit tests
Generic unit tests
The following tests are consistent across all adapters. Do not modify them — they are replaced automatically when the adapter is migrated to a newer foundation.
A marker comment in the file separates the generic section (replaced on migration) from the customizable section below it:
Specific unit tests
The Adapter Builder generates three tests for every API method in adapter.js. These tests can be customized to extend coverage.
Test 1 — method exists. Confirms the method is defined as a function on the adapter:
Test 2 — required parameter error. Confirms the adapter returns the correct error when a required parameter is missing. runErrorAsserts is a private helper that validates the error object structure:
Test 3 — schema validation failure. Confirms the adapter returns the correct error when data fails Ajv validation (for example, a missing required field or a value of the wrong type):
Adding tests or test data
Do not modify anything above the migration marker — those changes will be lost on the next migration. Below the marker, you can:
- Add additional
assertstatements to existing tests. - Add request data to existing tests.
- Add new tests for additional error conditions, using test doubles or additional mock data files.
- Add unit and integration tests for any methods you add manually to
adapter.js.
Integration tests
Generic integration tests
The following integration tests are consistent across all adapters. Do not modify them — they are replaced automatically when the adapter is migrated.
The same migration marker applies here as in the unit test file.
Specific integration tests
The Adapter Builder generates an integration test for every API method. These tests can be customized to extend coverage. Two private helpers are available: runCommonAsserts validates a successful response, and runErrorAsserts validates an error response.
Without mock data — when no mock data file exists for a call, the stub test expects an error. When running integrated, the test expects a successful response:
With mock data — when mock data is available, the stub test validates the response against the expected field values in the mock file:
Intelligent integration testing
Every adapter method has a generated integration test, but the generated tests apply only basic intelligence. Integration tests often need to run in a specific order — for example, creating a resource before retrieving, updating, or deleting it — and many tests depend on data from prior steps, or on the existence of related resources.
Adapters built with the Adapter Builder take these dependencies into account based on the information provided during the build. Where the builder can infer the correct test order and data dependencies, it does so automatically.