node-test-helper is a legacy testing utility suite designed to simplify Mocha test setup by providing globally available assertions, mocking utilities, and test structure variables. Currently at version 1.0.0, the package's development appears to be abandoned, with no significant code updates in the past few years, despite a recent npm publish. Its approach relies heavily on CommonJS `require()` to inject global variables and functions (like `describe`, `it`, `expect`, `stub`, `TEST_NAME`) into the test environment, diverging significantly from modern modular JavaScript testing practices. It also presumes a `make`-based workflow for test execution rather than `npm scripts`, limiting its direct applicability in contemporary Node.js projects. Key differentiators (at the time of its creation) included simplifying boilerplate by abstracting away direct `require` calls for Mocha, Chai, and Sinon in individual test files, and offering an `init` command to scaffold a basic test directory structure and Makefile.
npm install node-test-helperVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to set up and run a basic test file using `node-test-helper`'s global variable injection and a `make` command, including an asynchronous test example.
Ensure your test files are in a CommonJS context and use `require("node-test-helper");` at the top of each test file where globals are needed.While this is the intended usage, for new projects, consider using a modern testing framework and assertion library (e.g., Jest, Vitest, or Mocha/Chai with explicit imports) that avoids global pollution.
Adapt your project to use `make test`, or manually configure `npm scripts` to invoke the underlying `mocha` command with appropriate options, ensuring `node-test-helper` is required globally or via `--require` flags.
Always install `mocha`, `chai`, `sinon`, and `sinon-chai` as dev dependencies: `npm install --save-dev mocha chai sinon sinon-chai`.
Ensure `require("node-test-helper");` is at the very top of your test file, or in a bootstrap file loaded before your tests.Run `node-test-helper init` to generate the default `Makefile` and test directory structure, or ensure you are executing `make test` from the directory containing your `Makefile`.
Install the package locally: `npm install node-test-helper --save-dev`.
Install Chai as a development dependency: `npm install chai --save-dev`.