Seems to me like a clean way, but if there's a more natural way, do let me know.
Currently there are the following changes where we differentiate between browser and NodeJS:
creating a runtime uses the process.env, this is however not available in browser (and it is empty using the shim pacakge), so here we opt to assume that the env variables are available under window.testground.env, which are to be injected by the user of the js sdk in the browser;
for the logging we currently also create a file on the local FS (the output log file?), this is not possible in browser, so I just disable that single output, other outputs do still function;
This is just the beginning though, I imagine there is even more we can do and want to do if native browser support for sdk-js is what we want. My current aim is to make it as easy to use as in NodeJS, meaning that the code can just be used and it will pull all it needs in the background (e.g. env variables).
Things to keep in mind...
for now we still need to polyfill a lot when web-packing, e.g. this is what I have for a testground plan in my webpack config file:
Could be great if out of the box, the sdk-js already does a lot of that for us, or ensures that what it uses is more cross-platform and thus does not need to be shimmed?
I am no expert of this library, so there might be even more places where we need to add some different logic for clean browser support. Please do point me to these locations if you know of any.
Finally we might also want to add some documentation on pointers for some gotcha's, hints, etc. All related to usage in browser.
I am by far no NodeJS expert, so please do help me adapt to this culture where you see fit.
With this PR I distinguish in some first starter locations between the browser and node environment. Currently I do this using
process.title
:ps
(see: https://nodejs.org/api/process.html#processtitle)process
shim package it sets this tobrowser
as the title: https://github.com/defunctzombie/node-process/blob/master/browser.js#L155Seems to me like a clean way, but if there's a more natural way, do let me know.
Currently there are the following changes where we differentiate between browser and NodeJS:
process.env
, this is however not available in browser (and it is empty using the shim pacakge), so here we opt to assume that the env variables are available underwindow.testground.env
, which are to be injected by the user of the js sdk in the browser;This is just the beginning though, I imagine there is even more we can do and want to do if native browser support for sdk-js is what we want. My current aim is to make it as easy to use as in NodeJS, meaning that the code can just be used and it will pull all it needs in the background (e.g. env variables).
Things to keep in mind...
Could be great if out of the box, the sdk-js already does a lot of that for us, or ensures that what it uses is more cross-platform and thus does not need to be shimmed?
Finally we might also want to add some documentation on pointers for some gotcha's, hints, etc. All related to usage in browser.