npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@antiwork/shortest

v0.0.9

Published

AI-powered natural language end-to-end testing framework

Downloads

724

Readme

Shortest

AI-powered natural language end-to-end testing framework.

Features

  • Natural language test writing
  • AI-powered test execution using Claude computer use API
  • Built on Playwright
  • GitHub integration with 2FA support

Installation

npm install @antiwork/shortest
# or
pnpm add @antiwork/shortest
# or
yarn add @antiwork/shortest

Quick Start

  1. Determine your test entry and add your Anthropic API key in config file: shortest.config.ts
import type { ShortestConfig } from '@antiwork/shortest';

export default {
  headless: false,
  baseUrl: 'http://localhost:3000',
  testDir: 'app/__tests__',
  anthropicKey: process.env.ANTHROPIC_API_KEY
} satisfies ShortestConfig; 
  1. Write your test in the test directory: app/__tests__/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 })

Using callback functions

You can also use callback functions to add additoinal 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();
});

Lifecycle hooks

You can use lifecycle hooks to run code before and after the test.

import { shrotest } 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: "[email protected]" 
    },
  });
});

shortest.afterEach(async ({ page }) => {
  await page.close();
});

shortest.afterAll(async ({ page }) => {
  await clerk.signOut({ page });
});

Running Tests

shortest                    # Run all tests
shortest login.test.ts     # Run specific test
shortest --headless        # Run in headless mode using cli

If you installed shortest without -g flag, you can run tests as follows:

npx shortest    # for npm
pnpm shortest   # for pnpm
yarn shortest   # for yarn

GitHub 2FA Login Setup

Shortest currently supports login using Github 2FA. For GitHub authentication tests:

  1. Go to your repository settings
  2. Navigate to "Password and Authentication"
  3. Click on "Authenticator App"
  4. Select "Use your authenticator app"
  5. Click "Setup key" to obtain the OTP secret
  6. Add the OTP secret to your .env.local file or use the Shortest CLI to add it
  7. Enter the 2FA code displayed in your terminal into Github's Authenticator setup page to complete the process
shortest --github-code --secret=<OTP_SECRET>

Environment Setup

Required in .env.local:

ANTHROPIC_API_KEY=your_api_key
GITHUB_TOTP_SECRET=your_secret  # Only for GitHub auth tests

CI Setup

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.

Documentation

Visit GitHub for detailed docs

Prerequisites

  • React >=19.0.0 (if using with Next.js 14+ or Server Actions)
  • Next.js >=14.0.0 (if using Server Components/Actions)

⚠️ Known Issues

  • Using this package with React 18 in Next.js 14+ projects may cause type conflicts with Server Actions and useFormStatus
  • If you encounter type errors with form actions or React hooks, ensure you're using React 19