I'm writing an integration test using jest
. The test was successfully run on my Mac. But it throws an error in Bitbucket pipelines. I'm using pnpm
in Bitbucket pipelines.
The error is:
FAIL __tests__/integration/routes/signout.test.ts
● Console
console.warn
Starting the MongoMemoryServer Instance failed, enable debug log for more information. Error:
StdoutInstanceError: Instance failed to start because a library is missing or cannot be opened: "libcurl.so.4"
at MongoInstance.checkErrorInLine (/opt/atlassian/pipelines/agent/build/node_modules/.pnpm/mongodb-memory-server-core@8.14.0/node_modules/mongodb-memory-server-core/src/util/MongoInstance.ts:678:11)
at MongoInstance.stderrHandler (/opt/atlassian/pipelines/agent/build/node_modules/.pnpm/mongodb-memory-server-core@8.14.0/node_modules/mongodb-memory-server-core/src/util/MongoInstance.ts:563:10)
at Socket.emit (node:events:514:28)
at addChunk (node:internal/streams/readable:324:12)
at readableAddChunk (node:internal/streams/readable:297:9)
at Socket.Readable.push (node:internal/streams/readable:234:10)
at Pipe.onStreamRead (node:internal/stream_base_commons:190:23)
at MongoMemoryServer.<anonymous> (node_modules/.pnpm/mongodb-memory-server-core@8.14.0/node_modules/mongodb-memory-server-core/src/MongoMemoryServer.ts:293:17)
at node_modules/.pnpm/tslib@2.6.1/node_modules/tslib/tslib.js:169:75
at __awaiter (node_modules/.pnpm/tslib@2.6.1/node_modules/tslib/tslib.js:165:16)
at node_modules/.pnpm/mongodb-memory-server-core@8.14.0/node_modules/mongodb-memory-server-core/src/MongoMemoryServer.ts:284:68
● Signout › should clears the cookie when signing out
Instance failed to start because a library is missing or cannot be opened: "libcurl.so.4"
at MongoInstance.checkErrorInLine (node_modules/.pnpm/mongodb-memory-server-core@8.14.0/node_modules/mongodb-memory-server-core/src/util/MongoInstance.ts:678:11)
at MongoInstance.stderrHandler (node_modules/.pnpm/mongodb-memory-server-core@8.14.0/node_modules/mongodb-memory-server-core/src/util/MongoInstance.ts:563:10)
The error message is:
Instance failed to start because a library is missing or cannot be opened: "libcurl.so.4"
The test code is:
import { MongoMemoryServer } from "mongodb-memory-server";
import mongoose from "mongoose";
let mongo: any;
beforeAll(async () => {
process.env.JWT_KEY = "randomsafjlkfdsaauthkey";
mongo = await MongoMemoryServer.create();
const mongoUri = mongo.getUri();
await mongoose.connect(mongoUri, {});
});
beforeEach(async () => {
const collections = await mongoose.connection.db.collections();
for (let collection of collections) {
await collection.deleteMany({});
}
});
afterAll(async () => {
if (mongo) {
await mongo.stop();
}
await mongoose.connection.close();
});
// TEST CASE from another file
describe("Signout", () => {
it("should clears the cookie when signing out", async () => {
await request(app)
.post("/v2/auth/signup")
.send({
email: "test@test.com",
password: "password",
})
.expect(201);
const response = await request(app)
.post("/v2/auth/signout")
.send({})
.expect(200);
expect(response.get("Set-Cookie")[0]).toBe(
"session=; path=/; expires=Thu, 01 Jan 1970 00:00:00 GMT; httponly"
);
});
});
bitbucket-pipelines.yml
definitions:
caches:
pnpm: $BITBUCKET_CLONE_DIR/.pnpm-store
image: node:18-slim
pipelines:
default:
- step:
name: Build and test
script:
- corepack enable
- corepack prepare pnpm@latest-8 --activate
- pnpm install
- pnpm run test:ci
caches:
- pnpm
Node version: 18.17.1