import { RetryConfig } from 'ts-retry-promise'; import { AsyncOptionalCreatable } from '@salesforce/kit'; import { Optional } from '@salesforce/ts-types'; import { AuthFields } from '@salesforce/core'; import { TestProject, TestProjectOptions } from './testProject'; import { DevhubAuthStrategy } from './hubAuth'; export type ScratchOrgConfig = { /** * @deprecated 'sf' will be default */ executable?: 'sfdx' | 'sf'; config?: string; duration?: number; alias?: string; setDefault?: boolean; edition?: 'developer' | 'enterprise' | 'group' | 'professional' | 'partner-developer' | 'partner-enterprise' | 'partner-group' | 'partner-professional'; username?: string; wait?: number; /** true by default. Has no effect unless you set it to false */ tracksSource?: boolean; }; export type TestSessionOptions = { /** * Specify a different location for the test session. */ sessionDir?: string; /** * Define a test project to use for tests. */ project?: TestProjectOptions; /** * Scratch orgs to create as part of setup. All must be created successfully or session * create will throw. Scratch orgs created as part of setup will be deleted as part of * `TestSession.clean()`. */ scratchOrgs?: ScratchOrgConfig[]; /** * The preferred auth method to use */ devhubAuthStrategy?: DevhubAuthStrategy; /** * The number of times to retry the scratch org create after the initial attempt if it fails. Will be overridden by TESTKIT_SETUP_RETRIES environment variable. */ retries?: number; }; export declare const rmOptions: { recursive: boolean; force: boolean; }; /** * Represents a test session, which is a unique location for non-unit test (nut) * artifacts such as a project and a mocked home dir. It also provides easy * access to an org username created by a setup command, cwd stubbing, and a way to * zip up the test session. * * Create a TestSession instance with: `const testSession = TestSession.create(options)` * * Fine-grained control over certain test session details are provided by these * environment variables: * TESTKIT_SESSION_DIR = Overrides the default directory for the test session * TESTKIT_HOMEDIR = path to a home directory that the tests will use as a stub of os.homedir * TESTKIT_ORG_USERNAME = an org username to use for test commands. tests will use this org rather than creating new orgs. * TESTKIT_PROJECT_DIR = a SFDX project to use for testing. the tests will use this project directly. * TESTKIT_SAVE_ARTIFACTS = prevents a test session from deleting orgs, projects, and test sessions. * TESTKIT_ENABLE_ZIP = allows zipping the session dir when this is true * TESTKIT_SETUP_RETRIES = number of times to retry the org creates after the initial attempt before throwing an error * TESTKIT_SETUP_RETRIES_TIMEOUT = milliseconds to wait before the next retry of scratch org creations. Defaults to 5000 * TESTKIT_EXEC_SHELL = the shell to use for all testkit shell executions rather than the shelljs default. * * TESTKIT_HUB_USERNAME = username of an existing hub (authenticated before creating a session) * TESTKIT_JWT_CLIENT_ID = clientId of connected app for auth:jwt:grant * TESTKIT_JWT_KEY = JWT key (not a filepath, the actual contents of the key) * TESTKIT_HUB_INSTANCE = instance url for the hub. Defaults to https://login.salesforce.com * TESTKIT_AUTH_URL = auth url to be used with auth:sfdxurl:store */ export declare class TestSession extends AsyncOptionalCreatable { id: string; createdDate: Date; dir: string; homeDir: string; project: T['project'] extends TestSessionOptions['project'] ? TestProject : TestProject | undefined; rmRetryConfig: Partial>; orgs: Map; hubOrg: AuthFields; private debug; private cwdStub?; private overriddenDir?; private sandbox; private retries; private zipDir; private options; private shelljsExecOptions; private orgsAliases; constructor(options?: T); /** * Get an existing test session created with the same options, * or create a new session if a match is not found. This allows * sharing of test sessions between multiple test files. * * TODO: this needs to be implemented so that it works with * parallel testing. We need to read a testSessionOptions.json * file and compare options, then return that session. * * public static get(options: TestSessionOptions = {}): TestSession { * return sessions.get(options) ?? new TestSession(options); * } */ /** * Stub process.cwd() to return the provided directory path. * * @param dir The directory path to set as the current working directory */ stubCwd(dir: string): void; /** * Clean the test session by restoring the sandbox, deleting any setup * org created during the test, and deleting the test session dir. */ clean(): Promise; /** * Zip the contents of a test session directory if the TESTKIT_ENABLE_ZIP * env var is set. * * @name The name of the zip file to create. Default is the test session dirname with .zip extension. * @destDir The zip file will be written to this path. Default is `this.dir/..`. * @returns The created zip file path. */ zip(name?: string, destDir?: string): Promise>; protected init(): Promise; private deleteOrgs; private rmSessionDir; private createOrgs; private sleep; }