正如标题所述,每次更改代码时,都必须使用赛普拉斯测试运行器来查看结果。但是按照说明,它应该是自动重新加载并实时显示结果。
操作系统:Windows 10 Chrome:版本78.0.3904.70
答案 0 :(得分:0)
根据您是否有构建步骤,这里有两种解决方案。
如果没有构建步骤,那么这很容易:
在您的cypress/plugins/index.js
中:
rerun
事件。设置chokidar(或类似的)观察程序,侦听文件更改,然后重新运行规范。
// (1) setup to obtain file handles
// ------------------------------------------------------
let openFiles = [];
module.exports = ( on ) => {
on('file:preprocessor', file => {
if (
/\.spec\.js/.test(file.filePath) &&
!openFiles.find(f => f.filePath === file.filePath)
) {
openFiles.push(file);
file.on('close', () => {
openFiles = openFiles.filter(f => f.filePath !== file.filePath);
});
}
// tells cypress to not compile the file. If you normally
// compile your spec or support files, then instead of this line,
// return whatever you do for compilation
return file.filePath;
});
on('before:browser:launch', () => {
openFiles = [];
});
};
// (2) watching and re-running logic
// ------------------------------------------------------
chokidar.watch([ /* paths/to/watch */ ])
.on( "change", () => rerunTests());
function rerunTests () {
// https://github.com/cypress-io/cypress/issues/3614
const file = openFiles[0];
if ( file ) file.emit('rerun');
}
如果您有构建步骤,则工作流程将涉及更多。我将不介绍实现细节,而只是概述:
did-compile
事件或类似事件。cypress/plugins/index.js
中的逻辑与以前的解决方案基本相同,但是您将订阅IPC服务器的did-compile
事件,而不是chokidar监视程序,并在事件为发出。有关更多信息,请参阅Preprocessors API和cypress-io/cypress-watch-preprocessor。