How can I detect if meteor is running normally or running tests?

Is it possible to detect whether meteor was started in normal or test mode?

Normal mode is just:


Test mode is like so:

meteor test-packages

Can I somehow detect in my code when Meteor was started in the second form? I could probably get the arguments that were passed to the meteor command? What I really want to know is whether some kind of flag is set that I could read when meteor is started in test-packages mode.

I’ve been reading some of the meteor core code and I can’t find anything that appears to be set while meteor is running in test-packages mode. But if I missed something, I’ll be very happy. :smile:

If you have a package you are using that has the debugOnly flag set, it will not be bundled with normal builds (unless you do a debug build).

That’s the current “right way” to have test-only code. I wouldn’t use a flag.

I just thought of another idea - should you really want to have the knowledge at runtime. You could try (untested) to include an unordered: true flag on a package that you use in Package.onTest. This package could then set a global param. Ugly, I know, but you asked :slight_smile:

@sam Great, thanks for the tip about debugOnly. It’s not quite what I’m looking for, because it will also be run when I run meteor in development mode, but it’s definitely useful.

The unordered: true flag is also an interesting idea. It allows the dependency package to load afterwards, but I wonder if it actually requires it to load after. From reading the docs, I’d guess not, but it might do.