我正在尝试在NestJS
应用程序中实现E2E测试。我在Docker容器中使用Postgres。对于其他测试,它运行良好。唯一的问题是E2E测试。我得到以下错误:
No Docker client strategy found
at node_modules/testcontainers/dist/docker/docker-client.js:46:11
at fulfilled (node_modules/testcontainers/dist/docker/docker-client.js:5:58)
● Test suite failed to run
TypeError: Cannot read properties of undefined (reading 'close')
59 |
60 | afterAll(async () => {
> 61 | await app.close();
| ^
62 | await container.stop();
63 | });
64 |
at Object.<anonymous> (test/event.e2e-spec.ts:61:15)
字符串
我的代码如下:
describe('EventAPI (e2e)', () => {
jest.setTimeout(180_000);
let app: INestApplication;
let service: Service;
let container: E2EPgContainer;
beforeAll(async () => {
container = new E2EPgContainer();
await container.init();
// eslint-disable-next-line @typescript-eslint/no-var-requires
const AppModule = require('../src/server/app/app.module').AppModule;
const module: TestingModule = await Test.createTestingModule({
imports: [AppModule],
}).compile();
app = module.createNestApplication();
app.useGlobalPipes(new ValidationPipe({ transform: true }));
service = module.get<Service>(Service);
await app.init();
});
afterEach(() => {
jest.clearAllMocks();
});
afterAll(async () => {
await app.close();
await container.stop();
});
describe('GET-POINT API', () => {
it('GET /:customerId --> should return success 200 after get points', async () => {
// test code
});
});
});
型
如何解决这个问题?
2条答案
按热度按时间ztmd8pv51#
我假设你的docker容器正在运行,但不是无根的。请确保您正在以无根方式运行Docker。您可以尝试以下操作:
字符串
现在确保设置了以下环境变量(或将它们添加到
~/.bashrc
)型
现在尝试重新启动
docker
型
完成所有步骤后,尝试在终端中执行docker命令,而不使用sudo:
型
如果你能够看到你的docker容器,那么它将解决你的问题。
7fhtutme2#
在将Docker升级到
4.21.1
版本后,我在Mac上遇到了同样的问题,我通过创建此问题中建议的符号链接进行了修复字符串