Using Doppler with spawn and mocha

I have code that is using spawn to launch mocha.cmd. I am having trouble getting the syntax to get doppler cli prepended to the mocha cli command.

If it was a package.json script I would write as so:

"test:mocha": "doppler run --command \"mocha --no-deprecation --timeout 600000\""

but withing spwan this becomes a bit more complex and I can’t see any examples of how this might work:

const mocha = spawn(
      "doppler"[
        ("run",
        "--",
        '\\"node_modules\\.bin\\_mocha.cmd',
        [
          "--no-deprecation",
          "--timeout",
          "600000",
        ])
      ]
    );

This produces error (which I think i just red herring due to bad parsing of my spawn syntax):

Mocha error:  TypeError [ERR_INVALID_ARG_TYPE]: The "file" argument must be of type string.

I am on Windows platform hence the // in spawn…

Hi @Disco_Stew!

I believe what you’d want should be something like this:

const mocha = spawn(
  "doppler",
    [
      "run",
      "--",
      "\\node_modules\\.bin\\_mocha.cmd",
      "--no-deprecation",
      "--timeout",
      "600000"
    ]
);

Basically, everything after doppler is an argument to the doppler binary, so it all goes into the args array. Give that a shot and see if it works for you.

Regards,
-Joel

@watsonian That definitely helped, Doppler is now engaged without error, but it is having trouble with the path to mocha.cmd I am guessing by this error:
Doppler Error: exec: "\\node_modules\\.bin\\_mocha.cmd": file does not exist

Correcting the pathing by removing the leading \ fixed it:

    const mocha = spawn("doppler", [
      "run",
      "--",
      "node_modules\\.bin\\_mocha.cmd",
      "--no-deprecation",
      "--timeout",
      "600000",
    ]);

@Disco_Stew You may need to put the full path to the file. I’m not 100% sure for Windows environments, but on linux you also use . to indicate the current directory, so the relative version of that path would be .\\node_modules\\.bin\\_mocha.cmd – might be worth a try as well!