0

I am writing a small test app that exists only when tests are ran, otherwise not. Therefore I would like to have webpack perform asset copying when it is started.

In package.json I have added

"scripts": {
    "test_pack": "webpack --mode development"
  },

and now I am not sure how to properly bundle npm run test_pack to work when mix test is invoked?

aywen
  • 75
  • 1
  • 1
  • 9

1 Answers1

0

In your mix.exs you can create aliases. Maybe there already is an alias for test, something like (if you happen to use ecto):

  test: ["ecto.create --quiet", "ecto.migrate --quiet", "test"]

To add the npm command you want to run, you can use the cmd task, which is actually performing a mix.cmd:

  test: ["cmd npm run test_pack", "ecto.create --quiet", "ecto.migrate --quiet", "test"]

One warning though, from the mix.cmd docs, no idea if this would matter in your situation, but:

Beware that the Erlang VM does not terminate child processes when it shuts down. Therefore, if you use mix cmd to start long running processes and then shut down the VM, it is likely that those child processes won't be terminated with the VM.

zwippie
  • 15,050
  • 3
  • 39
  • 54