使用案例
这是一个用 JS 编码的 Cypress E2E 测试,我正在尝试比较预生产和生产站点地图 URL 内容,以找到差异。我有两个数据集(夹具),一个用于生产,另一个用于测试环境。
代码片段:
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 …Run Code Online (Sandbox Code Playgroud)