skip to Main Content

I have this hook in my 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()
            })
...

The touch command works fine, but the jre don’t produce the junitreport.xml file or any other output.

If I run npx jrm ./cypress/reports/junitreport.xml ./cypress/reports/junit/*.xml on the command line it works just fine.

I have also tried with ./node_modules/.bin/jre instead of npx jrm

as well as node ./node_modules/.bin/jre but to no avail.

What am I missing here?

2

Answers


  1. Chosen as BEST ANSWER

    Using the execSync() instead of exec() works:

                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()
                })
    

  2. If you use execSync() you can drop the async/await decoration.

    In the original code, exec() returns no promise, so await has no effect. It uses callbacks to respond.

    child_process.exec(command[, options][, callback])

    You could use util.promisify to make exec() work in the context of after:run.

    const util = require('util');
    
    on('after:run', async () => {
      await util.promisify(exec(''npx jrm ...'))
      ...
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search