Jest Node Debug Environment (Fixed)

2.0.0 · abandoned · verified Sun Apr 19

The `jest-environment-node-debug-fixed` package was developed to resolve debugging challenges encountered when using Jest versions up to around 19 with Node.js 7. It provided a specialized test environment to facilitate debugging, especially with external tools like `devtool` or the native Node.js Inspector. This 'fixed' version aimed to patch compatibility issues that prevented seamless debugging in those specific, older environments. However, with significant advancements in Jest (currently stable at 30.x) and Node.js, native debugging capabilities have become robust and universally supported. Modern Jest integrates directly with Node's inspector protocol, enabling streamlined debugging through IDEs like VS Code or browser developer tools without the need for custom environments. The package's release cadence was ad-hoc, responding to specific compatibility hurdles of its era, and it has not been updated to support contemporary Jest or Node.js versions, making it largely obsolete for current development workflows.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates how to configure Jest to use `jest-environment-node-debug-fixed` and initiate a debugging session using Node's inspector with a simple TypeScript test file.

// package.json
{
  "name": "my-jest-app",
  "version": "1.0.0",
  "devDependencies": {
    "jest": "^29.0.0",
    "jest-environment-node-debug-fixed": "2.0.0",
    "ts-jest": "^29.0.0",
    "typescript": "^5.0.0"
  },
  "scripts": {
    "test": "jest",
    "test:debug": "node --inspect-brk node_modules/.bin/jest --runInBand --config ./jest.config.js"
  }
}

// jest.config.js
module.exports = {
  testEnvironment: 'jest-environment-node-debug-fixed',
  roots: ['<rootDir>/src'],
  testMatch: ['**/__tests__/**/*.ts', '**/?(*.)+(spec|test).ts'],
  transform: {
    '^.+\.ts$': 'ts-jest'
  },
  globals: {
    'ts-jest': {
      tsconfig: 'tsconfig.json'
    }
  }
};

// tsconfig.json
{
  "compilerOptions": {
    "target": "ESNext",
    "module": "CommonJS",
    "strict": true,
    "esModuleInterop": true,
    "skipLibCheck": true,
    "forceConsistentCasingInFileNames": true
  }
}

// src/__tests__/example.test.ts
describe('My Debuggable Test Suite', () => {
  test('should perform a basic calculation', () => {
    const a = 10;
    const b = 20;
    // Add a debugger statement to pause execution
    // debugger;
    const result = a + b;
    expect(result).toBe(30);
  });
});

// To debug:
// 1. Open Chrome and navigate to chrome://inspect
// 2. In your terminal, run: npm run test:debug
// 3. In chrome://inspect, click "Open dedicated DevTools for Node" and then "inspect" for the Jest process. The debugger will pause at the first line of Jest's CLI.

view raw JSON →