Skip to content

nock@14 breaks testcontainers #2839

@radekbenkel

Description

@radekbenkel

Please avoid duplicates

Reproducible test case

https://gist.github.com/radekbenkel/6cede03ae57d93d5d238667476e1851c/c13fac327b2fa45ca3fad01786d514e76b62334f

Nock Version

14.0.0

Node Version

22.13.1

TypeScript Version

No response

What happened?

I updated to nock@14 and suddenly testcontainers stopped working.

Code in gist shows case which works:

radek@olive:~/nock-testcontainers-test$ node index.mjs
Container started
Container stopped

But when nock is imported (without any changes, because according to the docs by default it allows access) testcontainers fails.

radek@olive:~/nock-testcontainers-test$ head -n4 index.mjs
import { GenericContainer } from 'testcontainers';

// uncomment next line to see bug
import nock from 'nock';

radek@olive:~/nock-testcontainers-test$ DEBUG=testcontainers node index.mjs
  testcontainers [DEBUG] Checking container runtime strategy "TestcontainersHostStrategy"... +0ms
  testcontainers [DEBUG] Container runtime strategy "TestcontainersHostStrategy" is not applicable +3ms
  testcontainers [DEBUG] Checking container runtime strategy "ConfigurationStrategy"... +0ms
  testcontainers [DEBUG] Container runtime strategy "ConfigurationStrategy" is not applicable +0ms
  testcontainers [DEBUG] Checking container runtime strategy "UnixSocketStrategy"... +0ms
  testcontainers [TRACE] Fetching Docker info... +1ms
  testcontainers [DEBUG] Container runtime strategy "UnixSocketStrategy" does not work: "Error: connect ECONNREFUSED 127.0.0.1:80" +37ms
  testcontainers [DEBUG] Error: connect ECONNREFUSED 127.0.0.1:80
  testcontainers     at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1634:16) +0ms
  testcontainers [DEBUG] Checking container runtime strategy "RootlessUnixSocketStrategy"... +1ms
  testcontainers [DEBUG] Container runtime strategy "RootlessUnixSocketStrategy" is not applicable +1ms
  testcontainers [DEBUG] Checking container runtime strategy "NpipeSocketStrategy"... +0ms
  testcontainers [DEBUG] Container runtime strategy "NpipeSocketStrategy" is not applicable +0ms
/home/radek/nock-testcontainers-test/node_modules/testcontainers/build/container-runtime/clients/client.js:66
    throw new Error("Could not find a working container runtime strategy");
          ^

Error: Could not find a working container runtime strategy
    at getContainerRuntimeClient (/home/radek/nock-testcontainers-test/node_modules/testcontainers/build/container-runtime/clients/client.js:66:11)
    at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
    at async GenericContainer.start (/home/radek/nock-testcontainers-test/node_modules/testcontainers/build/generic-container/generic-container.js:55:24)
    at async file:///home/radek/nock-testcontainers-test/index.mjs:8:26

Node.js v22.13.1

As you see, it cannot connect to the socket:

testcontainers [DEBUG] Container runtime strategy "UnixSocketStrategy" does not work: "Error: connect ECONNREFUSED 127.0.0.1:80" +37ms
testcontainers [DEBUG] Error: connect ECONNREFUSED 127.0.0.1:80
radek@olive:~/nock-testcontainers-test$ docker context ls
NAME        DESCRIPTION                               DOCKER ENDPOINT               ERROR
default *   Current DOCKER_HOST based configuration   unix:///var/run/docker.sock

Downgrading to [email protected] fixes the issue:

# npm install nock@13
radek@olive:~/nock-testcontainers-test$ npm ls nock
[email protected] /home/radek/nock-testcontainers-test
└── [email protected]

radek@olive:~/nock-testcontainers-test$ head -n 4 index.mjs
import { GenericContainer } from 'testcontainers';

// uncomment next line to see bug
import nock from 'nock';

radek@olive:~/nock-testcontainers-test$ node index.mjs
Container started
Container stopped

Am I doing something incorrectly? Is there additional configuration required?

Would you be interested in contributing a fix?

  • yes

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions