I have Jest E2E project configured for Nx Nest app. My goal is to run docker compose up
for E2E testing and docker compose down
after testing is over.
In global-setup.ts
, I wrote:
/* eslint-disable */
var __TEARDOWN_MESSAGE__: string;
var os = require('os');
module.exports = async function () {
// Start services that that the app needs to run (e.g. database, docker-compose, etc.).
console.log('\nSetting up...\n');
globalThis.execCmd = (cmd: string) => {
const exec = require('child_process').exec;
const command = exec(cmd, (err, stdOut, stdErr) => {
if (err) {
console.log(err);
return;
}
console.log(stdOut);
});
return command;
};
const isWin = os.platform() === 'win32';
const dockerComposeUpCmd = 'docker compose up';
await globalThis.execCmd(dockerComposeUpCmd).on('exit', (code) => {
console.log(`${command}: Finished with code ${code}`);
});
// Hint: Use `globalThis` to pass variables to global teardown.
globalThis.__TEARDOWN_MESSAGE__ = '\nTearing down...\n';
};
The problem is that, when I run npx nx e2e <e2e-project>
, all tests fail because of Internal Server Error
, which happens because docker compose up
is outran.
Any ideas?