Node Test Executor
test-executor is a Node.js library, currently at version 1.2.4, designed for executing test scripts and directories of test scripts within a CommonJS (CJS) environment. It was last published to npm approximately 7 years ago, indicating that while it has a semantic version, active development has largely ceased. The library's core mechanism is based on the Async Tree Pattern, which it leverages to manage test execution flow. Its primary dependency is `cutie`. This package offers a straightforward API for running tests by specifying file or directory paths, providing console output for results. Due to its age, it primarily targets older Node.js environments and does not natively support ECMAScript Modules (ESM) syntax or modern testing paradigms.
Common errors
-
Error [ERR_REQUIRE_ESM]: require() of ES Module ...test-executor.js not supported. ...
cause Attempting to `require()` or implicitly load `test-executor` in an ECMAScript Module (ESM) context.fixThis package is CommonJS-only. If your project is ESM, you cannot directly `import` or `require` this package. Consider migrating to a modern test runner or refactoring your project to use CJS if `test-executor` is critical. -
TypeError: ExecutedTests is not a constructor
cause Incorrectly trying to instantiate `test-executor` directly, or attempting to destructure a non-existent export.fixEnsure you are using `const { ExecutedTests } = require('test-executor')` and instantiating with `new ExecutedTests(...)`. The default export is not `ExecutedTests` itself. -
Error: Cannot find module 'test-executor'
cause The `test-executor` package is not installed or cannot be resolved by Node.js.fixRun `npm install test-executor` or `yarn add test-executor` to install the package. Verify that `node_modules` is present and accessible.
Warnings
- breaking This package is CommonJS (CJS) only and does not support ECMAScript Modules (ESM). Trying to import it using `import ... from 'test-executor'` syntax in an ESM project will cause runtime errors.
- gotcha The package `test-executor` was last published approximately 7 years ago. This indicates it is no longer actively maintained and may have compatibility issues with newer Node.js versions, dependencies, or modern JavaScript features.
- gotcha The `ExecutedTests` constructor expects file paths or directory paths as arguments. Incorrect paths will result in no tests being found or executed, without necessarily throwing a clear error about invalid paths.
Install
-
npm install test-executor -
yarn add test-executor -
pnpm add test-executor
Imports
- ExecutedTests
import { ExecutedTests } from 'test-executor'const { ExecutedTests } = require('test-executor')
Quickstart
const { ExecutedTests } = require('test-executor');
// To execute tests from specific files and directories:
new ExecutedTests(
'./test/example-test.js',
'./test/my-test-dir/file1.js',
'./test/my-test-dir/file2.js'
).call();
// Or to execute all tests within a single top-level directory:
// Note: Ensure './test' exists and contains test files.
// new ExecutedTests('./test').call();
console.log('Test execution initiated. Results will be logged to console.');
// Example of a simple test file (e.g., ./test/example-test.js):
// module.exports = class ExampleTest {
// constructor() {}
// testSuccess() { console.assert(true, 'Success!'); }
// testFailure() { console.assert(false, 'Failure!'); }
// };