加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

如何在CI中运行cypress之前提供角度cli应用程序?

发布时间:2020-12-17 06:55:12 所属栏目:安全 来源:网络整理
导读:我正在尝试将赛普拉斯与Angular(v.5)CLI应用程序一起使用. 在本地运行时测试工作正常,因为在这里我可以在运行cypress测试之前启动serve命令. 我尝试按照文档here, 但是这些命令似乎都没有起作用. 我尝试了varioues组合,看起来像这样: "cypress:run:report":
我正在尝试将赛普拉斯与Angular(v.5)CLI应用程序一起使用.

在本地运行时测试工作正常,因为在这里我可以在运行cypress测试之前启动serve命令.

我尝试按照文档here,
但是这些命令似乎都没有起作用.

我尝试了varioues组合,看起来像这样:

"cypress:run:report": "./node_modules/.bin/cypress run --record --key <key>","cypress:run:ci": "start-server-and-test serve:dev http://localhost:4200 cypress:run:report","cypress:run:ci2": "npm run -s serve:dev & npm run -s cypress:run:report",

提前致谢.

解决方法

在尝试解决这个问题几个小时后,我使用 Cypress Module API开发了一个解决方案.

的package.json

"cypress:run:ci": "node ng-serve-and-run-cypress.js",

NG-发球和运行柏树

'use strict';

const cypress = require('cypress');
const { spawn } = require('child_process');
const child = spawn('ng',['serve']);

// On error exit,and print
child.on('error',(err) => process.exit(1));
child.stderr.on('data',(data) => console.log(data.toString()));
// On exit,print exit code
child.on('exit',(code,signal) => console.log(`Child exitting with code ${code}`));

child.stdout.on('data',(data) => {
    const asString = data.toString();
    // Log the output to inform CI/User
    console.log(asString);
    if (asString.includes('webpack: Compiled successfully.')) {
        cypress.run({})
        .then((results) => {
            const errorCode = (results.failures >= 1) ? 1 : 0;
            child.kill();
            // When cypress is done running the tests,exit with errorCode from above.
            process.exit(errorCode);
        })
        .catch((err) => {
            child.kill();
            // If cypress hit's an error,exit with code 1
            process.exit(1);
        })
    }
});

如果您对更多细节感兴趣,请在此处发布.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读