rollup-plugin-power-assert

raw JSON →
0.2.0 verified Mon Apr 27 auth: no javascript

Rollup and Vite plugin for power-assert, providing descriptive assertion messages through the standard Node.js assert interface. Current stable version is 0.2.0. It transforms assertion expressions (e.g., assert(ary.indexOf(zero) === two)) into detailed, labeled output showing intermediate values. The library supports both Rollup and Vite/Vitest with minimal configuration, and is part of the power-assert monorepo. Key differentiators include zero API overhead and compatibility with Vitest's assert API.

error Cannot find module '@power-assert/runtime'
cause Missing peer dependency @power-assert/runtime
fix
npm install --save-dev @power-assert/runtime
error TypeError: (0 , _rollupPluginPowerAssert.powerAssert) is not a function
cause Using default import instead of named import
fix
Change to: import { powerAssert } from 'rollup-plugin-power-assert'
error AssertionError: assert(...) expression not transformed
cause The file is not included in the plugin's include pattern
fix
Ensure the file path matches the include glob pattern in the plugin options.
gotcha The plugin transforms assert() calls only; it does not transform other assertion libraries like chai or expect.
fix Use Node.js assert module or Vitest's assert API. For other libraries, consider alternative power-assert wrappers.
gotcha The plugin requires the @power-assert/runtime package as a peer dependency. Failing to install it can result in runtime errors.
fix Install the peer dependency: npm install --save-dev @power-assert/runtime
deprecated The plugin may be deprecated in future versions of power-assert monorepo; check for migration notes.
fix Monitor the repository for deprecation notices and plan migration to alternative assertion enhancement tools.
npm install rollup-plugin-power-assert
yarn add rollup-plugin-power-assert
pnpm add rollup-plugin-power-assert

Configure Vite/Vitest with the powerAssert plugin to enable descriptive assertion messages in test files.

import { defineConfig } from 'vite';
import { powerAssert } from 'rollup-plugin-power-assert';

const testPattern = 'examples/**/__tests__/**/*.test.mts';

export default defineConfig({
  plugins: [
    powerAssert({
      include: testPattern,
    }),
  ],
  test: {
    include: testPattern,
  },
});