
Security News
Deno 2.6 + Socket: Supply Chain Defense In Your CLI
Deno 2.6 introduces deno audit with a new --socket flag that plugs directly into Socket to bring supply chain security checks into the Deno CLI.
@oracle/suitecloud-unit-testing
Advanced tools
Suitecloud Unit Testing allows you to use unit testing with Jest for your SuiteCloud projects.
For more information about the available SuitScript 2.x modules, see SuiteScript 2.x Modules.
For more information about all the mockable stubs, see the CORE_STUBS list in SuiteCloudJestConfiguration.js.
If you use SuiteCloud CLI for Node.js, you can install SuiteCloud Unit Testing when running the project:create command by following the questions prompted. This way, your project is initialized with SuiteCloud Unit Testing, and all the dependencies are being taken care of.
β SuiteCloud Unit Testing is installed as a
devDependency.
However, if you want to configure SuiteCloud Unit Testing manually, do the following:
src folder.src folder.npm init.π‘ A
package.jsonfile is created in your SuiteCloud project folder.
package.json file, add the following code:
{
"scripts": {
"test": "jest"
}
}
npm install --save-dev @oracle/suitecloud-unit-testing jest
__tests__ folder, inside of the root of your SuiteCloud project folder.sample-test.js file, inside of the __tests__ folder, with the following content:
describe('Basic jest test with simple assert', () => {
it('should assert stings are equal', () => {
const a = 'foobar';
const b = 'foobar';
expect(a).toMatch(b);
});
});
npm test
to run your test. You should see an output similar to the following:
PASS __tests__/sample-test.js
Basic jest test with simple assert
β should assert stings are equal (2ms)
You successfully ran your first test for a SuiteCloud project!
To properly run your tests against the SuiteScript 2.x files of your SuiteCloud project, create a jest.config.js file inside of the root of your SuiteCloud project folder.
The jest.config.js file must follow a specific structure. Depending on your SuiteCloud project type, check one of the following examples:
const SuiteCloudJestConfiguration = require("@oracle/suitecloud-unit-testing/jest-configuration/SuiteCloudJestConfiguration");
module.exports = SuiteCloudJestConfiguration.build({
projectFolder: 'src', //or your SuiteCloud project folder
projectType: SuiteCloudJestConfiguration.ProjectType.ACP,
});
const SuiteCloudJestConfiguration = require("@oracle/suitecloud-unit-testing/jest-configuration/SuiteCloudJestConfiguration");
module.exports = SuiteCloudJestConfiguration.build({
projectFolder: 'src', //or your SuiteCloud project folder
projectType: SuiteCloudJestConfiguration.ProjectType.SUITEAPP,
});
Here you can find two examples on how to use SuiteCloud Unit Testing with a SuiteCloud project.
The first example covers testing for the N/record module, which is fully mocked in SuiteCloud Unit Testing. Whereas the second example covers the testing of a module that is not mocked in SuiteCloud Unit Testing, by using a custom stub.
π‘ You can manually mock any module that is still not supported in SuiteCloud Unit Testing.
This example follows the structure presented below:
myAccountCustomizationProject
βββ __tests__
β βββ sample-test.js
βββ node_modules
βββ src
β βββ AccountConfiguration
β βββ FileCabinet
β βββ SuiteScripts
β βββ Suitelet.js
β βββ Objects
β βββ Translations
β βββ deploy.xml
β βββ manifest.xml
βββ jest.config.js
βββ suitecloud.config.js
βββ package-lock.json
βββ package.json
βββ project.json
See below the content of the SuiteCloud Unit Testing files:
jest.config.js fileconst SuiteCloudJestConfiguration = require("@oracle/suitecloud-unit-testing/jest-configuration/SuiteCloudJestConfiguration");
module.exports = SuiteCloudJestConfiguration.build({
projectFolder: 'src',
projectType: SuiteCloudJestConfiguration.ProjectType.ACP,
});
Suitelet.js file/**
* @NApiVersion 2.x
* @NScriptType Suitelet
* @NModuleScope SameAccount
*/
define(["N/record"], function(record) {
return {
onRequest: function(context) {
if (context.request.method === 'GET') {
const salesOrderId = context.request.parameters.salesOrderId;
let salesOrderRecord = record.load({id: salesOrderId});
salesOrderRecord.setValue({fieldId: 'memo', value: "foobar"});
salesOrderRecord.save({enableSourcing: false});
}
}
};
});
Suitelet.test.js fileimport Suitelet from "SuiteScripts/Suitelet";
import record from "N/record";
import Record from "N/record/instance";
jest.mock("N/record");
jest.mock("N/record/instance");
beforeEach(() => {
jest.clearAllMocks();
});
describe("Suitelet Test", () => {
it("Sales Order memo field has been updated", () => {
// given
const context = {
request: {
method: 'GET',
parameters: {
salesOrderId: 1352
}
}
};
record.load.mockReturnValue(Record);
Record.save.mockReturnValue(1352);
// when
Suitelet.onRequest(context);
// then
expect(record.load).toHaveBeenCalledWith({id: 1352});
expect(Record.setValue).toHaveBeenCalledWith({fieldId: 'memo', value: 'foobar'});
expect(Record.save).toHaveBeenCalledWith({enableSourcing: false});
});
});
This example follows the structure presented below:
myAccountCustomizationProject
βββ customStubs
β βββ http.js
βββ __tests__
β βββ http.test.js
βββ node_modules
βββ src
β βββ AccountConfiguration
β βββ FileCabinet
β βββ SuiteScripts
β βββ Templates
β βββ Web Site Hosting Files
β βββ Objects
β βββ Translations
β βββ deploy.xml
β βββ manifest.xml
βββ jest.config.js
βββ suitecloud.config.js
βββ package-lock.json
βββ package.json
βββ project.json
See below the content of the SuiteCloud Unit Testing files:
jest.config.js fileconst SuiteCloudJestConfiguration = require("@oracle/suitecloud-unit-testing/jest-configuration/SuiteCloudJestConfiguration");
module.exports = SuiteCloudJestConfiguration.build({
projectFolder: 'src',
projectType: SuiteCloudJestConfiguration.ProjectType.ACP,
customStubs: [
{
module: "N/http",
path: "<rootDir>/customStubs/http.js"
}
]
});
http.js file: This is the stub file. It partially mocks NetSuite's N/http module.π‘ The JSDoc annotations are copied from NetSuite's N/http module, but are not required to run SuiteCloud Unit Testing.
define([], function() {
/**
* @namespace http
*/
var http = function() {};
/**
* Send a HTTP GET request and return a reponse from a server.
*
* @governance 10 units
* @restriction Server SuiteScript only
*
* @param {Object} options
* @param {string} options.url the HTTP URL being requested
* @param {Object} options.headers (optional) The HTTP headers
* @return {ClientResponse}
*
* @throws {SuiteScriptError} SSS_MISSING_REQD_ARGUMENT if a required argument is missing
* @throws {SuiteScriptError} SSS_INVALID_URL if an incorrect protocol is used (ex: http in the HTTPS module)
*
* @since 2015.2
*/
http.prototype.get = function(options) {};
/**
* @exports N/http
* @namespace http
*/
return new http();
});
http.test.js fileimport http from 'N/http';
jest.mock('N/http');
beforeEach(() => {
jest.clearAllMocks();
});
describe('Sample test with user defined http module stub', () => {
it('should call http get method', () => {
// given
const clientResponseMock = {
code: 200,
body: {
data: 'foobar'
}
// more properties and functions here if needed
};
http.get.mockReturnValue(clientResponseMock);
const options = {
url: 'https://netsuite.com'
};
// when
const clientResponse = http.get(options);
// then
expect(http.get).toHaveBeenCalledWith(options);
expect(clientResponse).toMatchObject({
code: 200,
body: {
data: 'foobar'
}
});
});
});
Suitecloud Unit Testing is an open source project. Pull requests are currently not being accepted. See Contributing for details.
Copyright (c) 2023, 2024, 2025 Oracle and/or its affiliates The Universal Permissive License (UPL), Version 1.0.
FAQs
Unknown package
The npm package @oracle/suitecloud-unit-testing receives a total of 3,814 weekly downloads. As such, @oracle/suitecloud-unit-testing popularity was classified as popular.
We found that @oracle/suitecloud-unit-testing demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago.Β It has 6 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Deno 2.6 introduces deno audit with a new --socket flag that plugs directly into Socket to bring supply chain security checks into the Deno CLI.

Security News
New DoS and source code exposure bugs in React Server Components and Next.js: whatβs affected and how to update safely.

Security News
Socket CEO Feross Aboukhadijeh joins Software Engineering Daily to discuss modern software supply chain attacks and rising AI-driven security risks.