Skip to content

Troubleshooting

Solutions to common issues with rjest.

Common Errors

"Cannot use import statement outside a module"

Cause: TypeScript/ESM not being transformed to CommonJS.

Solution:

  1. Stop and restart the daemon:

    jest --daemon-stop
    jest
    

  2. Clear the transform cache:

    rm -rf ~/.cache/rjest
    jest
    

  3. Ensure your file has a TypeScript extension (.ts, .tsx).

"Daemon is not running"

Cause: The daemon hasn't started or crashed.

Solution:

  1. Start the daemon by running any test:

    jest
    

  2. Check for port conflicts:

    # See if something else is using the socket
    ls -la /tmp/rjest-*
    

  3. Check daemon logs:

    RUST_LOG=debug jest
    

"Connection refused" or Socket Errors

Cause: Daemon died or socket file is stale.

Solution:

  1. Kill any stale processes:

    pkill -f jestd
    

  2. Remove stale socket files:

    rm -f /tmp/rjest-*
    

  3. Restart:

    jest
    

Tests Pass in Jest but Fail in rjest

Cause: Using unsupported features.

Check for:

  1. jest.requireActual() - Not supported
  2. testEnvironment: 'jsdom' - Not supported
  3. Custom reporters - Not supported
  4. globalSetup/globalTeardown - Not supported

Solution: Check the Migration Guide for workarounds.

Mock Not Working

Cause: Mock not set up correctly.

Check:

// Ensure mock is created before use
const mockFn = jest.fn().mockReturnValue(42);

// Ensure you're checking the mock, not original
expect(mockFn).toHaveBeenCalled(); // ✓
expect(originalFn).toHaveBeenCalled(); // ✗ Wrong!

For module mocks:

// Mock must be called before import
jest.mock('./module');

// Then import
import { fn } from './module';

Snapshot Mismatch

Cause: Output changed or snapshot is stale.

Solution:

  1. Review the diff carefully
  2. If change is intentional:

    jest -u
    

  3. If change is unintentional, fix your code.

"expect(...).toSomeMatcher is not a function"

Cause: Matcher not implemented in rjest.

Check available matchers in Matchers Guide.

Workaround: Use available matchers:

// Instead of: expect(x).toBeWithinRange(1, 10)
expect(x).toBeGreaterThanOrEqual(1);
expect(x).toBeLessThanOrEqual(10);

Tests Timeout

Cause: Async operation taking too long.

Solutions:

  1. Increase timeout:

    test('slow test', async () => {
      // ...
    }, 30000); // 30 seconds
    

  2. Check for unresolved promises:

    // Bad: Floating promise
    test('async', () => {
      fetchData(); // Not awaited!
    });
    
    // Good: Await the promise
    test('async', async () => {
      await fetchData();
    });
    

  3. Check for infinite loops in mocks.

Daemon Issues

Daemon Won't Start

Check logs:

RUST_LOG=debug jest 2>&1 | head -50

Common causes:

  1. Port already in use
  2. Insufficient permissions
  3. Missing Node.js

Solutions:

# Check Node.js is available
which node
node --version

# Check for zombie processes
ps aux | grep jest
pkill -f jestd

# Try again
jest

Daemon Crashes

Check for errors:

RUST_LOG=trace jest

Common causes:

  1. Out of memory
  2. Invalid configuration
  3. Corrupt cache

Solutions:

# Clear cache
rm -rf ~/.cache/rjest

# Reduce workers
jest --maxWorkers=1

Daemon Uses Too Much Memory

Solution: Stop when not testing:

jest --daemon-stop

Or reduce workers:

jest --maxWorkers=2

Configuration Issues

Config Not Found

Check file exists:

ls jest.config.*

Check format:

// jest.config.js
module.exports = {
  // Must use CommonJS exports
};

Config Changes Not Applied

Solution: Restart daemon:

jest --daemon-stop
jest

TypeScript Config Not Working

Ensure you're exporting correctly:

// jest.config.ts
import type { Config } from 'jest';

const config: Config = {
  testMatch: ['**/*.test.ts'],
};

export default config;

Debug Mode

Enable Verbose Logging

# Info level
RUST_LOG=info jest

# Debug level
RUST_LOG=debug jest

# Trace level (very verbose)
RUST_LOG=trace jest

Log Specific Components

# Only daemon logs
RUST_LOG=jestd=debug jest

# Only transform logs
RUST_LOG=jestd::transform=debug jest

Save Logs to File

RUST_LOG=debug jest 2>&1 | tee rjest.log

Getting Help

Check Daemon Status

jest --daemon-status

Version Information

jest --version

File an Issue

When filing an issue, include:

  1. rjest version (jest --version)
  2. Node.js version (node --version)
  3. Operating system
  4. Minimal reproduction
  5. Debug logs (RUST_LOG=debug jest)

Quick Reset

If all else fails:

# Kill all rjest processes
pkill -f jestd
pkill -f rjest

# Clear all caches
rm -rf ~/.cache/rjest

# Clear transform cache
rm -rf /tmp/rjest-*

# Start fresh
jest