Instantiate a @salesforce/core test context.

Constructors

  • Parameters

    • options: {
          sandbox?: SinonSandbox;
          setup?: boolean;
          sinon?: SinonStatic;
      } = {}
      • Optionalsandbox?: SinonSandbox
      • Optionalsetup?: boolean
      • Optionalsinon?: SinonStatic

    Returns TestContext

Properties

configStubs: {
    AuthInfoConfig?: ConfigStub;
    Config?: ConfigStub;
    OrgUsersConfig?: ConfigStub;
    SfProjectJson?: ConfigStub;
    [configName: string]: Optional<ConfigStub>;
} = {}

An object used in tests that interact with config files.

id: string = ...

id A unique id for the test run.

SANDBOX: SinonSandbox

The default sandbox is cleared out before each test run.

See [sinon sandbox]https://sinonjs.org/releases/v14/sandbox/.

SANDBOXES: SandboxTypes

An object of different sandboxes. Used when needing to restore parts of the system for customized testing.

stubs: Record<string, SinonStub<any[], any>> = {}

A record of stubs created during instantiation.

TEST_LOGGER: Logger

The test logger that is used when Logger.child is used anywhere. It uses memory logging.

Methods

  • Used to mock http request to Salesforce.

    Parameters

    • request: AnyJson

      An HttpRequest.

    • Optionaloptions: AnyJson

      Additional options.

      See Connection.request

    Returns Promise<AnyJson>

  • A function used when resolving the global path. Calls globalPathResolverSync by default.

    Parameters

    • uid: string

      Unique id.

    Returns Promise<string>

  • A function used when resolving the global path.

    Parameters

    • uid: string

      Unique id.

    Returns string

  • Set stubs for working in the context of a SfProject

    Parameters

    • inProject: boolean = true

    Returns void

  • A function used when resolving the local path. Calls localPathResolverSync by default.

    Parameters

    • uid: string

      Unique id.

    Returns Promise<string>

  • A function used when resolving the local path.

    Parameters

    • uid: string

      Unique id.

    Returns string

  • A function used for resolving paths. Calls localPathRetriever and globalPathRetriever.

    Parameters

    • isGlobal: boolean

      true if the config is global.

    • Optionaluid: string

      user id.

    Returns Promise<string>

  • A function used for resolving paths. Calls localPathRetrieverSync and globalPathRetrieverSync.

    Parameters

    • isGlobal: boolean

      true if the config is global.

    • Optionaluid: string

      user id.

    Returns string

  • Sets a config stub contents by name

    Parameters

    • name: string

      The name of the config stub.

    • value: ConfigContents

      The actual stub contents. The Mock data.

    Returns void

  • Add beforeEach and afterEach hooks to init the stubs and restore them. This is called automatically when the class is instantiated unless the setup option is set to false.

    Returns void

  • Stub the aliases in the global aliases config file.

    Parameters

    • aliases: Record<string, string>
    • group: string = aliasAccessorEntireFile.DEFAULT_GROUP

    Returns void

  • Stub contents in the config file.

    Parameters

    • config: Record<string, string>

    Returns Promise<void>

  • Stub salesforce user authorizations.

    Parameters

    • users: Record<string, MockTestOrgData[]>

      The users to stub. The key is the username of the admin user and it must be included in the users array in order to obtain the orgId key for the remaining users. The admin user is excluded from the users array.

    Returns void