当我试图运行任何我的规范文件时,我会得到这个错误。以前起作用了。我是不是错过了一步?如何将路径标记为外部路径?
我删除了包含敏感信息的部分图像。
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
。就像一个无穷无尽的循环。
编辑的againThis是终端的视图。如何使用"platform:'node'“?
(再次编辑)
发布于 2022-08-11 10:30:41
我采用了默认的Cypress项目,安装并运行了cypress-plugin-snapshots
,但遗憾的是,它工作正常。
这是文件
cypress.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"
}
}
},
});
cypress/support/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"
});
})
})
https://stackoverflow.com/questions/73317013
复制相似问题