Detecting whether code is running in mirror when using Velocity to test a Meteor app

356 views Asked by At

I have a simple Meteor application. I would like to run some code periodically on the server end. I need to poll a remote site for XML orders.

It would look something like this (coffee-script):

unless process.env.ORDERS_NO_FETCH
    Meteor.setInterval ->
        checkForOrder()
    , 600000

I am using Velocity to test. I do not want this code to run in the mirrored instance that runs the tests (otherwise it will poach my XML orders and I won't see them in the real instance). So, to that end, I would like to know how to tell if server code is running in the testing environment so that I can avoid setting up the the periodic checks.

EDIT I realised that I missed faking one of my server calls in the tests, which is why my test code was grabbing one of the XML orders from the real server. So, this might not be an issue. I am not sure yet how the tests are run for the server code and if the server code runs in a mirror (is that a client only concept)?.

1

There are 1 answers

1
Xolv.io On BEST ANSWER

The server and the client both run in a mirror when using mocha/jasmine integration tests.

If you want to know if you are in a mirror, you can use:

Meteor.call('velocity/isMirror', function(err, isMirror) { if (isMirror) { // do something } });

Also, on the server you can use:

process.env.IS_MIRROR

You've already got the fake working, and that is the right approach.