ember.js - Testing Emberjs app using QUnit and Karma fails due to `ReferenceError: Faye is not defined` -
i testing emberjs application qunit , karma runner , working good. had integrate faye application went on running test suite, shows following error , crashes:
referenceerror: faye not defined
the error thrown where, defining client in emberjs
client = new faye.client(uri);
though works in development, staging not in testing. overhere, uri = "http://localhost:9292/faye"
faye.js included in vendor.js(single js file have js plugins including ember.js , ember-data.js itself) loaded before app.js(file above line exists)
the reason of weird behavior related following lines in faye:
if (typeof module !== 'undefined') module.exports = faye; else if (typeof window !== 'undefined') window.faye = faye;
source: https://github.com/faye/faye/blob/master/javascript/faye.js#l143
if module not undefined(meaning defined) module.exports set object, if not, window.faye set.
if use debugger , set breakpoint on line module actually defined, why? qunit global helper method!
why faye this? guess because can run in nodejs environment (you can read more module.exports here).
see have 2 possible solutions:
- require faye before qunit.
- patch faye ignore existence of module in window.
i've encountered same behavior while using teaspoon qunit.
making teaspoon require faye before qunit seems bad idea , in ugly hack.
i've ended patching faye make skip module check, not beautiful either, believe reasonable.
Comments
Post a Comment