Use case
This is a Cypress E2E test coded with JS and I'm trying to compare pre-production and production sitemap URL contents in order to find the differences. I have two data sets (fixture) one for production and the other for test env.
Code snippet:
let compareUrlsBetween = (prodSitemapUrls, testEnvSitemapUrls) => { const pathFirstEnv = new Set(JSON.parse(prodSitemapUrls).map(url => (new URL(url)).pathname)) const pathSecondEnv = new Set(JSON.parse(testEnvSitemapUrls).map(url => (new URL(url)).pathname)) const diff = new Set(pathFirstEnv); for (const path of pathSecondEnv) { diff.delete(path); } return diff } // Check for differences if (compareUrlsBetween.length > 0) { let titi = typeof(compareUrlsBetween(prodSitemapUrls, testEnvSitemapUrls)) console.log(titi) cy.log('text : ' , compareUrlsBetween (prodSitemapUrls, testEnvSitemapUrls)) // Returns null //console.log(compareUrlsBetween(prodSitemapUrls, testEnvSitemapUrls)) //console.log('Production and test env sitemap urls are not ISO, ' + 'Here are the differences : ' , compareUrlsBetween (prodSitemapUrls, testEnvSitemapUrls)) //throw new Error() } else { expect(prodSitemapUrls).to.eq(testEnvSitemapUrls) } Test goal & the problem
Test goal is to fail the test in cas of diff between these two fixtures (.xml), throw a new error and show the diff as normal log (cy.log()). I've already tried multiple solutions like JSON.stringify(), data type conversion etc. but none of them solved my case.
Log I observe at this moment : logtext : , {}
PS: the other type of logs like console.log() or console.table() are working perfectly fine
Any help is much appreciated.
{}is clearly notnullcy.log('text : ' , [...compareUrlsBetween (prodSitemapUrls, testEnvSitemapUrls)])?