Skip to content

Mat3uszkek/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
}

About

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

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • TypeScript 85.8%
  • HTML 9.8%
  • JavaScript 4.4%