What should be put into `command` and what should be put into `args`?

Hi,

I have some tests that I’m currently running with docker run /bin/bash -c "yarn jest --silent". I noticed that in garden both of these would run all the tests:
Using command:

tests:
  - name: modules
    command: ['yarn']
    args:
      - jest
      - --silent

Using args:

tests:
  - name: modules
    args:
      - yarn 
      - jest
      - --silent

However, jest’s behavior in both of these cases are different from what I currently have. Right now jest would print out something like this for each file it ran:

PASS src/something.spec.ts

But with the ways above it doesn’t. After some experiments it seems like this gets me the behavior I want:

tests:
  - name: modules
    command: [/bin/bash, -c, "yarn jest --silent"]

But if I move any of the args to args, it does not work. If I only have /bin/bash in command and the rest in args, the test would just run yarn install and exit right away. So I’m pretty confused what’s causing the differences here.

Thanks in advance!
Anna

Hey @anna! The command and args fields basically map directly to the same fields in Kubernetes Pod specs, which is indeed slightly confusing since it’s different to the Docker semantics. In Docker parlance, command maps to ENTRYPOINT, and args maps to CMD.

I’m not sure what ENTRYPOINT is set in the Dockerfile that’s being used in your case, but it seems to me you have the right idea with your last attempt there.

One alternative would be something like

tests:
  - name: modules
    command: [/bin/bash, -c]
    args:
      - "yarn jest --silent"

Note that /bin/bash -c expects a single string as an argument, which is why the 2nd option doesn’t work. I’m not 100% sure why your first example doesn’t work right though, might be something specific to yarn.

Does that make sense?

1 Like

Yea thanks Jon! I tried a few different things and I realized that it wasn’t using command vs args that made the difference, but the artifacts field. when I comment out artifacts, either using command or args gives me the kind of jest output I want. When I try to get the junit ouput copied over with artifacts though, jest finishes with no outputs, even ignoring options like --verbose. The artifacts do get copied over just fine. Does that behavior ring a bell?

That’s interesting. You may well have found a bug actually! Would you mind filing an issue for that on GitHub? There is a different code path used when copying out artifacts, so it seems probable that you’ve come across a legit issue there.

Yep, here’s the issue: Test command shows different behaviors when using artifacts · Issue #2634 · garden-io/garden · GitHub

Thanks again!

1 Like