我为Nx Nest应用程序配置了Jest E2E项目。我的目标是运行docker compose up
进行E2E测试,并在测试结束后运行docker compose down
。
在global-setup.ts
中,我写道:
/* 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';
};
问题是,当我运行npx nx e2e <e2e-project>
时,所有测试都因为Internal Server Error
而失败,这是因为docker compose up
是outran。
有什么想法吗
1条答案
按热度按时间xlpyo6sf1#
我强烈推荐使用https://pdmlab.github.io/docker-compose/。
然后,将
docker-compose.yml
与global-setup.ts
和global-teardown.ts
放在同一个目录中,像这样配置global-setup.ts
:global-teardown.ts
是这样的:这应该能起到作用,让你开始。祝你好运,玩得开心!