Registry / testing / test-ipfs-example

test-ipfs-example

JSON →
library1.3.3jsnpmunverified

This package, `test-ipfs-example`, provides a testing framework specifically designed for validating IPFS-related JavaScript examples. It offers distinct test harnesses for both Node.js and browser environments. For Node.js examples, it facilitates simple output matching, allowing developers to assert expected console or process outputs. For browser-based examples, it leverages Playwright, providing a robust end-to-end testing solution with full browser automation capabilities. The current stable version is `1.3.3`, with releases occurring at a moderate cadence, typically every few months, addressing bug fixes, dependency updates, and new features like Bun support. Key differentiators include its dual-environment testing capabilities and specialized focus on IPFS examples, providing an integrated setup for projects within that ecosystem. It ships with TypeScript types, promoting better developer experience and type safety.

npm install test-ipfs-example
INSTALL
IMPORT
SIG · TEST-IPFS-EXAMPLE
T
test-ipfs-example
testingjavascriptv1.3.3
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.

waitForOutput
import { waitForOutput } from 'test-ipfs-example/node'
const { waitForOutput } = require('test-ipfs-example/node')
The Node.js harness is ESM-first; CommonJS `require` is generally not supported for direct imports.
setup
import { setup, expect } from 'test-ipfs-example/browser'
const { setup } = require('test-ipfs-example/browser')
The browser harness also expects ESM imports. 'expect' is the Playwright assertion library re-exported.
test-node-example CLI
npx test-node-example ./my-test.spec.js
node ./my-test.spec.js
The package provides CLI binaries for running tests, specifically `test-node-example` and `test-browser-example`.

This quickstart demonstrates how to use `waitForOutput` from the Node.js test harness to assert the console output of a JavaScript file. It is run as a module, typically via the `test-node-example` CLI tool.

import { waitForOutput } from 'test-ipfs-example/node'; import { fileURLToPath } from 'url'; import path from 'path'; const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename); // Assuming 'my-example.js' is a simple Node.js script that prints 'Hello IPFS!' // Example content for 'my-example.js': console.log('Hello IPFS!'); async function runNodeTest() { console.log('Running Node.js example test...'); try { await waitForOutput('Hello IPFS!', path.join(__dirname, 'my-example.js')); console.log('Node.js test passed: Output matched expectations.'); } catch (error) { console.error('Node.js test failed:', error); process.exit(1); } } runNodeTest();
Debug
Known issues
breakingVersion 1.0.0 introduced breaking changes by exporting the Node and browser test harnesses directly, which might require adjusting import paths or usage patterns for consumers migrating from pre-1.0.0 versions.
fix
Review the README and API documentation for the correct import paths (e.g., `test-ipfs-example/node`, `test-ipfs-example/browser`) and updated API usage.
affects: >=1.0.0
gotchaWhen running browser tests, Playwright's browsers may fail to install, leading to test failures. While the library attempts to tolerate these failures, it will log errors which might indicate an environment issue.
fix
Ensure your environment meets Playwright's requirements for browser installation. You might need to manually install specific browsers using `npx playwright install` or check system dependencies. Refer to Playwright's documentation for troubleshooting browser installation issues.
affects: >=1.3.2
Errors
Common errors & fixes
Error: Cannot find module 'playwright' or 'playwright-chromium'
The Playwright package or its specific browser drivers are not installed in your project's `node_modules`.
fix
Install Playwright as a dependency: `npm install --save-dev playwright` or `npm install --save-dev playwright-chromium` if only chromium is needed. Ensure your testing environment has access to these packages.
ReferenceError: require is not defined in ES module scope
Attempting to use CommonJS `require()` syntax in a modern Node.js or browser environment where the `test-ipfs-example` package is designed for ES module (ESM) imports.
fix
Update your import statements to use ESM syntax: `import { symbol } from 'test-ipfs-example/path'` instead of `const { symbol } = require('test-ipfs-example/path')`. Ensure your project's `package.json` specifies `"type": "module"` if you are running in Node.js.
TypeError: test.describe is not a function
Incorrectly importing or initializing the browser test harness. The `setup` function needs to be called to configure Playwright and return the `test` object.
fix
Ensure you call `const test = setup({ /* ... config ... */ });` before trying to use `test.describe` or other Playwright test functions.
Upgrade
Version history
1.3.3latest on npm
Audit
Dependencies
playwrightrequiredRequired for the browser testing harness to function, as it uses Playwright for browser automation.
Agent activity
6 hits · last 30 days
node
6
Resources
test-ipfs-example — npm install test-ipfs-example · libregistry