{"id":15151,"library":"node-qunit","title":"QUnit Test Runner for Node.js","description":"node-qunit is a specialized test runner designed to integrate the QUnit testing framework with Node.js environments. Currently at version 2.0.2, this package was last published seven years ago and is now considered abandoned. It differentiates itself by running each test file in its own spawned Node.js process, enabling parallel execution for improved performance. It offers both a command-line interface (CLI) and a programmatic API for integrating with build systems. While providing test coverage via Istanbul, its core value proposition was maintaining API compatibility with the browser-based QUnit, allowing for consistent test writing across client and server environments. It aimed for a simplified API, particularly for asynchronous testing, and supported both TDD and BDD styles. Given its abandonment, users should exercise caution or consider more modern alternatives.","status":"abandoned","version":"2.0.2","language":"javascript","source_language":"en","source_url":"https://github.com/qunitjs/node-qunit","tags":["javascript","TDD","qunit","unit","testing","tests","async"],"install":[{"cmd":"npm install node-qunit","lang":"bash","label":"npm"},{"cmd":"yarn add node-qunit","lang":"bash","label":"yarn"},{"cmd":"pnpm add node-qunit","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"This package is CommonJS-only. Its last update was 7 years ago, pre-dating widespread Node.js ESM support.","wrong":"import { testrunner } from 'node-qunit';","symbol":"testrunner","correct":"const testrunner = require(\"node-qunit\");"},{"note":"`QUnit` is exposed as a global object within the test files executed by `node-qunit`. The `module` keyword is reserved in Node.js, so `QUnit.module` must be used instead.","wrong":"module('My tests', function() { /* ... */ });","symbol":"QUnit.module","correct":"QUnit.module('My tests', function() { /* ... */ });"},{"note":"`QUnit.test` is also exposed globally to test files, following the standard QUnit API for defining test cases.","symbol":"QUnit.test","correct":"QUnit.test('My test case', function(assert) { /* ... */ });"}],"quickstart":{"code":"const testrunner = require(\"node-qunit\");\nconst path = require(\"path\");\nconst fs = require(\"fs\");\n\n// Define a simple code file to be tested\nconst codeFilePath = path.join(__dirname, \"my-code.js\");\nfs.writeFileSync(codeFilePath, `\nmodule.exports = {\n  add: (a, b) => a + b,\n  subtract: (a, b) => a - b\n};\n`);\n\n// Define a simple test file using QUnit API\nconst testFilePath = path.join(__dirname, \"my-tests.js\");\nfs.writeFileSync(testFilePath, `\nQUnit.module('Calculator', function(hooks) {\n  hooks.beforeEach(function(assert) {\n    // Setup code if needed\n  });\n\n  QUnit.test('add function', function(assert) {\n    const calculator = require('./my-code.js'); // Relative path needed for child process\n    assert.equal(calculator.add(1, 2), 3, '1 + 2 should be 3');\n  });\n\n  QUnit.test('subtract function', function(assert) {\n    const calculator = require('./my-code.js');\n    assert.equal(calculator.subtract(5, 2), 3, '5 - 2 should be 3');\n  });\n});\n`);\n\n// Configure and run the tests\ntestrunner.run({\n    code: codeFilePath,\n    tests: testFilePath,\n    log: {\n        summary: true,\n        errors: true,\n        coverage: false // Assuming no istanbul setup for quickstart\n    }\n}, function(err, report) {\n    if (err) {\n        console.error(\"Test runner encountered an error:\", err);\n        process.exit(1);\n    }\n    console.log(\"Test Report:\", JSON.stringify(report, null, 2));\n    // Cleanup generated files\n    fs.unlinkSync(codeFilePath);\n    fs.unlinkSync(testFilePath);\n    process.exit(report.globalSummary.failed > 0 ? 1 : 0);\n});","lang":"javascript","description":"Demonstrates how to programmatically run QUnit tests in Node.js, including setting up a simple code file and its corresponding test file using the `node-qunit` test runner API. This example creates temporary files to illustrate the `code` and `tests` configuration."},"warnings":[{"fix":"Update `package.json` to `\"node-qunit\": \"^2.0.0\"` and run `npm install`.","message":"Prior to version 1.0.0, this package was published under the name `qunit`. Users upgrading from older versions must change their package dependency from `qunit` to `node-qunit`.","severity":"breaking","affected_versions":"<1.0.0"},{"fix":"Ensure you are installing `node-qunit` for the QUnit test runner, and not `qnit` (the old project). Review your `package.json` dependencies carefully.","message":"The `node-qunit` package name was previously used by a different, deprecated project that is now published under the name `qnit`. This can cause confusion if installing based on historical context.","severity":"breaking","affected_versions":"all versions"},{"fix":"Replace `module('My tests', ...)` with `QUnit.module('My tests', ...)` in your test files.","message":"When writing QUnit test files for `node-qunit`, the global `module` function is reserved by Node.js. You must use `QUnit.module()` instead to define test modules.","severity":"gotcha","affected_versions":"all versions"},{"fix":"Use `const testrunner = require(\"node-qunit\");` for importing the package.","message":"This package is CommonJS-only and does not support ES Modules (`import`/`export`) syntax for its own API. Attempting to import `node-qunit` using ESM will result in an error.","severity":"gotcha","affected_versions":"all versions"},{"fix":"Consider migrating to actively maintained testing frameworks like Jest, Mocha, or the official QUnit CLI (which runs QUnit tests in Node.js via headless browsers like Puppeteer or Playwright).","message":"This package is considered abandoned, with its last publish seven years ago (version 2.0.2). It is unlikely to receive further updates, bug fixes, or security patches. Usage in new projects is strongly discouraged.","severity":"breaking","affected_versions":"all versions"}],"env_vars":null,"last_verified":"2026-04-21T00:00:00.000Z","next_check":"2026-07-20T00:00:00.000Z","problems":[{"fix":"`npm install node-qunit` and then `require(\"node-qunit\")` in your code.","cause":"Attempting to install or `require` the `qunit` package when `node-qunit` is intended. `node-qunit` was previously named `qunit` before v1.0.0.","error":"Error: Cannot find module 'qunit'"},{"fix":"Use `QUnit.module()` instead, as `QUnit` is exposed globally by the test runner for defining test modules.","cause":"Using `module()` directly in a QUnit test file. The global `module` keyword conflicts with Node.js's native `module` object.","error":"ReferenceError: module is not defined"},{"fix":"Change the import statement to CommonJS: `const testrunner = require(\"node-qunit\");`.","cause":"Attempting to import `node-qunit` using ES Module syntax (`import { testrunner } from 'node-qunit'`). The package is CommonJS-only.","error":"SyntaxError: Named export 'testrunner' not found"},{"fix":"Review the test for infinite loops, blocking operations, or long-running async tasks. If the test genuinely needs more time, increase `testrunner.options.maxBlockDuration` or the specific run's `maxBlockDuration`.","cause":"A synchronous test, or an asynchronous test failing to complete its assertions within the configured `maxBlockDuration` (default 2000ms), causing the child process to be killed.","error":"RangeError: Maximum call stack size exceeded"}],"ecosystem":"npm"}