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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@mailsac/cypress

v0.1.0

Published

Reliable Mailsac email testing for Cypress: wait for matching messages, verify links and extract one-time codes.

Readme

Mailsac for Cypress

Wait for the right email, follow a password-reset link, or extract a one-time code in Cypress. The API key stays in Cypress's Node process. Tests receive the matching message, its text, and its links.

Create a Mailsac account · Mailsac API documentation · Runnable password-reset example

Install

Requires Cypress 16 and a Node.js version supported by Cypress (22, 24, or 26+).

npm install --save-dev @mailsac/cypress

Set MAILSAC_API_KEY in your shell or CI secret store. Do not use a CYPRESS_ prefix, put the key in Cypress.env() / config.env, or commit it.

Register the tasks in cypress.config.js:

const { defineConfig } = require('cypress');
const { createMailsacTasks } = require('@mailsac/cypress/node');

module.exports = defineConfig({
  e2e: {
    setupNodeEvents(on, config) {
      on('task', createMailsacTasks()); // Reads process.env.MAILSAC_API_KEY in Node.
      return config;
    },
  },
});

In cypress/support/e2e.js (or .ts):

import '@mailsac/cypress/commands';

Test a password reset

Replace the inbox, origin, subject, and selectors with your application's values. Use a test inbox you control and an API key authorized to read its bodies. Reset links are sensitive: use a private inbox or owned domain, and avoid recording live tokens in screenshots, videos, or logs.

import { extractLink } from '@mailsac/cypress';

it('resets a password', () => {
  const email = '[email protected]';
  const origin = 'http://localhost:3000';

  cy.visit(`${origin}/forgot-password`);
  cy.get('[name=email]').type(email);

  cy.then(() => {
    // Capture immediately before triggering the email, not before a long setup.
    const receivedAfter = new Date().toISOString();
    cy.get('button[type=submit]').click();
    return cy.mailsacWaitForMessage({
      email,
      receivedAfter,
      subject: 'Reset your password',
      timeoutMs: 60_000,
    });
  }).then((message) => {
    const resetLink = extractLink(message, { origin, pathname: '/reset-password' });
    cy.visit(resetLink, { log: false });
    cy.get('[name=password]').type('A-new-test-password-123!', { log: false });
    cy.get('button[type=submit]').click();
    cy.contains('Password updated').should('be.visible');
  });
});

For a complete runnable app, including successful sign-in and rejection of a reused reset link, see the password-reset example. Its default mode is fully local: no account, credentials, or email sending. A separate opt-in SMTP mode tests real delivery to Mailsac.

One-time codes

import { extractCode } from '@mailsac/cypress';

cy.mailsacWaitForMessage({
  email: '[email protected]',
  receivedAfter,
  subject: 'Your verification code',
}).then((message) => {
  const code = extractCode(message); // One distinct standalone six-digit code.
  cy.get('[name=code]').type(code, { log: false });
});

For other formats, use extractCode(message, { pattern: 'Code: ([A-Z0-9]{8})', group: 1 }). Supported flags are i, m, s, and u. Helpers fail if no match or more than one distinct match is found; they never guess between different links or codes.

API

cy.mailsacWaitForMessage(options)

| Option | Meaning | | --- | --- | | email | Required recipient inbox. | | receivedAfter | Required ISO timestamp with timezone. Only messages received at or after this time qualify. | | subject | Exact, case-sensitive subject. | | subjectIncludes | Case-sensitive subject substring. | | from | Sender email address, compared case-insensitively. | | timeoutMs | Total time including HTTP requests and retries; default 30,000 ms, maximum 120,000 ms. | | pollIntervalMs | Poll interval; default 1,000 ms, minimum 250 ms, maximum 10,000 ms. |

At least one of subject, subjectIncludes, or from is required. All supplied filters must match. The newest matching message among the latest 100 messages is selected; its full metadata and text are then fetched. This is intended for dedicated test inboxes, not a high-volume shared catch-all. Use a distinct inbox or a unique subject per parallel test. Keep the test runner's clock synchronized with the mail service.

Returns { _id, subject, received, to, from, links, text }. Recipients use { address, name? }. The task does not delete mail, change inbox settings, or send email. Polling and body/metadata reads consume Mailsac API operations, so choose an appropriate interval for your plan and concurrency.

createMailsacTasks(options?) — Node only

The /node entry point accepts apiKey (default process.env.MAILSAC_API_KEY), baseUrl (default https://mailsac.com/api), and default timeoutMs / pollIntervalMs. Direct cy.task('mailsac:waitForMessage', criteria, { log: false, timeout: 130000 }) callers can use those defaults. The convenience command uses its own 30-second timeout unless given timeoutMs explicitly.

HTTPS is required except for loopback fixtures. API redirects are disabled so a redirect cannot forward the key. HTTP 401/403 errors fail immediately; 429 and 5xx responses retry within the total deadline, respecting Retry-After. Other request failures fail promptly. Errors omit credentials and response bodies. Message contents themselves are returned to your test: avoid logging them when using sensitive fixtures.

extractLink(message, { origin, pathname? })

Returns one distinct HTTP(S) URL with the exact origin and, optionally, exact pathname. It rejects missing or ambiguous results and URLs containing credentials. Restrict the pathname to exclude same-origin help pages and other unrelated links to your app.

extractCode(message, options?)

Returns one distinct code from the message text. Default pattern: \\b\\d{6}\\b. Optional pattern, flags, and capture group (default zero) select another format. Patterns are test-author configuration, not untrusted user input.

Development

npm ci
npm test
npm run test:e2e
npm pack --dry-run

Unit tests cover matching, stale mail, timeouts, authorization failures, retries, path encoding, and safe error handling. Cypress drives the complete local example in CI on Node 22 and 24. Default tests never call production or send real email. The package uses the published @mailsac/api SDK; it adds no telemetry. The account and documentation links above carry campaign tags so Mailsac can measure visits from this integration.

License

MIT. Maintained by Mailsac / Habitat AI Incorporated. Report an issue.