From 247356b77b0cdf0e9b456ef535fd35a5947be8d6 Mon Sep 17 00:00:00 2001 From: Yahatix Date: Fri, 15 Sep 2023 21:22:45 +0200 Subject: [PATCH] feat: Vite Plugin to remove data-testids unless testing --- vite.config.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/vite.config.ts b/vite.config.ts index 725b07f..3e0e227 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -16,6 +16,17 @@ if (process.env.NODE_ENV?.toLowerCase() === 'test') { nycrcPath: './.nycrc.json', }) ); +} else { + plugins.push({ + name: 'remove-testids', + enforce: 'pre', + transform(code, id) { + if (id.endsWith('.svelte')) { + return code.replace(/data-testid=".*?"/g, ''); + } + return code; + }, + }); } const config: UserConfig = {