Closed carlobeltrame closed 4 years ago
"Workaround" is to use the REST API with cy.request
, instead of using this package:
cy.request('PUT', 'e2e-mock:1080', {...})
A PR to fix the check to distinguish browser from node.js environment would be gratefully appreciated. Are you able to provide such a PR or suggest some good code to implement this?
If you are fine with adding a single dependency, it could be done using the browser-or-node package. I could submit a PR for that.
If you want to do it manually, without a dependency, I could replicate the logic from the package, but I'm not enough of an expert on node.js code to maintain that piece of code.
Sorry for the slow response, yes your suggestion of using the browser-or-node package sounds good.
Even though the require('fs')
never runs, webpack will still pick it up for bundling, and thus webpack will error because there's no fs
module that can be bundled for browser usage. For this reason I think we need to add this to package.json
:
"browser": {
"fs": false
}
As per https://github.com/pugjs/pug-loader/issues/8#issuecomment-328331541.
Until then, we can workaround this with the following webpack config:
node: {
fs: 'empty',
},
Describe the issue When I try to use mockserver-client-node in the browser, I get the error:
This is because the check to distinguish browser from node.js environment does not consider browser bundle build systems (i.e., using require or import in browser-based environments), which is common practice by now.
What you are trying to do I want to use mockserver in Cypress.io end-to-end tests. To dynamically set my mocks depending on the tests I am running, I want to use mockserver-client-node. In Cypress, we can easily require or import CommonJS modules which are then transpiled to run in the browser, but we cannot easily add a script tag to the page.
MockServer version latest (5.11.1)
To Reproduce Steps to reproduce the issue:
Expected behaviour I expected the check in https://github.com/mock-server/mockserver-client-node/blob/master/mockServerClient.js#L27 to detect that I am running in a browser and use the XHR-based makeRequest function instead of
require('./sendRequest').sendRequest(tls, caCertPemFilePath)
.MockServer Log Not relevant, as it doesn't get far enough to talk to MockServer