运行节点脚本时出现 Cypress 配置挂钩问题

问题描述 投票:0回答:1

我的

cypress.config.ts
里有这个钩子:

...
            on('after:run', async () => {
                console.log('override after:run')
                await exec('touch ./cypress/reports/test.txt')
                await exec(
                    'npx jrm ./cypress/reports/junitreport.xml ./cypress/reports/junit/*.xml'
                )

                await afterRunHook()
            })
...

touch
命令工作正常,但
jre
不会生成
junitreport.xml
文件或任何其他输出。

如果我在命令行上运行

npx jrm ./cypress/reports/junitreport.xml ./cypress/reports/junit/*.xml
,它就可以正常工作。

我也尝试过用

./node_modules/.bin/jre
而不是
npx jrm

以及

node ./node_modules/.bin/jre
但无济于事。

我在这里缺少什么?

javascript node.js cypress
1个回答
0
投票

使用

execSync()
代替
exec()
有效:

            on('after:run', async () => {
                console.log('override after:run')
                await execSync(
                    'node ./node_modules/.bin/jrm ./cypress/reports/junitreport.xml ./cypress/reports/junit/*.xml > ./cypress/reports/jrm-log.txt 2>&1'
                )

                await afterRunHook()
            })
© www.soinside.com 2019 - 2024. All rights reserved.