Skip to main content

SDK: Testing

The @the-shift/sdk/testing entrypoint provides helpers for Stage session setup and delegated browser authentication.

Imports

import {
authenticatedPage,
createAgentBootstrap,
createTestSession,
} from "@the-shift/sdk/testing";

Create a Stage Test Session

const session = await createTestSession({
clientOptions: {
gatewayUrl: "https://app.the-shift.dev",
token: process.env.SHIFT_AGENT_TOKEN,
},
name: "drive-hasher-e2e",
googleScopes: ["https://www.googleapis.com/auth/drive.readonly"],
files: [
{
path: "/app/App.tsx",
content: `export default function App() { return <div>Ready</div>; }`,
},
],
publish: {
name: "drive-hasher-e2e",
},
});

await session.render();

Create a Browser Bootstrap Artifact

const bootstrap = await createAgentBootstrap({
gatewayUrl: "https://app.the-shift.dev",
token: process.env.SHIFT_AGENT_TOKEN,
redirectPath: "/s/k77abc123def",
});

console.log(bootstrap.bootstrapUrl);

Open an Authenticated Playwright Page

const { page, goto } = await authenticatedPage({
browser,
gatewayUrl: "https://app.the-shift.dev",
token: process.env.SHIFT_AGENT_TOKEN,
redirectPath: "/s/k77abc123def",
});

await goto("/s/k77abc123def");

Notes

  • These helpers expect a delegated SHIFT_AGENT_TOKEN, not a long-lived user session token.
  • The browser flow uses a one-time bootstrap URL and dedicated delegated cookies.
  • Pair these helpers with shift-cli token create and shift-cli test bootstrap when a shell-driven setup is easier than a pure SDK flow.