Weird behavior when testing async/await using meteortesting:mocha

#1

I’m having some weird behaviors when trying to add an integration test on an async function that calls other async functions, seems the code doesn’t run fully, problem is if I run the function on regular development mode it works as expected, but when running from a test it seems it misses calling some other async functions.

I’m using babel-plugin-istanbul, babel-plugin-rewire-exports, chai, chai-as-promised and sinon.

I run the tests with this npm run

"coverage:watch": "BABEL_ENV=COVERAGE COVERAGE=1 COVERAGE_VERBOSE=1 COVERAGE_APP_FOLDER=$PWD/ TEST_WATCH=1 MONGO_URL=mongodb://localhost:27017/worker meteor test --driver-package meteortesting:mocha --port 4000 --settings settings-development.json"

and this is my babel configuration on my packages.json

"babel": {
    "env": {
      "COVERAGE": {
        "plugins": [
          "istanbul",
          "babel-plugin-rewire-exports",
          {
            "unsafeConst": true
          }
        ]
      }
    }
  },

Any help will be truly appreciated as I have no clue why it doesn’t fully run on the integration test but on the regular app it works.

Thanks a lot!

1 Like
#2

I don’t have an answer for you as such, but I ran into similar problems with Cypress around some rxjs functions. Cypress modifies the event handling, and suspends some activities while it is waiting for the DOM to render. My code ran perfectly in normal mode, but didn’t fire events reliably in tests under Cypress. I ended up detecting the environment and not using the rxjs code (which I was using for debouncing), and it worked fine again.

It’s not ideal, and it means that the debouncing code is not tested, but everything else does get tested at least.

I vaguely remember something similar with meteor testing, and again ended up making the tests simpler (without the async part)

1 Like