0.0.9 • Published 2 years ago
unplugin-clear-testid v0.0.9
unplugin-clear-testid
Simple unplugin which removes data-testid
& data-cy
from your code.
Install
yarn add -D unplugin-clear-testid
// 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.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.config.js
module.exports = {
/* ... */
plugins: [
require('unplugin-clear-testid/webpack')({
attrs: ['data-testid', 'data-cy'],
testing: process.env.NODE_ENV === 'testing'
})
]
}
// 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.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
}