Adobe Campaign JavaScript runs directly in production — there is no staging test of the logic, no validation before deployment. A bug in a workflow script reaches production immediately.
Use acc instance pull to extract your JavaScript codes as local .js files, then run jest to validate business logic before it reaches the instance.
Preparation
Requirements: acc installed and authenticated, Node.js installed. Refer to Getting started.
jest is the standard JavaScript test runner used across the industry. It runs your functions locally and reports which pass and which fail — before anything reaches Adobe Campaign.
Important: Adobe Campaign JavaScript files must follow modern ES5 standards to be testable with jest. Files using E4X syntax (inline XML literals or for each loops) cannot be parsed outside the AC runtime. Refer to Modern development best practices before proceeding.
What will be extracted: JavaScript codes (xtk:javascript) as .js files via acc instance pull.
Walkthrough
1. Pull your JavaScript codes
acc instance pull --metadata xtk:javascript
Files are extracted to Administration/Configuration/JavaScript codes/.
2. Install jest
From your project root:
npm install --save-dev jest
3. Mock Adobe Campaign globals
Adobe Campaign exposes globals like logInfo, sqlExec, and NLWS that do not exist outside the runtime. Jest will throw ReferenceError on first use. Add a setup file to mock them.
Create jest.setup.js in the project root:
global.logInfo = jest.fn();
global.logError = jest.fn();
global.logWarning = jest.fn();
global.sqlExec = jest.fn();
global.sqlGetDouble = jest.fn();
global.sqlGetString = jest.fn();
global.NLWS = {};
Reference it in package.json:
{
"jest": {
"setupFiles": ["./jest.setup.js"]
}
}
4. Write a test file
For a JavaScript code cus:myHelpers.js that contains:
function formatCampaignCode(prefix, id) {
if (!prefix || !id) return null;
return prefix.toUpperCase() + "_" + id;
}
Create cus:myHelpers.test.js alongside it:
const { formatCampaignCode } = require("./cus:myHelpers.js");
test("formats a campaign code correctly", () => {
expect(formatCampaignCode("spring", 42)).toBe("SPRING_42");
});
test("returns null when prefix is missing", () => {
expect(formatCampaignCode(null, 42)).toBeNull();
});
5. Run the tests
npx jest
Jest reports each test as passed or failed, with the exact line and value that caused a failure.
Validation & troubleshooting
SyntaxError: Unexpected token '<'
The file uses E4X syntax. Jest cannot parse it. Refer to Modern development best practices to remove E4X before testing.
ReferenceError: logInfo is not defined
The jest.setup.js file is missing or not referenced in package.json. Verify the setupFiles entry points to the correct path.
Cannot find module './cus:myHelpers.js'
The colon in the filename may cause issues on Windows. Rename the test file to match the extracted filename exactly, or configure jest to resolve the path with moduleNameMapper in package.json.
Going further
Run jest automatically after each acc instance pull in a CI/CD pipeline — any regression introduced in the instance is caught before the next deployment. Refer to Code coverage with jest.