Skip to content
This repository has been archived by the owner on Jan 5, 2023. It is now read-only.

Simple unplugin which removes data-testid & data-cy from your code.

License

Notifications You must be signed in to change notification settings

grixu/unplugin-clear-testid

Repository files navigation

unplugin-clear-testid

NPM version

Simple unplugin which removes data-testid & data-cy from your code.

Install

yarn add -D unplugin-clear-testid
Vite
// vite.config.ts
import ClearTestid from 'unplugin-clear-testid/vite'

export default defineConfig({
  plugins: [
    ClearTestid({
      attrs: ['data-testid', 'data-cy'],
      testing: process.env.NODE_ENV === 'testing'
    }),
  ],
})

Example: playground/


Rollup
// rollup.config.js
import Starter from 'unplugin-clear-testid/rollup'

export default {
  plugins: [
    Starter({
      attrs: ['data-testid', 'data-cy'],
      testing: process.env.NODE_ENV === 'testing'
    }),
  ],
}


Webpack
// webpack.config.js
module.exports = {
  /* ... */
  plugins: [
    require('unplugin-clear-testid/webpack')({
      attrs: ['data-testid', 'data-cy'],
      testing: process.env.NODE_ENV === 'testing'
    })
  ]
}


Nuxt
// nuxt.config.js
export default {
  buildModules: [
    ['unplugin-clear-testid/nuxt', {
      attrs: ['data-testid', 'data-cy'],
      testing: process.env.NODE_ENV === 'testing'
    }],
  ],
}

This module works for both Nuxt 2 and Nuxt Vite


Vue CLI
// vue.config.js
module.exports = {
  configureWebpack: {
    plugins: [
      require('unplugin-clear-testid/webpack')({
        attrs: ['data-testid', 'data-cy'],
        testing: process.env.NODE_ENV === 'testing'
      }),
    ],
  },
}


Options

There are only two options which allows you to customize data attributes you want to remove and boolean flag to determine it is testing environment or not. Below there are default values:

{
  attrs: ['data-testid', 'data-cy'],
  testing: false
}