How to use extractZip method in taiko

Best JavaScript code snippet using taiko

downloader.test.ts

Source:downloader.test.ts Github

copy

Full Screen

1import * as d from '../downloader';2import * as tool from '@actions/tool-cache';3import * as glob from '@actions/glob';4test('downloading zip with cache hit', async () => {5 const findInCache = jest.spyOn(tool, 'find').mockImplementation(() => 'cached folder');6 const download = jest.spyOn(tool, 'downloadTool');7 const extractZip = jest.spyOn(tool, 'extractZip');8 const extractTar = jest.spyOn(tool, 'extractTar');9 const extract7z = jest.spyOn(tool, 'extract7z');10 const putInCache = jest.spyOn(tool, 'cacheDir');11 const result = await d.materialize('URL.zip', { name: 'tool', version: '1.1', arch: '' });12 expect(findInCache).toHaveBeenCalledTimes(1);13 expect(findInCache).toHaveBeenCalledWith('tool', '1.1', '');14 expect(download).not.toHaveBeenCalled();15 expect(extractZip).not.toHaveBeenCalled();16 expect(extractTar).not.toHaveBeenCalled();17 expect(extract7z).not.toHaveBeenCalled();18 expect(putInCache).not.toHaveBeenCalled();19 expect(result).toBe('cached folder');20});21test('downloading zip with cache miss', async () => {22 const findInCache = jest.spyOn(tool, 'find').mockImplementation();23 const download = jest.spyOn(tool, 'downloadTool').mockImplementation(async () => 'tmp file');24 const extractZip = jest.spyOn(tool, 'extractZip').mockImplementation(async () => 'tmp folder');25 const extractTar = jest.spyOn(tool, 'extractTar');26 const extract7z = jest.spyOn(tool, 'extract7z');27 const putInCache = jest.spyOn(tool, 'cacheDir').mockImplementation(async () => 'cached folder');28 const result = await d.materialize('URL.zip', { name: 'tool', version: '1.1', arch: '' });29 expect(findInCache).toHaveBeenCalledTimes(1);30 expect(download).toHaveBeenCalledTimes(1);31 expect(download).toHaveBeenCalledWith('URL.zip');32 expect(extractZip).toHaveBeenCalledTimes(1);33 expect(extractZip).toHaveBeenCalledWith('tmp file');34 expect(extractTar).not.toHaveBeenCalled();35 expect(extract7z).not.toHaveBeenCalled();36 expect(putInCache).toHaveBeenCalledTimes(1);37 expect(putInCache).toHaveBeenCalledWith('tmp folder', 'tool', '1.1', '');38 expect(result).toBe('cached folder');39});40test('downloading zip without caching', async () => {41 const findInCache = jest.spyOn(tool, 'find').mockImplementation();42 const download = jest.spyOn(tool, 'downloadTool').mockImplementation(async () => 'tmp file');43 const extractZip = jest.spyOn(tool, 'extractZip').mockImplementation(async () => 'tmp folder');44 const extractTar = jest.spyOn(tool, 'extractTar');45 const extract7z = jest.spyOn(tool, 'extract7z');46 const putInCache = jest.spyOn(tool, 'cacheDir');47 const result = await d.materialize('URL.zip', { name: '', version: '', arch: '' });48 expect(findInCache).not.toHaveBeenCalled();49 expect(download).toHaveBeenCalledTimes(1);50 expect(download).toHaveBeenCalledWith('URL.zip');51 expect(extractZip).toHaveBeenCalledTimes(1);52 expect(extractZip).toHaveBeenCalledWith('tmp file');53 expect(extractTar).not.toHaveBeenCalled();54 expect(extract7z).not.toHaveBeenCalled();55 expect(putInCache).not.toHaveBeenCalled();56 expect(result).toBe('tmp folder');57});58test('downloading tar.bz2 with cache hit', async () => {59 const findInCache = jest.spyOn(tool, 'find').mockImplementation(() => 'cached folder');60 const download = jest.spyOn(tool, 'downloadTool');61 const extractZip = jest.spyOn(tool, 'extractZip');62 const extractTar = jest.spyOn(tool, 'extractTar');63 const extract7z = jest.spyOn(tool, 'extract7z');64 const putInCache = jest.spyOn(tool, 'cacheDir');65 const result = await d.materialize('URL.tar.bz2', { name: 'tool', version: '1.1', arch: '' });66 expect(findInCache).toHaveBeenCalledTimes(1);67 expect(findInCache).toHaveBeenCalledWith('tool', '1.1', '');68 expect(download).not.toHaveBeenCalled();69 expect(extractZip).not.toHaveBeenCalled();70 expect(extractTar).not.toHaveBeenCalled();71 expect(extract7z).not.toHaveBeenCalled();72 expect(putInCache).not.toHaveBeenCalled();73 expect(result).toBe('cached folder');74});75test('downloading tar.bz2 with cache miss', async () => {76 const findInCache = jest.spyOn(tool, 'find').mockImplementation();77 const download = jest.spyOn(tool, 'downloadTool').mockImplementation(async () => 'tmp file');78 const extractZip = jest.spyOn(tool, 'extractZip');79 const extractTar = jest.spyOn(tool, 'extractTar').mockImplementation(async () => 'tmp folder');80 const extract7z = jest.spyOn(tool, 'extract7z');81 const putInCache = jest.spyOn(tool, 'cacheDir').mockImplementation(async () => 'cached folder');82 const result = await d.materialize('URL.tar.bz2', { name: 'tool', version: '1.1', arch: '' });83 expect(findInCache).toHaveBeenCalledTimes(1);84 expect(download).toHaveBeenCalledTimes(1);85 expect(download).toHaveBeenCalledWith('URL.tar.bz2');86 expect(extractZip).not.toHaveBeenCalled();87 expect(extractTar).toHaveBeenCalledTimes(1);88 expect(extractTar).toHaveBeenCalledWith('tmp file', undefined, 'xj');89 expect(extract7z).not.toHaveBeenCalled();90 expect(putInCache).toHaveBeenCalledTimes(1);91 expect(putInCache).toHaveBeenCalledWith('tmp folder', 'tool', '1.1', '');92 expect(result).toBe('cached folder');93});94test('downloading tar.bz2 without caching', async () => {95 const findInCache = jest.spyOn(tool, 'find').mockImplementation();96 const download = jest.spyOn(tool, 'downloadTool').mockImplementation(async () => 'tmp file');97 const extractZip = jest.spyOn(tool, 'extractZip');98 const extractTar = jest.spyOn(tool, 'extractTar').mockImplementation(async () => 'tmp folder');99 const extract7z = jest.spyOn(tool, 'extract7z');100 const putInCache = jest.spyOn(tool, 'cacheDir');101 const result = await d.materialize('URL.tar.bz2', { name: '', version: '', arch: '' });102 expect(findInCache).not.toHaveBeenCalled();103 expect(download).toHaveBeenCalledTimes(1);104 expect(download).toHaveBeenCalledWith('URL.tar.bz2');105 expect(extractZip).not.toHaveBeenCalled();106 expect(extractTar).toHaveBeenCalledTimes(1);107 expect(extractTar).toHaveBeenCalledWith('tmp file', undefined, 'xj');108 expect(extract7z).not.toHaveBeenCalled();109 expect(putInCache).not.toHaveBeenCalled();110 expect(result).toBe('tmp folder');111});112test('downloading tar.gz with cache hit', async () => {113 const findInCache = jest.spyOn(tool, 'find').mockImplementation(() => 'cached folder');114 const download = jest.spyOn(tool, 'downloadTool');115 const extractZip = jest.spyOn(tool, 'extractZip');116 const extractTar = jest.spyOn(tool, 'extractTar');117 const extract7z = jest.spyOn(tool, 'extract7z');118 const putInCache = jest.spyOn(tool, 'cacheDir');119 const result = await d.materialize('URL.tar.gz', { name: 'tool', version: '1.1', arch: '' });120 expect(findInCache).toHaveBeenCalledTimes(1);121 expect(findInCache).toHaveBeenCalledWith('tool', '1.1', '');122 expect(download).not.toHaveBeenCalled();123 expect(extractZip).not.toHaveBeenCalled();124 expect(extractTar).not.toHaveBeenCalled();125 expect(extract7z).not.toHaveBeenCalled();126 expect(putInCache).not.toHaveBeenCalled();127 expect(result).toBe('cached folder');128});129test('downloading tar.gz with cache miss', async () => {130 const findInCache = jest.spyOn(tool, 'find').mockImplementation();131 const download = jest.spyOn(tool, 'downloadTool').mockImplementation(async () => 'tmp file');132 const extractZip = jest.spyOn(tool, 'extractZip');133 const extractTar = jest.spyOn(tool, 'extractTar').mockImplementation(async () => 'tmp folder');134 const extract7z = jest.spyOn(tool, 'extract7z');135 const putInCache = jest.spyOn(tool, 'cacheDir').mockImplementation(async () => 'cached folder');136 const result = await d.materialize('URL.tar.gz', { name: 'tool', version: '1.1', arch: '' });137 expect(findInCache).toHaveBeenCalledTimes(1);138 expect(download).toHaveBeenCalledTimes(1);139 expect(download).toHaveBeenCalledWith('URL.tar.gz');140 expect(extractZip).not.toHaveBeenCalled();141 expect(extractTar).toHaveBeenCalledTimes(1);142 expect(extractTar).toHaveBeenCalledWith('tmp file');143 expect(extract7z).not.toHaveBeenCalled();144 expect(putInCache).toHaveBeenCalledTimes(1);145 expect(putInCache).toHaveBeenCalledWith('tmp folder', 'tool', '1.1', '');146 expect(result).toBe('cached folder');147});148test('downloading tar.gz without caching', async () => {149 const findInCache = jest.spyOn(tool, 'find').mockImplementation();150 const download = jest.spyOn(tool, 'downloadTool').mockImplementation(async () => 'tmp file');151 const extractZip = jest.spyOn(tool, 'extractZip');152 const extractTar = jest.spyOn(tool, 'extractTar').mockImplementation(async () => 'tmp folder');153 const extract7z = jest.spyOn(tool, 'extract7z');154 const putInCache = jest.spyOn(tool, 'cacheDir');155 const result = await d.materialize('URL.tar.gz', { name: '', version: '', arch: '' });156 expect(findInCache).not.toHaveBeenCalled();157 expect(download).toHaveBeenCalledTimes(1);158 expect(download).toHaveBeenCalledWith('URL.tar.gz');159 expect(extractZip).not.toHaveBeenCalled();160 expect(extractTar).toHaveBeenCalledTimes(1);161 expect(extractTar).toHaveBeenCalledWith('tmp file');162 expect(extract7z).not.toHaveBeenCalled();163 expect(putInCache).not.toHaveBeenCalled();164 expect(result).toBe('tmp folder');165});166test('downloading 7z with cache hit', async () => {167 const findInCache = jest.spyOn(tool, 'find').mockImplementation(() => 'cached folder');168 const download = jest.spyOn(tool, 'downloadTool');169 const extractZip = jest.spyOn(tool, 'extractZip');170 const extractTar = jest.spyOn(tool, 'extractTar');171 const extract7z = jest.spyOn(tool, 'extract7z');172 const putInCache = jest.spyOn(tool, 'cacheDir');173 const result = await d.materialize('URL.7z', { name: 'tool', version: '1.1', arch: '' });174 expect(findInCache).toHaveBeenCalledTimes(1);175 expect(findInCache).toHaveBeenCalledWith('tool', '1.1', '');176 expect(download).not.toHaveBeenCalled();177 expect(extractZip).not.toHaveBeenCalled();178 expect(extractTar).not.toHaveBeenCalled();179 expect(extract7z).not.toHaveBeenCalled();180 expect(putInCache).not.toHaveBeenCalled();181 expect(result).toBe('cached folder');182});183test('downloading 7z with cache miss', async () => {184 const findInCache = jest.spyOn(tool, 'find').mockImplementation();185 const download = jest.spyOn(tool, 'downloadTool').mockImplementation(async () => 'tmp file');186 const extractZip = jest.spyOn(tool, 'extractZip');187 const extractTar = jest.spyOn(tool, 'extractTar');188 const extract7z = jest.spyOn(tool, 'extract7z').mockImplementation(async () => 'tmp folder');189 const putInCache = jest.spyOn(tool, 'cacheDir').mockImplementation(async () => 'cached folder');190 const result = await d.materialize('URL.7z', { name: 'tool', version: '1.1', arch: '' });191 expect(findInCache).toHaveBeenCalledTimes(1);192 expect(download).toHaveBeenCalledTimes(1);193 expect(download).toHaveBeenCalledWith('URL.7z');194 expect(extractZip).not.toHaveBeenCalled();195 expect(extractTar).not.toHaveBeenCalled();196 expect(extract7z).toHaveBeenCalledTimes(1);197 expect(extract7z).toHaveBeenCalledWith('tmp file');198 expect(putInCache).toHaveBeenCalledTimes(1);199 expect(putInCache).toHaveBeenCalledWith('tmp folder', 'tool', '1.1', '');200 expect(result).toBe('cached folder');201});202test('downloading 7z without caching', async () => {203 const findInCache = jest.spyOn(tool, 'find').mockImplementation();204 const download = jest.spyOn(tool, 'downloadTool');205 const extractZip = jest.spyOn(tool, 'extractZip');206 const extractTar = jest.spyOn(tool, 'extractTar');207 const extract7z = jest.spyOn(tool, 'extract7z').mockImplementation(async () => 'tmp folder');208 const putInCache = jest.spyOn(tool, 'cacheDir');209 const result = await d.materialize('URL.7z', { name: '', version: '', arch: '' });210 expect(findInCache).not.toHaveBeenCalled();211 expect(download).toHaveBeenCalledTimes(1);212 expect(download).toHaveBeenCalledWith('URL.7z');213 expect(extractZip).not.toHaveBeenCalled();214 expect(extractTar).not.toHaveBeenCalled();215 expect(extract7z).toHaveBeenCalledTimes(1);216 expect(extract7z).toHaveBeenCalledWith('tmp file');217 expect(putInCache).not.toHaveBeenCalled();218 expect(result).toBe('tmp folder');219});220test('finding subfolder', async () => {221 const globCreate = jest.spyOn(glob, 'create');222 const result = await d.findGlob('subfolder')('tmp folder');223 expect(globCreate).toHaveBeenCalledTimes(1);224 expect(result).toStrictEqual([]);...

Full Screen

Full Screen

test-util.js

Source:test-util.js Github

copy

Full Screen

1import { extractZip } from '../dist/util';2import * as path from 'path';3import tmp from 'tmp';4import * as fs from 'fs-extra';5describe('extractZip()', () => {6 it('should error if params is not an object', async () => {7 try {8 await extractZip(123);9 } catch (e) {10 expect(e).to.be.instanceOf(TypeError);11 expect(e.message).to.equal('Expected params to be an object');12 return;13 }14 throw new Error('Expected error');15 });16 it('should error if dest is not a string', async () => {17 try {18 await extractZip({ dest: 123 });19 } catch (e) {20 expect(e).to.be.instanceOf(TypeError);21 expect(e.message).to.equal('Expected destination directory to be a non-empty string');22 return;23 }24 throw new Error('Expected error');25 });26 it('should error if file is not a string', async () => {27 try {28 await extractZip({ dest: __dirname, file: 123 });29 } catch (e) {30 expect(e).to.be.instanceOf(TypeError);31 expect(e.message).to.equal('Expected zip file to be a non-empty string');32 return;33 }34 throw new Error('Expected error');35 });36 it('should error if file does not exist', async () => {37 try {38 await extractZip({ dest: __dirname, file: 'does_not_exist.zip' });39 } catch (e) {40 expect(e).to.be.instanceOf(Error);41 expect(e.message).to.equal('The specified zip file does not exist');42 return;43 }44 throw new Error('Expected error');45 });46 it('should error if file is invalid', async () => {47 try {48 await extractZip({ dest: __dirname, file: __dirname });49 } catch (e) {50 expect(e).to.be.instanceOf(Error);51 expect(e.message).to.equal('The specified zip file is not a file');52 return;53 }54 throw new Error('Expected error');55 });56 it('should support symlinks', async () => {57 const tempDir = tmp.dirSync().name;58 await extractZip({ dest: tempDir, file: path.join(__dirname, 'fixtures', 'symlinks.zip') });59 const folder = path.join(tempDir, 'symlinks/folder');60 expect(fs.existsSync(folder)).to.equal(true);61 const folderStat = fs.statSync(folder);62 expect(folderStat.isDirectory()).to.equal(true);63 const file = path.join(tempDir, 'symlinks/folder/testfile.txt');64 expect(fs.existsSync(file)).to.equal(true);65 const fileStat = fs.statSync(file);66 expect(fileStat.isDirectory()).to.equal(false);67 expect(fileStat.isFile()).to.equal(true);68 const fileLink = path.join(tempDir, 'symlinks/link.txt');69 expect(fs.existsSync(fileLink)).to.equal(true);70 const fileLinkStat = fs.lstatSync(fileLink);71 expect(fileLinkStat.isSymbolicLink()).to.equal(true);72 const folderLink = path.join(tempDir, 'symlinks/folderlink');73 // Since node 12.16.0 (https://github.com/nodejs/node/commit/366a45be2a) this existsSync74 // call will fail even though the symlink exists and is valid on disk75 // expect(fs.existsSync(folderLink)).to.equal(true);76 const folderLinkStat = fs.lstatSync(folderLink);77 expect(folderLinkStat.isSymbolicLink()).to.equal(true);78 const target = fs.readlinkSync(folderLink);79 expect(target).to.equal(`folder${path.sep}`);80 });81 it('should handle if a symlink already exists', async () => {82 const tempDir = tmp.dirSync().name;83 await extractZip({ dest: tempDir, file: path.join(__dirname, 'fixtures', 'symlinks.zip') });84 await extractZip({ dest: tempDir, file: path.join(__dirname, 'fixtures', 'symlinks.zip') });85 const folder = path.join(tempDir, 'symlinks/folder');86 expect(fs.existsSync(folder)).to.equal(true);87 const folderStat = fs.statSync(folder);88 expect(folderStat.isDirectory()).to.equal(true);89 const file = path.join(tempDir, 'symlinks/folder/testfile.txt');90 expect(fs.existsSync(file)).to.equal(true);91 const fileStat = fs.statSync(file);92 expect(fileStat.isDirectory()).to.equal(false);93 expect(fileStat.isFile()).to.equal(true);94 const fileLink = path.join(tempDir, 'symlinks/link.txt');95 expect(fs.existsSync(fileLink)).to.equal(true);96 const fileLinkStat = fs.lstatSync(fileLink);97 expect(fileLinkStat.isSymbolicLink()).to.equal(true);98 const folderLink = path.join(tempDir, 'symlinks/folderlink');...

Full Screen

Full Screen

Unzipper.ts

Source:Unzipper.ts Github

copy

Full Screen

1import { extractZip } from '@actions/tool-cache'2import path from 'path'3import { Logger } from 'winston'4import LoggerFactory from './LoggerFactory'5export default class Unzipper implements IUnzipper {6 private ez: typeof extractZip7 private log: Logger8 constructor(ez: typeof extractZip = extractZip) {9 this.ez = ez10 this.log = LoggerFactory.create('Unzipper')11 }12 async unzip(zipPath: string): Promise<string> {13 const folderPath: string = await this.ez(zipPath, path.dirname(zipPath))14 this.log.info(`Unzipped ${zipPath} to ${folderPath}`)15 return folderPath16 }...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const { openBrowser, goto, closeBrowser, extractZip } = require('taiko');2(async () => {3 try {4 await openBrowser();5 await extractZip("test.zip", "test");6 } catch (e) {7 console.error(e);8 } finally {9 await closeBrowser();10 }11})();12### extractZip(zipFilePath, destinationPath)13[Apache License 2.0](LICENSE)

Full Screen

Using AI Code Generation

copy

Full Screen

1const { extractZip } = require('taiko');2const assert = require('assert');3(async () => {4 try {5 await extractZip('test.zip', 'test');6 assert.ok(true);7 } catch (e) {8 assert.ok(false, e);9 }10})();11const { openBrowser, goto, extractTar, closeBrowser } = require('taiko');12(async () => {13 try {14 await openBrowser();15 await goto('

Full Screen

Using AI Code Generation

copy

Full Screen

1const { extractZip } = require('taiko');2const assert = require('assert');3(async () => {4 try {5 await extractZip('test.zip', 'test');6 assert.ok(1);7 } catch (error) {8 console.error(error);9 assert.ok(0);10 }11})();12[MIT](

Full Screen

Using AI Code Generation

copy

Full Screen

1const { openBrowser, goto, inputField, write, click, closeBrowser, toRightOf, button, $, evaluate, text, link, accept, fileField, attach, waitFor, screenshot, focus, toLeftOf, press, dropDown, below, above, toLeftOf, toRightOf, near, intercept, extractZip } = require('taiko');2(async () => {3 try {4 await openBrowser();5 await attach('test.zip', toRightOf('Select a file:'));6 await click('Submit');7 await waitFor(2000);8 await screenshot({path: 'test.png'});9 await extractZip('test.zip');10 await waitFor(2000);11 await screenshot({path: 'test2.png'});12 } catch (e) {13 console.error(e);14 } finally {15 await closeBrowser();16 }17})();

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run taiko automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful