Skip to content

Error: spawn Unknown system error -8 #202

Closed
@Keda87

Description

@Keda87

I'm setup test using mocha and chai using this package and failed to run test.
I got this following error and got no clue regarding the error.


  0 passing (115ms)
  1 failing

  1) POST /tasks
       "before all" hook for "OK, Create new task is success":
     Error: spawn Unknown system error -8
      at ChildProcess.spawn (internal/child_process.js:358:11)
      at Object.spawn (child_process.js:538:9)
      at Object.spawn [as default] (node_modules/cross-spawn/index.js:12:24)
      at MongoInstance._launchMongod (node_modules/mongodb-memory-server-core/lib/util/MongoInstance.js:198:49)
      at MongoInstance.<anonymous> (node_modules/mongodb-memory-server-core/lib/util/MongoInstance.js:134:50)
      at step (node_modules/mongodb-memory-server-core/lib/util/MongoInstance.js:43:23)
      at Object.next (node_modules/mongodb-memory-server-core/lib/util/MongoInstance.js:24:53)
      at fulfilled (node_modules/mongodb-memory-server-core/lib/util/MongoInstance.js:15:58)



error Command failed with exit code 1.

The test is running within docker container using node:10.14.2-alpine

Here is my mock connection when testing my project

/* eslint-disable no-undef */
import mongoose from 'mongoose'
import { MongoMemoryServer } from 'mongodb-memory-server';

const MONGO_USER = process.env.TODO_DB_USER
const MONGO_PASS = process.env.TODO_DB_PASS
const MONGO_PORT = process.env.MONGO_PORT
const MONGO_DB_NAME = process.env.TODO_DB_NAME
const DB_URI = `mongodb://${MONGO_USER}:${MONGO_PASS}@db:${MONGO_PORT}/${MONGO_DB_NAME}`


mongoose.Promise = Promise;

export function connect() {
  return new Promise((resolve, reject) => {

    if (process.env.NODE_ENV === 'test') {
      const mongoServer = new MongoMemoryServer({ debug: true })
      mongoServer.getConnectionString()
        .then((mongoUri) => {
          mongoose.connect(mongoUri, { useNewUrlParser: true })
            .then((res, err) => {
              if (err) { return reject(err) }
              resolve()
            })
        })
        .catch(err => reject(err))
    } else {
      mongoose.connect(DB_URI, { useNewUrlParser: true })
        .then((res, err) => {
          if (err) { return reject(err) }
          resolve()
        })
        .catch(err => reject(err))
    }

  })
}

export function close() {
  return mongoose.disconnect()
}

Also here is my test command
NODE_ENV=test mocha dist/tests --recursive --exit

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions