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

acto

v0.0.5

Published

connector for browser based tests

Downloads

327

Readme

Installation

npm i acto

Acto is a connector to enable easily creating component tests within a variety of e2e test runners. The two main parts are the app connector and test connector.

App Connectors

You'll need to use the connectApp function from acto/connect-app when bootstrapping your app (instead of, for example
createRoot(document.getElementById('root')!).render(...) in React or mount(App) in Svelte etc). This function takes a property that allows the test code to be imported dynamically (which will not have any impact on the app bundle). You'll probably use importGlob if you're using vite as your bundler, but other flavors are supported as well. You may need to change the glob pattern to match your test files.

// src/main.tsx
import { connectApp } from 'acto/connect-app';

connectApp({
  // When using vite:
  importGlob: import.meta.glob('./**/*.test.{j,t}s{,x}'),

  // When using webpack:
  webpackContext: import.meta.webpackContext('.', {
    recursive: true,
    regExp: /\.test$/,
    mode: 'lazy',
  }),

  // When using a bundler that doesn't handle globbing:
  imports: {
    './App.test.tsx': () => import('./App.test.tsx'),
    './OtherComponent.test.tsx': () => import('./OtherComponent.test.tsx'),
  },

  // These values are the same regardless of the bundler you're using
  render: async (elem) => {
    const root = createRoot(document.getElementById('root')!);
    root.render(elem);
  },
  defaultElement: <App />,
});

Test Connectors

The test connectors are available for:

  • @playwright/test: import { connectPlaywright } from 'acto/connect-playwright'
  • Cypress: import { connectCypress } from 'acto/connect-cypress'
  • Node Test Runner: import { connectNodeTest } from 'acto/connect-node-test'
    • Take a look at the examples to see how connectNodeTest is wired up for puppeteer or playwright.
// tests/playwright.spec.tsx
import React from 'react';
import { connectPlaywright } from 'acto/connect-playwright';

const { test, expect } = connectPlaywright({
  bootstrappedAt: import.meta.resolve('../src/main.tsx'),
});

test('app test', async ({ render }) => {
  const { page } = await render();
  await expect(page.getByText('Vite + React')).toBeVisible();
});

test('component test', async ({ render }) => {
  const { page } = await render(<div>Custom</div>);
  await expect(page.getByText('Custom')).toBeVisible();
});
// cypress/e2e/spec.cy.tsx
import React from 'react';
import { connectCypress } from 'acto/connect-cypress';

const { render, describe, it, cy } = connectCypress({
  bootstrappedAt: '../../src/main.tsx',
});

describe('my tests', () => {
  it('tests app', () => {
    render();

    cy.contains('Vite + React').should('be.visible');
  });

  it('tests components', async ({ render }) => {
    const { page } = await render(<div>Custom</div>);
    await expect(page.getByText('Custom')).toBeVisible();
  });
});