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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@metagptx/vite-plugin-testid-checker

v0.0.1-alpha.3

Published

A Vite plugin for testid checker

Downloads

5

Readme

@metagptx/vite-plugin-testid-checker

npm version

A Vite plugin that checks for required attributes (like data-testid) on interactive elements in Vue and React/JSX files during the build process.

Features

  • 🔍 Automatic Detection: Identifies interactive elements that need test IDs
  • 🚀 Framework Support: Works with Vue and React/JSX/TSX files
  • Fast: Built-in caching mechanism for optimal performance
  • 🛠️ Configurable: Customize which attributes to check and which files to include/exclude
  • 🎯 Build-time Validation: Catches missing test IDs before they reach production

Installation

npm install @metagptx/vite-plugin-testid-checker --save-dev

or

pnpm add @metagptx/vite-plugin-testid-checker -D

or

yarn add @metagptx/vite-plugin-testid-checker --dev

Usage

Add the plugin to your vite.config.ts:

import { defineConfig } from 'vite'
import { vitePluginTestIdChecker } from '@metagptx/vite-plugin-testid-checker'

export default defineConfig({
  plugins: [
    vitePluginTestIdChecker({
      // Optional configuration
      attributes: ['data-testid'],
      include: ['src/**/*.{vue,jsx,tsx,js,ts}'],
      exclude: ['src/**/*.test.{js,ts,jsx,tsx}']
    })
  ]
})

Configuration

The plugin accepts the following options:

| Option | Type | Default | Description | |--------|------|---------|-------------| | attributes | string[] | ['data-testid'] | Array of attribute names to check for | | include | string \| string[] | ['src/**/*.{vue,jsx,tsx,js,ts}'] | Files to include (glob patterns) | | exclude | string \| string[] | [] | Files to exclude (glob patterns) |

What Elements Are Checked

The plugin checks for required attributes on the following interactive elements:

HTML Elements

  • <a> - Links
  • <button> - Buttons
  • <input> - Input fields
  • <textarea> - Text areas
  • <select> - Select dropdowns
  • <option> - Select options

React/JSX Elements

Elements with event handlers (e.g., onClick, onChange, onSubmit, etc.)

Vue Elements

Elements with the following Vue directives:

  • @click
  • @change
  • @input
  • @focus
  • @blur
  • @mouseover
  • @mouseout
  • @mouseenter
  • @mouseleave
  • @mousemove
  • @mouseup
  • @mousedown
  • @mousewheel
  • @keydown
  • @keyup
  • @keypress

Examples

Vue Example

This will cause a build error:

<template>
  <button @click="handleClick">Click me</button>
</template>

This will pass:

<template>
  <button @click="handleClick" data-testid="click-button">Click me</button>
</template>

React/JSX Example

This will cause a build error:

function MyComponent() {
  return (
    <button onClick={handleClick}>Click me</button>
  );
}

This will pass:

function MyComponent() {
  return (
    <button onClick={handleClick} data-testid="click-button">Click me</button>
  );
}

Custom Attributes

You can configure the plugin to check for custom attributes:

vitePluginTestIdChecker({
  attributes: ['data-testid', 'data-cy', 'data-test']
})

Now the plugin will check for any of these attributes:

// Any of these will pass:
<button onClick={handleClick} data-testid="button">Click</button>
<button onClick={handleClick} data-cy="button">Click</button>
<button onClick={handleClick} data-test="button">Click</button>

Error Messages

When the plugin detects missing attributes, it will show descriptive error messages:

data-testid is required for button in src/components/Button.vue:15:8
data-testid is required for input in src/components/Form.tsx:22:12

Build Integration

The plugin runs during the build process and will:

  1. ✅ Pass silently if all interactive elements have required attributes
  2. ❌ Throw an error and stop the build if any required attributes are missing

Performance

The plugin includes built-in caching to ensure optimal performance:

  • Files are cached based on their content hash
  • Only changed files are re-processed
  • Minimal impact on build times

Requirements

  • Node.js >= 14.0.0
  • Vite ^3.0.0 || ^4.0.0 || ^5.0.0