【发布时间】:2022-08-17 10:06:50
【问题描述】:
我尝试在 Cypress 版本 10 中实现 Node 插件,但我做不到。
https://www.npmjs.com/package/music-metadata-browser#fetchurl-function
-
安装完成:
npm install --save-dev music-metadata-browsernpm install --save-dev util -
在 plugin/index.js 中添加了以下行
const musicMetadata = require(\'music-metadata-browser\'); const util = require(\'util\'); module.exports = (on, config) => { require(\'@cypress/code-coverage/task\')(on, config); on(\'task\', { validateAudioFormat(audioTrackUrl) { return new Promise((resolve, reject) => { musicMetadata.parseFile(audioTrackUrl, (err, data) => { if (err) { return reject(err); } return resolve(data); }); }); }, }); };- 在 e2e/validateFile.cy.js 中添加了以下代码
describe(\'Parsing File\', () => { it(\'Validating Audio File\', () => { const audioURL = \'cypress/fixtures/media/Patrikios.mp3\'; console.log(\'url: \' + audioURL); cy.task(\'validateAudioFormat\', audioURL).then(data => { const allData = Object.values(data); console.log(\'All data: \' + allData); }); /****** cy.on(\'validateAudioFormat\', (url) => { async () => { const metadata = await mm.fetchFromUrl(url); console.log(\'url: \' + url); console.log(util.inspect(metadata, { showHidden: false, depth: null })); }; }); *****/ }); });错误:
CypressError: `cy.task(\'validateAudioFormat\')` failed with the following error: The task \'validateAudioFormat\' was not handled in the setupNodeEvents method. The following tasks are registered: resetCoverage, combineCoverage, coverageReport Fix this in your setupNodeEvents method here: /opt/lampp/htdocs/project/cypress.config.js注释块错误:
taskreadAudioFiles, cypress/fixtures/media/audios/valid/Beyond_Patrick_Patrikios.mp3 CypressError cy.task(\'readAudioFiles\') timed out after waiting 60000ms任何人都可以在这种情况下提供帮助吗?
谢谢!
标签: npm cypress node-modules cypress-component-test-runner cypress-configuration