首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Cypress:柏树插件快照在Cypress 10中支持吗?

Cypress:柏树插件快照在Cypress 10中支持吗?
EN

Stack Overflow用户
提问于 2022-08-11 07:42:13
回答 1查看 635关注 0票数 -1

当我试图运行任何我的规范文件时,我会得到这个错误。以前起作用了。我是不是错过了一步?如何将路径标记为外部路径?

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

e2e.js

代码语言:javascript
运行
复制
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。就像一个无穷无尽的循环。

编辑的againThis是终端的视图。如何使用"platform:'node'“?

(再次编辑)

EN

回答 1

Stack Overflow用户

发布于 2022-08-11 10:30:41

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

这是文件

cypress.config.js

代码语言:javascript
运行
复制
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"
      }
    }
  },
});

cypress/support/e2e/js

代码语言:javascript
运行
复制
import './commands'
import 'cypress-plugin-snapshots/commands';

测试

代码语言:javascript
运行
复制
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"
      });
  })
})
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73317013

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档