我想用柏树审计做一个灯塔测试,但是在做完他们在https://www.npmjs.com/package/cypress-audit上说的所有事情之后,它就不起作用了。我可以在cypress/support/commands.js中使用"cy.lighthouse( )“,但不能在扩展名为.spec.ts或.ts的文件中使用(在'cy &EventEmitter‘..ts(2339)”错误“类型上不存在”属性’灯塔“。我已经试图在互联网上找到任何解决方案,但都没有效果。
package.json:
{
"name": "XXXX",
"version": "0.0.1",
"description": "",
"scripts": {
"start_cypress": "npx cypress open",
"install_dependencies": "npm install"
},
"author": "",
"devDependencies": {
"babel-core": "^6.26.0",
"babel-loader": "^7.1.2",
"babel-preset-env": "^1.6.0",
"babel-preset-stage-3": "^6.24.1",
"cross-env": "^5.0.5",
"cypress": "^9.3.1",
"cypress-audit": "^1.1.0",
"typescript": "^4.5.4",
"webpack": "^5.66.0",
"webpack-dev-server": "^4.7.3"
}
}cypress/plugins/index.js:
/// <reference types="cypress" />
/**
* @type {Cypress.PluginConfig}
*/
const { lighthouse, pa11y, prepareAudit } = require("cypress-audit");
module.exports = (on, config) => {
on("before:browser:launch", (browser = {}, launchOptions) => {
prepareAudit(launchOptions);
});
on("task", {
lighthouse: lighthouse(), // calling the function is important
pa11y: pa11y(), // calling the function is important
});
}cypress/support/commands.js:
import 'cypress-audit/commands';CypressAudit.spec.ts:
describe('Audits', () => {
beforeEach(() => {
cy.visit('/');
});
it("should pass the audits", function () {
cy.lighthouse();
cy.pa11y();
});
});发布于 2022-01-31 07:55:46
结果,我想在cy.lighthouse()中使用“file.spec.ts ()”(我使用的是类型记录),在检查了示例中的所有内容之后,我注意到示例是在file.spec.js中。事实证明,即使柏树使用的是类型记录,这个命令也只能在javascript中工作。
发布于 2022-01-26 11:12:16
有一些类型的防御,在柏树审计包,应该是启动。也许是ts和js文件的混合?
尝试将这些添加到/cypress/support/index.ts中
interface Chainable<Subject> {
/**
* Runs a lighthouse audit
* @example
* cy.lighthouse(thresholds,opts,config)
*/
lighthouse(thresholds?: LighthouseThresholds, opts?: any, config?: any);
/**
* Runs a pa11y audit
* @example
* cy.pa11y(opts)
*/
pa11y(opts?: Options);
}https://stackoverflow.com/questions/70862103
复制相似问题