javascriptnode.jscypressunzipcypress-task

unzipping the file using cypress


enter image description hereI need to unzip the file using 'unzipping' whereas I am using the below code to do the same but it is partially unzipping but it is throwing an Invalid path error (as path contains special character *).please help me to fix it

let path = 'cypress/downloads/'
let file = '910-00001.1-20220419-1843.zip'

describe('example unzip', () => {
  it(' test', () => {
    cy.task('unzipping', { path, file })
    })





//task code (Added it into plugins --> index.js)

const unzipping = require('./unzipping')

module.exports = (on, config) => {
    on('task', {
        'unzipping': unzipping.unzip,
    })
}

// ./unzipping file (created a file named unzipping.js inside plugin folder)

const decompress = require('decompress');

const unzip = ({ path, file }) => decompress(path + file, path + 'unzip/' + file.replace('.zip', ''))

module.exports = {
    unzip,
}

Solution

  • So, I tried all your code you gave above, and it worked perfectly.

    The only thing I can think if is the contents of the zip is the problem. In my test I made a simple zip with two text files 1.txt and 2.txt, then running the test, found them in the folder /cypress/downloads/unzip/910-00001.1-20220419-1843.

    I suggest you do the same with a dummy zip, if the code works then look at the contents of 910-00001.1-20220419-1843.zip.