Got a test for a React app's login function in a Page class:
async login(t) {
console.log('starting login...');
debugger;
this.logBrowserMessages(t);
await this.loginModal({ visibilityCheck: true });
await t
.expect(this.loginModal.visible)
.ok()
// then log the user in etc...
And the test, which passes when running locally but fails in the container
test.requestHooks(mock)('user can log in', async t => {
await page.login(t);
// Make sure test user's orders render.
await t.expect(page.orders.childNodeCount).gt(1, { timeout: 10000 });
The test passes locally but fails (the login doesn't work) when running in the container.
When I run the test locally it debugs as expected:
testcafe chrome --inspect-brk=9230 ./tests/login.test.js --skip-js-errors
The process node_modules/testcafe/lib/cli
shows up in my chrome://inspect/#devices
, as expected.
However, when I run testcafe in the testcafe docker container it won't debug with any of these commands:
docker run --expose 9230 -p 9230:9230 -e BASIC_AUTH_USER -e BASIC_AUTH_PASS -e NODE_ENV=docker -e TEST_USER -e TEST_PASS --shm-size=1gb -v `pwd`:/tests -v `pwd`/screenshots/docker:/screenshots testcafe/testcafe 'chromium --no-sandbox' --inspect-brk=0.0.0.0:9230 -S -s '/screenshots' --skip-js-errors /tests/**/login.test.js
docker run --expose 9230 -p 9230:9230 -e \"NODE_PATH=/opt:/opt/testcafe/node_modules:/tests/node_modules\" -e BASIC_AUTH_USER -e BASIC_AUTH_PASS -e NODE_ENV=docker -e TEST_USER -e TEST_PASS --shm-size=1gb -v `pwd`:/tests -v `pwd`/screenshots/docker:/screenshots testcafe/testcafe 'chromium --no-sandbox' --inspect-brk=0.0.0.0:9230 -S -s '/screenshots' --skip-js-errors /tests/**/login.test.js
docker run --expose 9230 -p 9230:9230 -e BASIC_AUTH_USER -e BASIC_AUTH_PASS -e NODE_ENV=docker -e TEST_USER -e TEST_PASS --shm-size=1gb -v `pwd`:/tests -v `pwd`/screenshots/docker:/screenshots testcafe/testcafe 'chromium --no-sandbox' --inspect-brk=127.0.0.1:9230 -S -s '/screenshots' --skip-js-errors /tests/**/login.test.js
docker run --expose 9230 -p 9230:9230 -e \"NODE_PATH=/opt:/opt/testcafe/node_modules:/tests/node_modules\" -e BASIC_AUTH_USER -e BASIC_AUTH_PASS -e NODE_ENV=docker -e TEST_USER -e TEST_PASS --shm-size=1gb -v `pwd`:/tests -v `pwd`/screenshots/docker:/screenshots testcafe/testcafe --inspect-brk=0.0.0.0:9230 --browsers 'chromium --no-sandbox' -S -s '/screenshots' --skip-js-errors /tests/**/login.test.js
docker run --expose 9230 -p 9230:9230 -e \"NODE_PATH=/opt:/opt/testcafe/node_modules:/tests/node_modules\" -e BASIC_AUTH_USER -e BASIC_AUTH_PASS -e NODE_ENV=docker -e TEST_USER -e TEST_PASS --shm-size=1gb -v `pwd`:/tests -v `pwd`/screenshots/docker:/screenshots testcafe/testcafe 'chromium --no-sandbox' -S -s '/screenshots' --skip-js-errors --inspect-brk=9230 /tests/**/login.test.js
Is there some limitation to the container that I'm using that I'm not aware of? I've debugged Node processes running in Docker containers before, I know it can be done. But it was a while ago. Am I missing something?
You can use the NODE_OPTIONS
environment variable to enable remote debugging:
docker run -it --rm -p 9229:9229 -e NODE_OPTIONS="--inspect-brk=0.0.0.0:9229" -v /host/path/to/tests:/tests testcafe/testcafe 'chromium --no-sandbox' /tests/test.js
If you don't use docker-machine
, you can open http://localhost:9229/json
in your browser and navigate to a DevTools URL specified in the devtoolsFrontendUrl
property.
Otherwise, use the docker-machine ip
command to get the IP address of your Docker VM and open http://${DOCKER_MACHINE_IP}:9229/json
to get a DevTools URL.