Registry / testing / postcss-tape

postcss-tape

JSON →
library6.0.1jsnpmunverified

PostCSS Tape is a development utility designed to streamline the testing of PostCSS plugins. Currently at stable version 6.0.1, this package offers a focused approach to testing by abstracting the boilerplate often associated with PostCSS processing. It allows developers to define test cases efficiently through configuration files like `.tape.js`, `.mjs`, or `.cjs`, supporting both CommonJS and ES Modules for test definitions. Key differentiators include its automatic test generation for empty cases, comprehensive options for testing plugin behavior (including PostCSS plugin options, process options, warning counts, and error matching), and a simple CLI-first interface. The package typically updates in response to major PostCSS releases, ensuring compatibility with the latest versions. It provides a structured yet flexible framework for ensuring the correctness and stability of PostCSS transformations.

npm install postcss-tape
INSTALL
IMPORT
SIG · POSTCSS-TAPE
P
postcss-tape
testingjavascriptv6.0.1
Install
—
Import
—
Disk
—
Pass rate
0/ 6
Env Coverage0 / 6
glibc
18–22
musl
18–22
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 18–226 runs
build_error
glibc
node 18–226 runs
build_error
Code
Verified usage

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

Configuration object (ESM)
✓ export default { 'my-test': { message: '...' } }; // In .tape.mjs or .tape.js with type: 'module'
✗ module.exports = { 'my-test': { message: '...' } }; // In .mjs file
Test configurations are defined by exporting a default object from a dedicated configuration file (.tape.js, .tape.mjs, etc.). Use ESM `export default` for `.mjs` files or `.js` files when `type: 'module'` is set in `package.json`.
Configuration object (CJS)
✓ module.exports = { 'my-test': { message: '...' } }; // In .tape.cjs or .tape.js without type: 'module'
✗ export default { 'my-test': { message: '...' } }; // In .cjs file
Test configurations can also be defined using CommonJS `module.exports` for `.cjs` files or `.js` files when `type: 'module'` is not explicitly set in `package.json`.
postcss-tape CLI runner
✓ npm test // if 'postcss-tape' is in package.json scripts
✗ import postcssTape from 'postcss-tape'; // or require('postcss-tape')
The `postcss-tape` package is primarily a command-line interface (CLI) tool. It is not designed for direct programmatic import as a JavaScript module. The recommended way to use it is via `package.json` scripts or by directly executing the `postcss-tape` command.

Demonstrates installation, configuration via .tape.js, and running tests for a PostCSS plugin using the CLI.

npm install --save-dev postcss-tape # Add to your package.json # { # "scripts": { # "test": "postcss-tape" # } # } # Create a file named .tape.js at the root of your project // .tape.js export default { 'basic-test': { message: 'supports basic plugin functionality', source: 'input.css', expect: 'output.expect.css', options: { /* plugin options */ } }, 'another-test:variant': { message: 'supports a variant of another test', source: 'input.css', expect: 'output-variant.expect.css', options: { /* different plugin options */ } } }; // Optional: Create input.css and output.expect.css in a 'fixtures' directory // Then run: npm test
tape --version
Debug
Known issues
breakingVersion 6.0.0 and above requires Node.js version 10 or greater. Older Node.js environments will result in errors.
fix
Upgrade your Node.js environment to version 10 or higher (e.g., using `nvm install 16 && nvm use 16`).
affects: >=6.0.0
breakingPostCSS Tape v6.0.0 introduced support for PostCSS 7 and 8 concurrently. Ensure your `postcss` peer dependency is within the `^7 || ^8` range. Older `postcss-tape` versions might have different PostCSS peer dependency requirements.
fix
Verify and update your `postcss` peer dependency in `package.json` to a compatible version (e.g., `"postcss": "^8.4.0"`).
affects: >=6.0.0
gotchaThe order of configuration file resolution changed in v6.0.0. Configuration files are now resolved in the order: `postcss-tape.config.js`, `postcss-tape.config.mjs`, `postcss-tape.config.cjs`, `.tape.js`, `.tape.mjs`, and `.tape.cjs`.
fix
If upgrading, verify that your test configuration file name and location align with the new resolution order. Consider renaming to `postcss-tape.config.js` for explicit recognition.
affects: >=6.0.0
gotchaWhen using `export default` in `.tape.js` (an ES Module syntax), ensure your Node.js project is configured for ESM (e.g., by adding `"type": "module"` to `package.json`) or use a `.mjs` extension. Otherwise, you might encounter `SyntaxError: Cannot use import statement outside a module`.
fix
Either rename your config file to `.tape.mjs`, or add `"type": "module"` to your `package.json`. Alternatively, use CommonJS syntax (`module.exports = { ... }`) and a `.cjs` extension or a `.js` file without `"type": "module"`.
affects: >=3.0.0
Errors
Common errors & fixes
Error: Cannot find module 'postcss'
The required `postcss` peer dependency is not installed in the project.
fix
Install PostCSS: `npm install postcss` or `yarn add postcss`.
SyntaxError: Cannot use import statement outside a module
An ES Module (`import`/`export`) syntax is used in a configuration file (`.tape.js`) that is being interpreted as a CommonJS module.
fix
Rename the configuration file to `.tape.mjs` or add `"type": "module"` to your project's `package.json`. Alternatively, switch to CommonJS `module.exports` syntax and use a `.cjs` extension or a `.js` file without `"type": "module"`.
Error: Test suite failed to run: No test configuration file found.
The `postcss-tape` runner could not locate a valid configuration file (e.g., `.tape.js`, `postcss-tape.config.js`) in the expected locations.
fix
Ensure a configuration file exists at the root of your project or specify its path using the `--config` option (e.g., `postcss-tape --config path/to/my-tests.js`). Double-check file name and extension.
Upgrade
Version history
6.0.1latest on npm
Audit
Dependencies
postcssrequiredRequired for processing CSS and running PostCSS plugins during tests.
Agent activity
4 hits · last 30 days
node
4
Resources
postcss-tape — npm install postcss-tape · libregistry