Closed sdetweil closed 2 weeks ago
from tests/e2e/helpers/global-setup.js
:
exports.getDocument = () => {
return new Promise((resolve) => {
const url = `http://${config.address || "localhost"}:${config.port || "8080"}`;
jsdom.JSDOM.fromURL(url, { resources: "usable", runScripts: "dangerously" }).then((dom) => {
dom.window.name = "jsdom";
global.window = dom.window;
// Following fixes `navigator is not defined` errors in e2e tests, found here
// https://www.appsloveworld.com/reactjs/100/37/mocha-react-navigator-is-not-defined
global.navigator = {
useragent: "node.js"
};
dom.window.fetch = fetch;
dom.window.onload = () => {
global.document = dom.window.document;
resolve();
};
});
});
};
we are setting here dom.window.name = "jsdom";
so this could maybe used in the e2e-tests.
I meant the code running inside MM.. a module
to test the refreshable compliments remote file and have it locally we need to 'change' the configured url on the fly to it will pull a different file. but i have another way... if the url starts with tests and there is another parm (url2...)
I meant the code running inside MM.. a module
and I meant you maybe can use
if (global.window.name === "jsdom")` {
console.log("running in test");
}
ok, thx
if (global.window.name === "jsdom")` {
console.log("running in test");
}
this didn't work... global not defined inside the module.register for compliments the / global global / didn't work either (as it did for Cron loaded via getScripts)
In the browser environment, global variables are attached to the
windowobject.
so for code running in browser omit the global
:
if (window.name === "jsdom")` {
console.log("running in test");
}
hm.. doesn't fail, but doesn't work
// in test mode only
if (window.name === "jsdom") {
// check for (undocumented) remote file2 to change test new load
if(this.config.remoteFile2!== null && this.config.remoteFileRefreshInterval!==null){
console.log("running in test");
this.config.remoteFile=this.config.remoteFile2
}
}
for changing the remote file to prove that the cycle and fetch work , only wanted to fake a new file in test mode if I comment out the if jsdom, then testcase works. but fails with it enabled.
in test and in non-test window.name is empty console.log("name='+window.name+"'") results in name=''
this is in the getDom() callback
also empty outside the module register
console.log("window name='"+window.name+"'")
const compliments_test_mode=(window.name=='jsdom')?true:false
Module.register("compliments", {
code in pr #3630
in helper side one can test the process.env.JEST_WORKER_ID not available in module side
I am helping user with new compliments parm test