How to execute a docker-compose command from within a Cypress test

Viewed 424

The root of my app project contains my docker-compose and Makefile, plus a folder called apps. Within apps is api and frontend. My Cypress installation is within the frontend folder.

I would like to be able to run a command cy.exec('make reset-fixtures') from within Cypress. This returns a "No rule to make target reset-fixtures" error, which I figured might be because I am executing from a folder that is deeper in the tree than my Makefile. So I changed my command to cy.exec('cd ../.. && make reset-fixtures') which yielded the following:

Stderr:
the input device is not a TTY
make[1]: *** [reset-fixtures] Error 1

What is the best way to be able to execute these make commands from within Cypress?

EDIT: This is the make command:

reset-fixtures:     
@docker-compose exec mongodb /scripts/reset-fixtures.sh
1 Answers

What worked for me was using the -T option with docker-compos exec. This prevents the use of TTY:

-T, --no-TTY docker compose exec     Disable pseudo-TTY allocation. By default docker compose exec allocates a TTY.

This would make it look like the following:

cypress test

cy.exec('(cd ../; make your_command)')

Makefile

your_command:
  docker-compose exec -T your_container path_to_executable
Related