AI-powered natural language end-to-end testing framework.
<video src="https://github.com/user-attachments/assets/d443279e-7364-452b-9f50-0c8dd0cf55fc" controls autoplay loop muted> Your browser does not support the video tag. </video>If helpful, here's a short video!
Use the shortest init
command to streamline the setup process in a new or existing project.
The shortest init
command will:
npx @antiwork/shortest init
This will:
@antiwork/shortest
package as a dev dependency if it is not already installedshortest.config.ts
file with boilerplate configuration.env.local
file (unless present) with placeholders for required environment variables, such as ANTHROPIC_API_KEY
.env.local
and .shortest/
to .gitignore
shortest.config.ts
import type { ShortestConfig } from "@antiwork/shortest";
export default {
headless: false,
baseUrl: "http://localhost:3000",
browser: {
contextOptions: {
ignoreHTTPSErrors: true
},
},
testPattern: "**/*.test.ts",
ai: {
provider: "anthropic",
},
} satisfies ShortestConfig;
The Anthropic API key defaults to SHORTEST_ANTHROPIC_API_KEY
/ ANTHROPIC_API_KEY
environment variables. Can be overwritten via ai.config.apiKey
.
Optionally, you can configure browser behavior using the browser.contextOptions
property in your configuration file. This allows you to pass custom Playwright browser context options.
app/login.test.ts
import { shortest } from "@antiwork/shortest";
shortest("Login to the app using email and password", {
username: process.env.GITHUB_USERNAME,
password: process.env.GITHUB_PASSWORD,
});
You can also use callback functions to add additional assertions and other logic. AI will execute the callback function after the test
execution in browser is completed.
import { shortest } from "@antiwork/shortest";
import { db } from "@/lib/db/drizzle";
import { users } from "@/lib/db/schema";
import { eq } from "drizzle-orm";
shortest("Login to the app using username and password", {
username: process.env.USERNAME,
password: process.env.PASSWORD,
}).after(async ({ page }) => {
// Get current user's clerk ID from the page
const clerkId = await page.evaluate(() => {
return window.localStorage.getItem("clerk-user");
});
if (!clerkId) {
throw new Error("User not found in database");
}
// Query the database
const [user] = await db
.select()
.from(users)
.where(eq(users.clerkId, clerkId))
.limit(1);
expect(user).toBeDefined();
});
You can use lifecycle hooks to run code before and after the test.
import { shortest } from "@antiwork/shortest";
shortest.beforeAll(async ({ page }) => {
await clerkSetup({
frontendApiUrl:
process.env.PLAYWRIGHT_TEST_BASE_URL ?? "http://localhost:3000",
});
});
shortest.beforeEach(async ({ page }) => {
await clerk.signIn({
page,
signInParams: {
strategy: "email_code",
identifier: "iffy+clerk_test@example.com",
},
});
});
shortest.afterEach(async ({ page }) => {
await page.close();
});
shortest.afterAll(async ({ page }) => {
await clerk.signOut({ page });
});
Shortest supports flexible test chaining patterns:
// Sequential test chain
shortest([
"user can login with email and password",
"user can modify their account-level refund policy",
]);
// Reusable test flows
const loginAsLawyer = "login as lawyer with valid credentials";
const loginAsContractor = "login as contractor with valid credentials";
const allAppActions = ["send invoice to company", "view invoices"];
// Combine flows with spread operator
shortest([loginAsLawyer, ...allAppActions]);
shortest([loginAsContractor, ...allAppActions]);
Test API endpoints using natural language
const req = new APIRequest({
baseURL: API_BASE_URI,
});
shortest(
"Ensure the response contains only active users",
req.fetch({
url: "/users",
method: "GET",
params: new URLSearchParams({
active: true,
}),
}),
);
Or simply:
shortest(`
Test the API GET endpoint ${API_BASE_URI}/users with query parameter { "active": true }
Expect the response to contain only active users
`);
pnpm shortest # Run all tests
pnpm shortest login.test.ts # Run specific tests from a file
pnpm shortest login.test.ts:23 # Run specific test from a file using a line number
pnpm shortest --headless # Run in headless mode using
You can find example tests in the examples
directory.
You can run Shortest in your CI/CD pipeline by running tests in headless mode. Make sure to add your Anthropic API key to your CI/CD pipeline secrets.
Shortest supports login using GitHub 2FA. For GitHub authentication tests:
.env.local
file or use the Shortest CLI to add itshortest --github-code --secret=<OTP_SECRET>
Required in .env.local
:
ANTHROPIC_API_KEY=your_api_key
GITHUB_TOTP_SECRET=your_secret # Only for GitHub auth tests
The NPM package is located in packages/shortest/
. See CONTRIBUTING guide.
This guide will help you set up the Shortest web app for local development.
[!WARNING]
Using this package with React 18 in Next.js 14+ projects may cause type conflicts with Server Actions anduseFormStatus
If you encounter type errors with form actions or React hooks, ensure you're using React 19
git clone https://github.com/antiwork/shortest.git
cd shortest
npm install -g pnpm
pnpm install
Pull Vercel env vars:
pnpm i -g vercel
vercel link
vercel env pull
pnpm run setup
to configure the environment variables.pnpm drizzle-kit generate
pnpm db:migrate
pnpm db:seed # creates stripe products, currently unused
You'll need to set up the following services for local development. If you're not an Antiwork Vercel team member, you'll need to either run the setup wizard pnpm run setup
or manually configure each of these services and add the corresponding environment variables to your .env.local
file:
.env.local
file.Create Database
button.Postgres
from the Browse Storage
menu.Quickstart
.env.local
tab.Developers
dashboard at stripe.com.Test mode
.API Keys
tab and copy your Secret key
.pnpm run stripe:webhooks
. It will prompt you to login with a code then give you your STRIPE_WEBHOOK_SECRET
.Developer settings
> OAuth Apps
> New OAuth App
.http://localhost:3000
for local developmentConfigure
> SSO Connections
> GitHub
.Use custom credentials
Client ID
and Client Secret
from the GitHub OAuth app you just created.repo
to the Scopes
MAILOSAUR_API_KEY
: Your API keyMAILOSAUR_SERVER_ID
: Your server IDThe email used to test the login flow will have the format shortest@<MAILOSAUR_SERVER_ID>.mailosaur.net
, whereMAILOSAUR_SERVER_ID
is your server ID.
Make sure to add the email as a new user under the Clerk app.
Run the development server:
pnpm dev
Open http://localhost:3000 in your browser to see the app in action.
antiwork/shortest
September 18, 2024
July 7, 2025
TypeScript