Closed goldylucks closed 2 years ago
Please provide the full debug output from both the postinstall and the actually running of the tests.
PS: also if possible, dont censor the paths used in the debug output
PPS: the postinstall expects to be run in a package-manager environment where INIT_CWD
is set, so this may affect some things
@hasezoey thanks for looking into this ❤️
Debug output
Let me know if there's anything else I can do to help you help me :)
can confirm from the log that the postinstall downloads and places the binary in the correct path and confirm that the test tries to look into the directory where the postinstall has put the binary, but cannot find it
could you maybe put a simple log like ls -al ~/.cache/mongodb-binaries
before running the tests (but after the postinstall) and provide the output?
btw, how do you tests work, because i can see that MMS is somehow loaded 4 times (not 4 server instances, but actually loaded 4 times)?
PS: why are some home paths "censored" but some not even though they should be the same?
nx run api:test
, which is just a wrapper around jest
Somehow some of the test pass now, with the only change being adding this log, but, there are still errors thrown globally in the execution of the tests
#!/bin/bash -eo pipefail
ls -al ~/.cache/mongodb-binaries
total 106908
drwxr-xr-x 2 circleci circleci 37 Aug 1 10:31 .
drwxr-xr-x 4 circleci circleci 42 Aug 1 10:31 ..
-rwxr-xr-x 1 circleci circleci 109473272 Aug 1 10:31 mongod-x64-ubuntu-5.0.8
and the logs for the tests:
Thanks for the extra information, thanks to it, it is confirmed that the binary actually exists and has the proper permissions (and name), but somehow the test environment is unable to find / see these binaries, which i cannot quite understand on why.
as a side note, how are your tests set-up? because i see a lot of "attempted after finished / torn down" messages
@hasezoey thanks for confirming that.
The "after finished" messages (probably) come from the cleanup phase in which I clear the DB, which isn't connected since MMS can't find the binaries.
Maybe the problem here is the combination of CircleCi + nx?
I don't know how nx work behind the scenes, basically it's a tool to manage monorepos.
Any idea how to get around this issue?
Maybe setting an environment variable somewhere?
Any idea how to get around this issue?
no i dont really have a clue
Maybe setting an environment variable somewhere?
you could try to manually set the path to the downloaded binary (though if defined in the package.json, it will also disable downloading it) with MONGOMS_SYSTEM_BINARY
, but if this works, then i really have no clue on why it would not work out-of-the-box
PS: if its public, you could try to share your circleci config (if any)
sure, here's the relevant part:
version: 2.1
orbs:
node: circleci/node@5.0.2
nx: nrwl/nx@1.5.1
cypress: cypress-io/cypress@2.1.0
jobs:
main:
docker:
- image: cimg/node:lts-browsers
environment:
NX_CLOUD_DISTRIBUTED_EXECUTION: "true"
steps:
- checkout
- node/install-packages:
pkg-manager: yarn
- run: npx nx run-many --all --target=test --parallel=20 --ci --code-coverage
workflows:
build:
jobs:
- main
And here's how I mock mongo:
import { MongoMemoryServer } from "mongodb-memory-server"
import mockMongoose from "mongoose"
const mockMongoMemoryServer = MongoMemoryServer.create()
// @ts-ignore
jest.mock("../../src/db", () => ({
// @ts-ignore
...(jest.requireActual("../../src/db").default as any),
// @ts-ignore
connect: jest.fn().mockImplementation(async () => {
const mongo = await mockMongoMemoryServer
const uri = mongo.getUri()
await mockMongoose.connect(uri)
}),
}))
and the app calls db.connect()
on init
thanks for providing the config, from what i can tell, it does not have any problems and from some searching it also seems like circleci does not hide files or remove them, which leads me to believe that either jest or nx have problems
are you maybe mocking some files or file paths somewhere in jest (or nx) aside from the one example provided?
also if you still can work on this issue, could you put console.log(fs.readDirSync(path.join(os.homedir(), '.cache/mongodb-binaries')));
(and import import * as fs from "fs"; import * as path from "path"; import * as os from "os";
) just before you call .create
for a instance and provide the output?
I have no idea how, but it's working fine now. Not sure exactly what I change 🤷
Thank you so much for the support!
Versions
package: mongo-memory-server
What is the Problem?
Locally everything passes, but on circle ci it tries to download the binary even tho it's already there.
By running
node node_modules/mongodb-memory-server/postinstall.js
on CircleCi I see this output:However then down the line when I run my tests:
in addition, the SYSTEM_BINARY env variable is set to the path where the binary is.
Code Example
Do you know why it happenes?
no