How to resolve the issue > Cannot read properties of undefined (reading 'native') with log4js implementation in cypress?

549 Views Asked by At
  1. JSON data in json file:

    { "appenders": { "out": {"type": "console", "layout": { "type": "coloured" } }, "app": {"type": "dateFile", "filename": "cypress-logs/logger/info.log", "maxLogSize": 10485760, "layout": {"type":"pattern", "pattern":"[%d{dd-MM-yyyy hh:mm:ss}] [%p] - %m"} } }, "categories": { "default": { "appenders": ["out", "app"], "level": "info" } } }

  2. .js file code:


"use strict";

function log4js_logger() {
    var log4js = require("log4js");  //importing log4js
    log4js.configure("cypress/fixtures/log4js.json");  //loading the json data here
    var logs = log4js.getLogger();
    //logs.info("Logger has implemented !!")
    return logs; 
}

module.exports = {log4js_logger}
  1. js file where I'm using this logger.info: ---------------------------------------------
"use strict";
var logGenerator = require("../generic_utils/logger")
var logger = logGenerator.log4js_logger()


-----some js functions ---------------------------
-----using logger.info() within those functions---

Error when running cypress test:

An uncaught error was detected outside of a test: TypeError: The following error originated from your test code, not from Cypress.

Cannot read properties of undefined (reading 'native')

When Cypress detects uncaught errors originating from your test code it will automatically fail the current test.

Cypress could not associate this error to any specific test.

We dynamically generated a new test to display this failure. at ./node_modules/streamroller/node_modules/fs-extra/lib/fs/index.js (https://mcmp-cd2-int-testfra-apiauto.multicloud-ibm.com/__cypress/tests?p=cypress\e2e\common_inventory\aws\awsInventoryResourceDetails_cy.js:49841:24) at webpack_require (https://mcmp-cd2-int-testfra-apiauto.multicloud-ibm.com/__cypress/tests?p=cypress\e2e\common_inventory\aws\awsInventoryResourceDetails_cy.js:20:30) at ./node_modules/streamroller/node_modules/fs-extra/lib/index.js (https://mcmp-cd2-int-testfra-apiauto.multicloud-ibm.com/__cypress/tests?p=cypress\e2e\common_inventory\aws\awsInventoryResourceDetails_cy.js:49861:3) at webpack_require (https://mcmp-cd2-int-testfra-apiauto.multicloud-ibm.com/__cypress/tests?p=cypress\e2e\common_inventory\aws\awsInventoryResourceDetails_cy.js:20:30) at Object.eval (https://mcmp-cd2-int-testfra-apiauto.multicloud-ibm.com/__cypress/tests?p=cypress\e2e\common_inventory\aws\awsInventoryResourceDetails_cy.js:48187:12) at ./node_modules/streamroller/lib/RollingFileWriteStream.js (https://mcmp-cd2-int-testfra-apiauto.multicloud-ibm.com/__cypress/tests?p=cypress\e2e\common_inventory\aws\awsInventoryResourceDetails_cy.js:48525:30) at webpack_require (https://mcmp-cd2-int-testfra-apiauto.multicloud-ibm.com/__cypress/tests?p=cypress\e2e\common_inventory\aws\awsInventoryResourceDetails_cy.js:20:30) at ./node_modules/streamroller/lib/index.js (https://mcmp-cd2-int-testfra-apiauto.multicloud-ibm.com/__cypress/tests?p=cypress\e2e\common_inventory\aws\awsInventoryResourceDetails_cy.js:48694:27) at webpack_require (https://mcmp-cd2-int-testfra-apiauto.multicloud-ibm.com/__cypress/tests?p=cypress\e2e\common_inventory\aws\awsInventoryResourceDetails_cy.js:20:30) at Object.eval (https://mcmp-cd2-int-testfra-apiauto.multicloud-ibm.com/__cypress/tests?p=cypress\e2e\common_inventory\aws\awsInventoryResourceDetails_cy.js:44945:17)

Observation:

when I'm running js file with node command where log4js code is present, It is working fine but giving above error when running the cypress test

0

There are 0 best solutions below