npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@availentdev/suitemocks

v0.1.5

Published

Mocks for suitescript entry point scriptContext

Downloads

55

Readme

README

What is this repository for?

  • This contains mocks of SuiteScript entry points for use with jest testing.
  • Version 0.1.5

How do I get set up?

  • You can install by running npm install @availentdev/suitemocks --save-dev
  • Before using this package
    • Follow instructions for setting up your SuiteScript project for testing here
    • Additional information can be found here
    • Test examples can be found here
  • Once installed and your project is configured for testing
    • Copy and paste the following over the contents of jest.config.js
    • This adds the array of custom stubs, which allows custom stubs to mimic the import style of stubs provided by @oracle/suitecloud-unit-testing
      • Ex. import afterSubmitContext from 'N/ScriptContext/afterSubmitContext';
      • Rather than ./path/to/file/afterSubmitContext
    • The transformIgnorePatterns property is modified to include this package so that @babel can transform them properly alongside the stubs provided by @oracle/suitecloud-unit-testing
const SuiteCloudJestConfiguration = require('@oracle/suitecloud-unit-testing/jest-configuration/SuiteCloudJestConfiguration');
const cliConfig = require('./suitecloud.config');

const TESTING_FRAMEWORK_PATH = '@oracle/suitecloud-unit-testing';
const CORE_STUBS_PATH = `${TESTING_FRAMEWORK_PATH}/stubs`;
const nodeModulesToTransform = [CORE_STUBS_PATH].join('|');

const build = SuiteCloudJestConfiguration.build({
  projectFolder: cliConfig.defaultProjectFolder,
  projectType: SuiteCloudJestConfiguration.ProjectType.ACP,
  customStubs: [
    {
      module: 'N/ScriptContext/beforeLoadContext',
      path: '<rootDir>/node_modules/@availentdev/suitemocks/customStubs/UserEvent/beforeLoadContext.js',
    },
    {
      module: 'N/ScriptContext/beforeSubmitContext',
      path: '<rootDir>/node_modules/@availentdev/suitemocks/customStubs/UserEvent/beforeSubmitContext.js',
    },
    {
      module: 'N/ScriptContext/afterSubmitContext',
      path: '<rootDir>/node_modules/@availentdev/suitemocks/customStubs/UserEvent/afterSubmitContext.js',
    },
    {
      module: 'N/ScriptContext/inputContext',
      path: '<rootDir>/node_modules/@availentdev/suitemocks/customStubs/MapReduce/inputContext.js',
    },
    {
      module: 'N/ScriptContext/mapContext',
      path: '<rootDir>/node_modules/@availentdev/suitemocks/customStubs/MapReduce/mapContext.js',
    },
    {
      module: 'N/ScriptContext/reduceContext',
      path: '<rootDir>/node_modules/@availentdev/suitemocks/customStubs/MapReduce/reduceContext.js',
    },
    {
      module: 'N/ScriptContext/summaryContext',
      path: '<rootDir>/node_modules/@availentdev/suitemocks/customStubs/MapReduce/summaryContext.js',
    },
    {
      module: 'N/ScriptContext/pageInitContext',
      path: '<rootDir>/node_modules/@availentdev/suitemocks/customStubs/ClientScript/pageInitContext.js',
    },
    {
      module: 'N/ScriptContext/saveRecordContext',
      path: '<rootDir>/node_modules/@availentdev/suitemocks/customStubs/ClientScript/saveRecordContext.js',
    },
    {
      module: 'N/ScriptContext/fieldChangedContext',
      path: '<rootDir>/node_modules/@availentdev/suitemocks/customStubs/ClientScript/fieldChangedContext.js',
    },
    {
      module: 'N/ScriptContext/sublistChangedContext',
      path: '<rootDir>/node_modules/@availentdev/suitemocks/customStubs/ClientScript/sublistChangedContext.js',
    },
    {
      module: 'N/ScriptContext/postSourcingContext',
      path: '<rootDir>/node_modules/@availentdev/suitemocks/customStubs/ClientScript/postSourcingContext.js',
    },
    {
      module: 'N/ScriptContext/lineInitContext',
      path: '<rootDir>/node_modules/@availentdev/suitemocks/customStubs/ClientScript/lineInitContext.js',
    },
    {
      module: 'N/ScriptContext/validateFieldContext',
      path: '<rootDir>/node_modules/@availentdev/suitemocks/customStubs/ClientScript/validateFieldContext.js',
    },
    {
      module: 'N/ScriptContext/validateLineContext',
      path: '<rootDir>/node_modules/@availentdev/suitemocks/customStubs/ClientScript/validateLineContext.js',
    },
    {
      module: 'N/ScriptContext/validateInsertContext',
      path: '<rootDir>/node_modules/@availentdev/suitemocks/customStubs/ClientScript/validateInsertContext.js',
    },
    {
      module: 'N/ScriptContext/validateDeleteContext',
      path: '<rootDir>/node_modules/@availentdev/suitemocks/customStubs/ClientScript/validateDeleteContext.js',
    },
    {
      module: 'N/ScriptContext/eachParamsContext',
      path: '<rootDir>/node_modules/@availentdev/suitemocks/customStubs/MassUpdate/eachParamsContext.js',
    },
    {
      module: 'N/ScriptContext/executeContext',
      path: '<rootDir>/node_modules/@availentdev/suitemocks/customStubs/ScheduledScript/executeContext.js',
    },
    {
      module: 'N/ScriptContext/onRequestContext',
      path: '<rootDir>/node_modules/@availentdev/suitemocks/customStubs/Suitelet/onRequestContext.js',
    },
  ],
});

build.transformIgnorePatterns = [`/node_modules/(?!(${nodeModulesToTransform}|@availentdev/suitemocks)/)`];

module.exports = build;
  • Each scriptContext mock contains the properties normally found in the scriptContext for that entry point
    • Properties representing SuiteScript module objects are included with each of their methods as a jest function
    • Properties of primitive data types default to undefined
    • Enums are included
    • Example for User Event afterSubmit:
    {
     oldRecord = recordObj,
     newRecord = recordObj,
     type = undefined,
     UserEventType = {
       COPY: 'copy',
       CREATE: 'create',
       VIEW: 'view',
       EDIT: 'edit',
       XEDIT: 'xedit',
       DELETE: 'delete',
       DROPSHIP: 'dropship',
       SPECIALORDER: 'specialorder',
       ORDERITEMS: 'orderitems',
       CANCEL: 'cancel',
       APPROVE: 'approve',
       REJECT: 'reject',
       RETRACT: 'retract',
       SAVESUBMIT: 'savesubmit',
       PACK: 'pack',
       SHIP: 'ship',
       EDITFORECAST: 'editforecast',
       REASSIGN: 'reassign',
       MARKCOMPLETE: 'markcomplete',
       PRINT: 'print',
       EMAIL: 'email',
       CHANGEPASSWORD: 'changepassword',
       TRANSFORM: 'transform',
       PAYBILLS: 'paybills',
       QUICKVIEW: 'quickview',
     }
    }
    • oldRecord and newRecord in this example represent record.record objects
      • Each method is a jest function
        • Immediately available in tests expect(afterSubmitScriptContextMock.getValue).toHaveBeenCalled();

        • However, any mock returns or implementations need to be set up in the test file

Contribution guidelines

To create new script contexts, copy an existing context file that most closely matches the one you need. Then, using NetSuite's documentation, add, remove, or modify the properties.

Entry points not yet included:

  • Bundle Installation Script:

    • afterInstall(params)
    • afterUpdate(params)
    • beforeInstall(params)
    • beforeUninstall(params)
    • beforeUpdate(params)
  • Client Script:

    • localizationContextEnter(scriptContext)
    • localizationContextExit(scriptContext)
  • Portlet:

    • render(params) (needs Portlet object added)
  • RESTlet:

    • get
    • delete
    • put
    • post
  • Workflow Action:

    • onAction(scriptContext)
  • SDF Installation:

    • run(scriptContext)

Who do I talk to?

  • Repo owner or admin
  • Other community or team contact