Registry / testing / strip-test-selectors

strip-test-selectors

JSON →
library0.1.0jsnpmunverified

A Babel plugin that strips data-test-* attributes from Ember.js templates and properties from JavaScript objects in production builds. Current stable version is 0.1.0, released as part of the ember-test-selectors monorepo. It is designed for Embroider+Vite apps (Ember 3.28+, Ember CLI 4.12+, Node.js 18+). Unlike the classic ember-test-selectors addon which works with classic Ember builds, this package provides granular Babel plugins for Vite-based setups, giving developers control over when stripping occurs via environment variables.

npm install strip-test-selectors
INSTALL
IMPORT
SIG · STRIP-TEST-SELECTO
S
strip-test-selectors
testingjavascriptv0.1.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

stripPropertiesPlugin
import { stripPropertiesPlugin } from 'strip-test-selectors'
const stripPropertiesPlugin = require('strip-test-selectors').stripPropertiesPlugin
ESM import is preferred but CommonJS require works if using CJS. The plugin strips data-test-* properties from JavaScript objects.
default (AST transform plugin)
import stripTestSelectors from 'strip-test-selectors'
import { stripTestSelectors } from 'strip-test-selectors'
The default export is the AST transform plugin for stripping data-test-* attributes from templates. Named import will fail.
types
import type { StripTestSelectorsPlugin } from 'strip-test-selectors'
import { StripTestSelectorsPlugin } from 'strip-test-selectors'
Type imports should use 'import type' to avoid runtime import. The library ships TypeScript declarations.

Configures Babel to strip data-test-* from templates and JS objects only when STRIP_TEST_SELECTORS environment variable is set, typically for production builds.

// babel.config.cjs const { stripPropertiesPlugin } = require('strip-test-selectors'); module.exports = { plugins: [ [ 'babel-plugin-ember-template-compilation', { compilerPath: 'ember-source/dist/ember-template-compiler.js', enableLegacyModules: ['@ember/template-compiler'], transforms: [ ...(process.env.STRIP_TEST_SELECTORS ? [require('strip-test-selectors').default] : []), ], }, ], ...(process.env.STRIP_TEST_SELECTORS ? [stripPropertiesPlugin] : []), ], };
Debug
Known issues
gotchaThis package only works with Embroider+Vite apps, not classic Ember builds. Classic builds must use ember-test-selectors addon.
fix
Use ember-test-selectors package for classic Ember apps, or migrate to Embroider+Vite.
affects: >=0.1.0
gotchaThe default export is the AST transform for templates, not a named export. Doing import { stripTestSelectors } will fail with 'undefined'.
fix
Use import stripTestSelectors from 'strip-test-selectors' for the template plugin.
affects: >=0.1.0
breakingRequires Node.js 18+ and Ember 3.28+. Older versions are not supported.
fix
Update Node.js to 18+ and Ember to 3.28+.
affects: >=0.1.0
gotchaYou are responsible for configuring when stripping occurs via environment variable; there is no automatic production detection.
fix
Set STRIP_TEST_SELECTORS=true in your production build script.
affects: >=0.1.0
gotchaThe plugin only strips attributes starting with 'data-test-'. Custom prefixes or suffixes are not supported.
fix
Use data-test-* prefix for all test selectors.
affects: >=0.1.0
Errors
Common errors & fixes
TypeError: Cannot destructure property 'stripPropertiesPlugin' of 'require(...)' as it is undefined.
Using old named import syntax for default export or incorrect package path.
fix
Use stripPropertiesPlugin as a named export: import { stripPropertiesPlugin } from 'strip-test-selectors'
Error: Cannot find module 'babel-plugin-ember-template-compilation'
Missing peer dependency babel-plugin-ember-template-compilation.
fix
Install it: npm install -D babel-plugin-ember-template-compilation
AssertionError [ERR_ASSERTION]: The plugin expected an object for 'transforms', got undefined.
babel-plugin-ember-template-compilation config missing transforms array.
fix
Provide transforms array in plugin options, e.g., transforms: [stripTestSelectors]
Upgrade
Version history
0.1.0latest on npm
Audit
Dependencies
babel-plugin-ember-template-compilationrequiredRequired to transform Ember templates and apply AST transforms for stripping data-test attributes.
Agent activity
6 hits · last 30 days
node
4
Resources
strip-test-selectors — npm install strip-test-selectors · libregistry