TheBrainFamily/chimpy

wrapAsync is not defined

abecks opened this issue · 2 comments

Expected behaviour
  • wrapAsync should be available globally as per the documentation
Actual behaviour
  • ReferenceError: wrapAsync is not defined
Exact steps to reproduce / repository that demonstrates the problem
  • Call wrapAsync in a test file
Version & tools:
  • Chimp command line used: chimp ../.chimp.js --mocha --path ../tests --ddp=http://127.0.0.1:3000 --watch --debug
  • Chimpy: 0.52.0
  • Meteor: 1.7.0.3
  • Node.js: v8.11.3
  • Java: 1.8.0_65
  • Operation system: Darwin Kernel Version 15.6.0: Tue Jan 9 20:12:05 PST 2018; root:xnu-3248.73.5~1/RELEASE_X86_64
  • Chimp version: 0.52.0
  • ChromeDriver version: ChromeDriver 2.40.565386 (45a059dc425e08165f9a10324bd1380cc13ca363)
  • Java version: java version "1.8.0_65", Java(TM) SE Runtime Environment (build 1.8.0_65-b17), Java HotSpot(TM) 64-Bit Server VM (build 25.65-b01, mixed mode)
  • Selenium version: 3.8.1
  • Selenium drivers version: chrome: 2.35, ie: 3.0.0, firefox: 0.19.1
  • OS version: Darwin 15.6.0
  • Node version: v8.9.1
  • Browser version: chrome 68.0.3440.75

Chimp configuration:

module.exports = {
  screenshotPath: '.screenshots',
  webdriverio: {
    waitforTimeout: 20000,
    waitforInterval: 25,
    desiredCapabilities: {
      browserName: 'chrome',
      chromeOptions: {
        prefs: {
          'download.default_directory': '/tmp',
          'download.directory_upgrade': 'true',
          'download.extensions_to_open': '',
          'download.prompt_for_download': 'false',
          credentials_enable_service: false,
          profile: {
            password_manager_enabled: false,
          },
        },
      },
    },
  },
}
Console / Log Output
ReferenceError: wrapAsync is not defined
    at Object.<anonymous> (/Users/andrew/Development/meteor/tests/http.js:118:13)
    at Module._compile (module.js:635:30)
    at loader (/Users/andrew/Development/meteor/node_modules/babel-register/lib/node.js:144:5)
    at Object.require.extensions.(anonymous function) [as .js] (/Users/andrew/Development/meteor/node_modules/babel-register/lib/node.js:154:7)
    at Module.load (module.js:554:32)
    at tryModuleLoad (module.js:497:12)
    at Function.Module._load (module.js:489:3)
    at Module.require (module.js:579:17)
    at require (internal/module.js:11:18)
    at /Users/andrew/Development/meteor/node_modules/chimpy/node_modules/mocha/lib/mocha.js:231:27
    at Array.forEach (<anonymous>)
    at Mocha.loadFiles (/Users/andrew/Development/meteor/node_modules/chimpy/node_modules/mocha/lib/mocha.js:228:14)
    at Mocha.run (/Users/andrew/Development/meteor/node_modules/chimpy/node_modules/mocha/lib/mocha.js:536:10)
    at new MochaWrapper (/Users/andrew/Development/meteor/node_modules/chimpy/dist/lib/mocha/mocha-wrapper.js:71:11)
    at Object.<anonymous> (/Users/andrew/Development/meteor/node_modules/chimpy/dist/lib/mocha/mocha-wrapper-instance.js:5:20)
    at Module._compile (module.js:635:30)
    at Object.Module._extensions..js (module.js:646:10)
    at Module.load (module.js:554:32)
    at tryModuleLoad (module.js:497:12)
    at Function.Module._load (module.js:489:3)
    at Function.Module.runMain (module.js:676:10)
    at startup (bootstrap_node.js:187:16)

So I've tracked this down to mocha-helper.js

chimp-helper.js has an init method that sets up all of the chimp-based global variables.

mocha-helper imports this file, but only runs init inside the before hook. The before hook has not run yet while the test files are being loaded by mocha, therefore these variables are not defined.

It would seem a solution is to move the call to chimpHelper.init() out of before and into the root of the mocha-helper file.

Happy to make a PR if someone like @samhatoum (sorry if you aren't the maintainer here anymore) can verify that is the proper solution.

Edit: Unless this is a bad move, and we should only be using wrapAsync and wrapAsyncObject inside before... which is how I'm starting to think this was intended to be used all along. Perhaps we just need to update the documentation to mention this?

Using wrapAsync inside before, beforeEach, etc. works, so I'm gonna close this issue. I do think it should be documented though.