protocolbuffers / protobuf-javascript

BSD 3-Clause "New" or "Revised" License
351 stars 67 forks source link

Generated output is incompatible with Jest (again) #149

Open nex3 opened 1 year ago

nex3 commented 1 year ago

This is the same issue as https://github.com/protocolbuffers/protobuf/issues/9152, which was notionally fixed in https://github.com/protocolbuffers/protobuf/pull/9156. However, it seems that as of 3.20.3 the output is (still? again?) the Jest-incompatible

var global = (function() { return this || window || global || self || Function('return this')(); }).call(null);

For now I've rolled back to 3.11.2 which emits the compatible

var global = Function('return this')();

but this isn't a great long-term solution.

dibenede commented 1 year ago

@nex3 Do you happen to know what aspect of the generated code is incompatible with Jest? I haven't used the framework before.

dibenede commented 1 year ago

Ah, it was right in front of me: it looks like window is the immediate issue.

lukesandberg commented 1 year ago

querying for globalThis first is probably reasonable typeof window != "undefined" && window would also work i suppose