How can I tell if the script is being executed via jsdom? I assumed it was node but wanted to be sure.
I'll need to look into this a bit more to verify if this is a jsdom issue or something related to node itself Thanks for the in-depth answer! Toran On Apr 25, 7:24 pm, Elijah Insua <[email protected]> wrote: > On Wed, Apr 25, 2012 at 11:28 AM, toranb <[email protected]> wrote: > > I've been using jasmine to unit test my javascript the last few > > months. I've been running these tests with node (v4) jsdom/jasmine- > > node/jasmine-jquery > > > Everything was fine until I had to upgrade from node v4 -I did a make > > install from the 6.11 build and noticed that I had to update jsdom. > > > jsdom and or jsdom + node seems to have changed how it views the > > "window" keyword. > > is this in the context of jsdom's script executor or node's? I'm assuming > the former, but that is still weird. The jsdom script context doesn't > define a 'global' variable. It is more likely that the string > representation of a window is incorrect. > > Here's how I came to that conclusion: > > Code: > > require('jsdom').env({ > html : "<html><head></head><body></body></html>", > src : "window.stringified = window + ''; window.typeofGlobal = typeof > global; window.keys = Object.keys(window)", > done : function(err, window) { > console.log('[jsdom context] window.stringified:', window.stringified, > '\n'); > console.log('[jsdom context] typeof global:', window.typeofGlobal, > '\n'); > console.log('[jsdom context] window.keys:', > JSON.stringify(window.keys), '\n'); > console.log('[node context] window === global: ' + (window === global), > '\n'); > } > > }); > > Output: > > tmp‣ node window-global.js > [jsdom context] window.stringified: [object global] > > [jsdom context] typeof global: undefined > > [jsdom context] window.keys: > ["location","addEventListener","removeEventListener","dispatchEvent","raise > ","setTimeout","setInterval","clearInterval","clearTimeout","__stopAllTimer > s","run","getGlobal","dispose","top","parent","self","frames","window","doc > ument","stringified","typeofGlobal","_length","length","close","getComputed > Style","console","navigator","XMLHttpRequest","name","innerWidth","innerHei > ght","outerWidth","outerHeight","pageXOffset","pageYOffset","screenX","scre > enY","screenLeft","screenTop","scrollX","scrollY","scrollTop","scrollLeft", > "alert","blur","confirm","createPopup","focus","moveBy","moveTo","open","pr > int","prompt","resizeBy","resizeTo","scroll","scrollBy","scrollTo","screen" > ,"Image","languageProcessors","resourceLoader","HTMLCollection","HTMLOption > sCollection","HTMLDocument","HTMLElement","HTMLFormElement","HTMLLinkElemen > t","HTMLMetaElement","HTMLHtmlElement","HTMLHeadElement","HTMLTitleElement" > ,"HTMLBaseElement","HTMLIsIndexElement","HTMLStyleElement","HTMLBodyElement > ","HTMLSelectElement","HTMLOptGroupElement","HTMLOptionElement","HTMLInputE > lement","HTMLTextAreaElement","HTMLButtonElement","HTMLLabelElement","HTMLF > ieldSetElement","HTMLLegendElement","HTMLUListElement","HTMLOListElement"," > HTMLDListElement","HTMLDirectoryElement","HTMLMenuElement","HTMLLIElement", > "HTMLDivElement","HTMLParagraphElement","HTMLHeadingElement","HTMLQuoteElem > ent","HTMLPreElement","HTMLBRElement","HTMLBaseFontElement","HTMLFontElemen > t","HTMLHRElement","HTMLModElement","HTMLAnchorElement","HTMLImageElement", > "HTMLObjectElement","HTMLParamElement","HTMLAppletElement","HTMLMapElement" > ,"HTMLAreaElement","HTMLScriptElement","HTMLTableElement","HTMLTableCaption > Element","HTMLTableColElement","HTMLTableSectionElement","HTMLTableRowEleme > nt","HTMLTableCellElement","HTMLFrameSetElement","HTMLFrameElement","HTMLIF > rameElement","_augmented","INVALID_STATE_ERR","SYNTAX_ERR","INVALID_MODIFIC > ATION_ERR","NAMESPACE_ERR","INVALID_ACCESS_ERR","StyleSheet","MediaList","C > SSStyleSheet","CSSRule","CSSStyleRule","CSSMediaRule","CSSImportRule","CSSS > tyleDeclaration","StyleSheetList","mapper","mapDOMNodes","visitTree","markT > reeReadonly","INDEX_SIZE_ERR","DOMSTRING_SIZE_ERR","HIERARCHY_REQUEST_ERR", > "WRONG_DOCUMENT_ERR","INVALID_CHARACTER_ERR","NO_DATA_ALLOWED_ERR","NO_MODI > FICATION_ALLOWED_ERR","NOT_FOUND_ERR","NOT_SUPPORTED_ERR","INUSE_ATTRIBUTE_ > ERR","exceptionMessages","DOMException","NodeList","DOMImplementation","Nod > e","NamedNodeMap","AttrNodeMap","NotationNodeMap","EntityNodeMap","Element" > ,"DocumentFragment","ProcessingInstruction","Document","CharacterData","Att > r","Text","Comment","CDATASection","DocumentType","Notation","Entity","Enti > tyReference"] > > [node context] window === global: false > > So as you can see above, the window object does have all of the expected > props/method and it is not the same as node's global object. > > I hope that helps, and if you do find a sidecase please report it > (https://github.com/tmpvar/jsdom/issues) > > Oh, and for future reference there is a mailing list for jsdom specific > issues/questions (http://groups.google.com/group/jsdom) > > -- Elijah -- Job Board: http://jobs.nodejs.org/ Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines You received this message because you are subscribed to the Google Groups "nodejs" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/nodejs?hl=en?hl=en
