【问题标题】:Cypress: Is cypress-plugin-snapshots supported in Cypress 10?Cypress:Cypress 10 是否支持 cypress-plugin-snapshots?
【发布时间】:2022-11-19 11:40:55
【问题描述】:

当我尝试运行我的任何规格文件时出现此错误。它以前工作过。我在这里错过了一步吗?如何将路径标记为外部路径?

我删除了包含敏感信息的部分图像。

e2e.js

require('cypress-plugin-tab')
import './commands'

const dayjs = require('dayjs')
Cypress.dayjs = dayjs

import 'cypress-plugin-snapshots/commands'; 

(编辑)

我试图再次重新安装该软件包,但我现在收到此错误。当我尝试npm install --force crypto时,我返回了这个错误,而且我还必须执行npm install path。这就像一个无限循环。

再次编辑这是终端的视图。我如何使用“平台:'节点'”?

(再次编辑)

【问题讨论】:

  • 尝试将 import 语句移动到文件的顶部。通常你会收到一个警告。 (假设您检查过它实际上已安装?)。此外,将另一个导入放在 require('cypress-plugin-tab') 上方 - 导入应全部位于其他代码上方。
  • 嗨@Fody 我又重新安装了,但我现在遇到了加密错误。当我尝试 npm install crypto 时,我返回了这个错误。我要循环了:/
  • 我会试试看,也需要使用类似的东西。
  • 非常感谢@Fody!期待好消息!交叉手指

标签: cypress visual-testing


【解决方案1】:

我采用了默认的 Cypress 项目,安装并运行了 cypress-plugin-snapshots 但遗憾的是它工作正常。

这是文件

赛普拉斯.config.js

const { defineConfig } = require("cypress");
const { initPlugin } = require('cypress-plugin-snapshots/plugin');

module.exports = defineConfig({
  e2e: {
    setupNodeEvents(on, config) {
      initPlugin(on, config);     // this is cypress/plugins/index.js in Cypress v9
      return config;
    },
    excludeSpecPattern: [        // this is "ignoreTestFiles" in Cypress v9
      "**/__snapshots__/*",
      "**/__image_snapshots__/*" 
    ],
    "env": {      // just pasted everything from the docs here
      "cypress-plugin-snapshots": {
        "autoCleanUp": false,            // Automatically remove snapshots that are not used by test
        "autopassNewSnapshots": true,    // Automatically save & pass new/non-existing snapshots
        "diffLines": 3,                  // How many lines to include in the diff modal
        "excludeFields": [],             // Array of fieldnames that should be excluded from snapshot
        "ignoreExtraArrayItems": false,  // Ignore if there are extra array items in result
        "ignoreExtraFields": false,      // Ignore extra fields that are not in `snapshot`
        "normalizeJson": true,           // Alphabetically sort keys in JSON
        "prettier": true,                // Enable `prettier` for formatting HTML before comparison
        "imageConfig": {
          "createDiffImage": true,       // Should a "diff image" be created, can be disabled for performance
          "resizeDevicePixelRatio": true,// Resize image to base resolution when Cypress is running on high DPI screen, `cypress run` always runs on base resolution
          "threshold": 0.01,             // Amount in pixels or percentage before snapshot image is invalid
          "thresholdType": "percent"     // Can be either "pixels" or "percent"
        },
        "screenshotConfig": {            // See https://docs.cypress.io/api/commands/screenshot.html#Arguments
          "blackout": [],
          "capture": "fullPage",
          "clip": null,
          "disableTimersAndAnimations": true,
          "log": false,
          "scale": false,
          "timeout": 30000
        },
        "serverEnabled": true,           // Enable "update snapshot" server and button in diff modal
        "serverHost": "localhost",       // Hostname for "update snapshot server"
        "serverPort": 2121,              // Port number for  "update snapshot server"
        "updateSnapshots": false,        // Automatically update snapshots, useful if you have lots of changes
        "backgroundBlend": "difference"  // background-blend-mode for diff image, useful to switch to "overlay"
      }
    }
  },
});

赛普拉斯/支持/e2e/js

import './commands'
import 'cypress-plugin-snapshots/commands';

测试

describe('empty spec', () => {
  it('passes', () => {
    cy.visit('https://example.cypress.io')
      .then(() => {
        cy.get('div').toMatchSnapshot();  // 1st run - logs "update snapshot"
                                          // 2nd run - logs "snapshots match"
      });
  })
})

【讨论】:

  • 它与黄瓜一起运行吗?
  • 对于码头工人?我再次尝试但仍然收到错误:(
  • 我尝试逐步安装并打开 npx cypress。每当我添加 import 'cypress-plugin-snapshots/commands' 时都会发生此错误;在 e2e.js 中。 npm install 和 cypress.config.js 中的所有其他内容都可以
  • 嗨@Fody 我们如何使用“平台:'节点'”?我编辑了问题并添加了终端的屏幕截图。是因为esbuild吗?目前我们正在使用“esbuild”:“^0.14.51”。
  • 是的,看起来 esbuild 预处理器不适合cypress-plugin-snapshots。我也尝试了其他一些黄瓜配置,到目前为止没有任何效果。
【解决方案2】:

我将为我的项目编写快照自动化测试。并且正在寻找快照插件。那么这个线程的结果是什么?不过我不会在我的项目中使用黄瓜

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-07-30
  • 2019-02-19
  • 1970-01-01
  • 2012-03-25
  • 1970-01-01
  • 2017-03-12
  • 1970-01-01
相关资源
最近更新 更多