Skip to main content

Import

import {
  createConnection,
  connectionValue,
  defaultConnectionValueEnvironmentVariable,
} from "@prismatic-io/spectral/dist/testing";

createConnection

Signature

export const createConnection = <T extends ConnectionDefinition>(
  { key }: T,
  values: Record<string, unknown>,
  tokenValues?: Record<string, unknown>,
  displayName?: string,
): ConnectionValue
Constructs a ConnectionValue inline — no environment variable required. Use this when you want to hard-code test credentials directly in a test file.

Parameters

definition
ConnectionDefinition
required
The connection definition object. Only the key property is read to populate ConnectionValue.key.
values
Record<string, unknown>
required
Field values for the connection. Keys should match the input keys declared on the connection definition.
{ username: "alice", password: "secret" }
tokenValues
Record<string, unknown>
Optional OAuth 2.0 token fields. Set access_token here for OAuth connections.
{ access_token: "ya29.abc", refresh_token: "1//xyz", expires_in: 3600 }
displayName
string
Optional display name used as configVarKey. Defaults to an empty string.

Return value

ConnectionValue
object
required
A ConnectionValue object ready to pass as an input to invoke, harness.action, etc.

connectionValue

Signature

export const connectionValue = (
  envVarKey = defaultConnectionValueEnvironmentVariable,
): ConnectionValue
Reads a ConnectionValue from an environment variable. The environment variable must contain a JSON-serialized object. Throws an Error if the variable is not set.

Parameters

envVarKey
string
default:"PRISMATIC_CONNECTION_VALUE"
The name of the environment variable to read. Defaults to PRISMATIC_CONNECTION_VALUE.

Return value

ConnectionValue
object
required
A ConnectionValue parsed from the environment variable, with key set to an empty string.

defaultConnectionValueEnvironmentVariable

export const defaultConnectionValueEnvironmentVariable = "PRISMATIC_CONNECTION_VALUE";
The name of the environment variable that connectionValue() and ComponentTestHarness.connectionValue() read by default.

Examples

import { connection } from "@prismatic-io/spectral";
import { createConnection, invoke } from "@prismatic-io/spectral/dist/testing";

const apiKeyConnection = connection({
  key: "apiKeyConnection",
  display: { label: "API Key", description: "" },
  inputs: {
    apiKey: { label: "API Key", type: "string", required: true },
  },
});

const testConn = createConnection(apiKeyConnection, {
  apiKey: "test-key-abc123",
});

const { result } = await invoke(myAction, { connection: testConn });
Never commit real credentials to source control. Use environment variables or a secrets manager when testing with live credentials. For CI environments, inject the PRISMATIC_CONNECTION_VALUE variable from your secrets store.
  • invoke — pass a ConnectionValue as an action input
  • createHarnessharness.connectionValue() reads the same env var
  • invokeFlow — pass connection values in configVars

Build docs developers (and LLMs) love