Docs

Testing package

@alienplatform/testing deploys your stack from inside a test and returns a handle to the running deployment. Use it for integration tests that exercise real bindings, commands, and HTTP endpoints, locally or in a cloud account.

tests/api.test.ts
import { type Deployment, deploy } from "@alienplatform/testing"
import { afterAll, beforeAll, describe, expect, it } from "vitest"

describe("api", () => {
  let deployment: Deployment

  beforeAll(async () => {
    deployment = await deploy({ app: ".", platform: "local" })
  }, 300_000)

  afterAll(async () => {
    await deployment?.destroy()
  })

  it("answers health checks", async () => {
    const response = await fetch(`${deployment.url}/health`)
    expect(response.ok).toBe(true)
  })

  it("runs the get-summary command", async () => {
    const input = { accountId: "acct_1" }
    const result = await deployment.invokeCommand<{ total: number }>("get-summary", input)
    expect(result.total).toBe(0)
  })
})

The package works with any test runner; the example uses Vitest. For test strategy, see Testing.

Install

npm install --save-dev @alienplatform/testing

The alien CLI must be installed. See Install the CLI.

deploy(options)

Deploys the app and resolves once it is ready.

OptionTypeDescription
appstringPath to the directory that contains alien.ts.
configstringConfig file to use instead of alien.ts.
platform"local" | "aws" | "gcp" | "azure"Where to deploy. Default "local".
environmentVariables{ name, value, type?, targetResources? }[]Variables to set on the deployment. type is "plain" or "secret".
verbosebooleanPrint CLI output. Also enabled by VERBOSE=true.

How each platform deploys:

  • local: runs alien dev in the background and waits for its status file to report ready. You need no cloud credentials.
  • aws, gcp, azure: builds the stack, creates a release and a deployment through the Alien API, and waits for it to run. Requires ALIEN_API_KEY and cloud credentials for the target account.

Deployment

MemberDescription
id, name, platformIdentify the deployment.
urlPublic URL of the app, or undefined when no resource exposes one.
invokeCommand<T>(name, params, { target? })Run a command and return its result. Pass target when more than one resource handles the same command name.
setExternalSecret(vault, key, value)Write a secret into the deployment's vault with the platform's own tools, as a customer would.
upgrade({ environmentVariables? })Create a new release and update the deployment. Cloud platforms only.
destroy()Stop alien dev, or delete the cloud deployment and wait for it to be removed.
destroyedtrue after destroy() completes.

Errors from the package are TestingOperationFailedError and TestingUnsupportedPlatformError.

Environment variables

VariableDescription
ALIEN_API_KEYAPI key for cloud deployments.
ALIEN_API_URLAPI base URL. Default https://api.alien.dev.
ALIEN_CLI_PATHPath to the alien binary. Default: alien on PATH.
VERBOSESet to true to print CLI output.

Next

On this page