zipcypress

I need to zip a report folder in cypress


I am working on uploading the test results to Xray using JIRA API. I am already generating the cucumber-html report in my project directory and could call JIRA upload API for uploading single file. However, I need to upload the whole html report for which I need to zip report folder to upload via API. I tried couple of available solution with javascript to zip my report folder at project directory but none of them are helping. can anyone help to solve this problem?

I need to store the zipped folder in the same directory and without browser


Solution

  • You probably just add a task to perform the zip.

    For example see zip-lib

    on('task', {
      zipFile({pathToFile, pathToZip}) {
        const zl = require("zip-lib");
        zl.archiveFile(pathToFile, pathToZip)
      },
      zipFolder({pathToFolder, pathToZip}) {
        const zl = require("zip-lib");
        zl.archiveFolder(pathToFile, pathToZip)
      }
    })
    

    Using an object to pass parameters since task only takes one argument.

    after(() => {
      cy.task('zipFile', {
        pathToFile: 'path/to/file.txt', 
        pathToZip: 'path/to/target.zip'
      })
    })