kirbysayshi / vash

Vash, the 60 billion double-dollar template-maker. Razor syntax, for JavaScript templates
Other
524 stars 60 forks source link

Fix render problem when running Jest #128

Closed JohanObrink closed 5 years ago

JohanObrink commented 5 years ago

Layout used a "hacky guard" to prevent non-nodejs erroring by checking for the existance of window. In Jest this breaks since window is polyfilled using jsdom. The new "hacky guard" is checking for global not being undefined.

Also ran npm audit fix to upgrade a dependency with an identified vulnerability.

kirbysayshi commented 5 years ago

@JohanObrink thanks for the PR! I'm curious, since I haven't used vash with jest before: was an error being thrown?

kirbysayshi commented 5 years ago

published as 0.12.5!

JohanObrink commented 5 years ago

@kirbysayshi No worries :)

It threw an error in lib/helpers/layout.js on row 51 saying cannot call function "normalize" of undefined. This is because of path only being required if window is undefined. Jest sets global.window to an instance of jsdom :/

You can try it out by forking https://github.com/JobtechSwe/mydata-operator and running the tests against version 0.12.4

kirbysayshi commented 5 years ago

Ok, that makes sense. Thanks for explaining! I haven't used jest for server-side tests (and of course this code was written before jest was really a huge thing haha).

JohanObrink commented 5 years ago

Yeah... Jest is good since they run on a lot of platforms. Their assumptions do clash with the assumptions of a lot of Node libs though. Vash is far from the only lib that uses the existance of window to determine the runtime environment :(