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.
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/testingThe alien CLI must be installed. See Install the CLI.
deploy(options)
Deploys the app and resolves once it is ready.
| Option | Type | Description |
|---|---|---|
app | string | Path to the directory that contains alien.ts. |
config | string | Config 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". |
verbose | boolean | Print CLI output. Also enabled by VERBOSE=true. |
How each platform deploys:
local: runsalien devin 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. RequiresALIEN_API_KEYand cloud credentials for the target account.
Deployment
| Member | Description |
|---|---|
id, name, platform | Identify the deployment. |
url | Public 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. |
destroyed | true after destroy() completes. |
Errors from the package are TestingOperationFailedError and TestingUnsupportedPlatformError.
Environment variables
| Variable | Description |
|---|---|
ALIEN_API_KEY | API key for cloud deployments. |
ALIEN_API_URL | API base URL. Default https://api.alien.dev. |
ALIEN_CLI_PATH | Path to the alien binary. Default: alien on PATH. |
VERBOSE | Set to true to print CLI output. |
Next
- Testing: what to test locally and what to test in a real cloud
- Local development
- TypeScript SDK