diff --git a/test/zip/test/.gitignore b/test/archive_content/test/.gitignore similarity index 100% rename from test/zip/test/.gitignore rename to test/archive_content/test/.gitignore diff --git a/test/zip/test/README.md b/test/archive_content/test/README.md similarity index 100% rename from test/zip/test/README.md rename to test/archive_content/test/README.md diff --git a/test/zip/test/addon/addon.py b/test/archive_content/test/addon/addon.py similarity index 100% rename from test/zip/test/addon/addon.py rename to test/archive_content/test/addon/addon.py diff --git a/test/zip/test/addon/addon.xml b/test/archive_content/test/addon/addon.xml similarity index 100% rename from test/zip/test/addon/addon.xml rename to test/archive_content/test/addon/addon.xml diff --git a/test/files/archives/7z/bzip2.7z b/test/files/archives/7z/bzip2.7z new file mode 100644 index 0000000..cdb0445 Binary files /dev/null and b/test/files/archives/7z/bzip2.7z differ diff --git a/test/files/archives/7z/lzma.7z b/test/files/archives/7z/lzma.7z new file mode 100644 index 0000000..47b9bc9 Binary files /dev/null and b/test/files/archives/7z/lzma.7z differ diff --git a/test/files/archives/7z/lzma2.7z b/test/files/archives/7z/lzma2.7z new file mode 100644 index 0000000..7390246 Binary files /dev/null and b/test/files/archives/7z/lzma2.7z differ diff --git a/test/files/archives/test.rar b/test/files/archives/rar/test-v4.rar similarity index 100% rename from test/files/archives/test.rar rename to test/files/archives/rar/test-v4.rar diff --git a/test/files/archives/test-v5.rar b/test/files/archives/rar/test-v5.rar similarity index 100% rename from test/files/archives/test-v5.rar rename to test/files/archives/rar/test-v5.rar diff --git a/test/files/archives/test.tar b/test/files/archives/tar/test.tar similarity index 100% rename from test/files/archives/test.tar rename to test/files/archives/tar/test.tar diff --git a/test/files/archives/test.tar.bz2 b/test/files/archives/tar/test.tar.bz2 similarity index 100% rename from test/files/archives/test.tar.bz2 rename to test/files/archives/tar/test.tar.bz2 diff --git a/test/files/archives/test.tar.gz b/test/files/archives/tar/test.tar.gz similarity index 98% rename from test/files/archives/test.tar.gz rename to test/files/archives/tar/test.tar.gz index 1a02003..e1c870e 100644 Binary files a/test/files/archives/test.tar.gz and b/test/files/archives/tar/test.tar.gz differ diff --git a/test/files/archives/tar/test.tar.xz b/test/files/archives/tar/test.tar.xz new file mode 100644 index 0000000..817ac9d Binary files /dev/null and b/test/files/archives/tar/test.tar.xz differ diff --git a/test/files/test-single.html b/test/files/test-single.html index b95113c..33fe035 100644 --- a/test/files/test-single.html +++ b/test/files/test-single.html @@ -65,21 +65,11 @@ const file = e.currentTarget.files[0]; const archive = await Archive.open(file); const files = await archive.getFilesArray(); - //console.log(files); fileObj = await files[0].file.extract(); - - objBefore = await archive.getFilesObject(); - //console.log(f1); - objAfter = await archive.extractFiles(); - //console.log( await archive.getFilesObject() ); - //console.log( await archive.getFilesArray() ); - objAfter = await fileChecksums(objAfter); }catch(err){ console.error(err); }finally{ - window.fileObj = await getChecksum(fileObj); - window.obj = objAfter; - window.objBefore = objBefore; + window.obj = await getChecksum(fileObj); finish(); } }); diff --git a/test/formats/7z.test.js b/test/formats/7z.test.js new file mode 100644 index 0000000..c63f48c --- /dev/null +++ b/test/formats/7z.test.js @@ -0,0 +1,36 @@ +/* eslint-disable no-undef */ +const {checksum} = require('../checksum'); +const {navigate,inputFile,response,setup,cleanup} = require('../testutils'); + +let browser,page; + +beforeAll(async () => { + let tmp = await setup(); + browser = tmp.browser; + page = tmp.page; +}); + +describe("Extract 7Z files with various compressions", () => { + test("Extract 7Z with LZMA", async () => { + await navigate(page); + await inputFile('archives/7z/lzma.7z',page); + const files = await response(page); + expect(files).toEqual(checksum); + }, 16000); + test("Extract 7Z with LZMA2", async () => { + await navigate(page); + await inputFile('archives/7z/lzma2.7z',page); + const files = await response(page); + expect(files).toEqual(checksum); + }, 16000); + test("Extract 7Z with BZIP2", async () => { + await navigate(page); + await inputFile('archives/7z/bzip2.7z',page); + const files = await response(page); + expect(files).toEqual(checksum); + }, 16000); +}); + +afterAll(() => { + cleanup(browser); +}); \ No newline at end of file diff --git a/test/formats/rar.test.js b/test/formats/rar.test.js new file mode 100644 index 0000000..80c16a4 --- /dev/null +++ b/test/formats/rar.test.js @@ -0,0 +1,30 @@ +/* eslint-disable no-undef */ +const {checksum} = require('../checksum'); +const {navigate,inputFile,response,setup,cleanup} = require('../testutils'); + +let browser,page; + +beforeAll(async () => { + let tmp = await setup(); + browser = tmp.browser; + page = tmp.page; +}); + +describe("Extract RAR files", () => { + test("Extract RAR v4", async () => { + await navigate(page); + await inputFile('archives/rar/test-v4.rar',page); + const files = await response(page); + expect(files).toEqual(checksum); + }, 16000); + test("Extract RAR v5", async () => { + await navigate(page); + await inputFile('archives/rar/test-v5.rar',page); + const files = await response(page); + expect(files).toEqual(checksum); + }, 16000); +}); + +afterAll(() => { + cleanup(browser); +}); \ No newline at end of file diff --git a/test/formats/tar.test.js b/test/formats/tar.test.js new file mode 100644 index 0000000..561bd6f --- /dev/null +++ b/test/formats/tar.test.js @@ -0,0 +1,42 @@ +/* eslint-disable no-undef */ +const {checksum} = require('../checksum'); +const {navigate,inputFile,response,setup,cleanup} = require('../testutils'); + +let browser,page; + +beforeAll(async () => { + let tmp = await setup(); + browser = tmp.browser; + page = tmp.page; +}); + +describe("Extract TAR files with various compressions", () => { + test("Extract TAR without compression", async () => { + await navigate(page); + await inputFile('archives/tar/test.tar',page); + const files = await response(page); + expect(files).toEqual(checksum); + }, 16000); + test("Extract TAR BZIP2", async () => { + await navigate(page); + await inputFile('archives/tar/test.tar.bz2',page); + const files = await response(page); + expect(files).toEqual(checksum); + }, 16000); + test("Extract TAR GZIP", async () => { + await navigate(page); + await inputFile('archives/tar/test.tar.gz',page); + const files = await response(page); + expect(files).toEqual(checksum); + }, 16000); + test("Extract TAR LZMA2", async () => { + await navigate(page); + await inputFile('archives/tar/test.tar.xz',page); + const files = await response(page); + expect(files).toEqual(checksum); + }, 16000); +}); + +afterAll(() => { + cleanup(browser); +}); \ No newline at end of file diff --git a/test/zip.test.js b/test/formats/zip.test.js similarity index 91% rename from test/zip.test.js rename to test/formats/zip.test.js index 95bdce6..d06cee8 100644 --- a/test/zip.test.js +++ b/test/formats/zip.test.js @@ -1,6 +1,6 @@ /* eslint-disable no-undef */ -const {checksum} = require('./checksum'); -const {navigate,inputFile,response,setup,cleanup} = require('./testutils'); +const {checksum} = require('../checksum'); +const {navigate,inputFile,response,setup,cleanup} = require('../testutils'); let browser,page; diff --git a/test/main.test.js b/test/main.test.js index f73a05b..5eaec80 100644 --- a/test/main.test.js +++ b/test/main.test.js @@ -11,47 +11,18 @@ beforeAll(async () => { }); describe("extract various compression types", () => { - test("extract zip file", async () => { - await navigate(page); - await inputFile('archives/test.zip',page); - const files = await response(page); - expect(files).toEqual(checksum); - }, 16000); test("extract 7z file", async () => { await navigate(page); await inputFile('archives/test.7z',page); const files = await response(page); expect(files).toEqual(checksum); }, 16000); - test("extract tar file", async () => { - await navigate(page); - await inputFile('archives/test.tar',page); - const files = await response(page); - expect(files).toEqual(checksum); - }, 16000); - test("extract tar.gz file", async () => { - await navigate(page); - await inputFile('archives/test.tar.gz',page); - const files = await response(page); - expect(files).toEqual(checksum); - }, 16000); - test("extract rar v4 file", async () => { - await navigate(page); - await inputFile('archives/test.rar',page); - const files = await response(page); - expect(files).toEqual(checksum); - }, 16000); - test("extract rar v5 file", async () => { - await navigate(page); - await inputFile('archives/test-v5.rar',page); - const files = await response(page); - expect(files).toEqual(checksum); - }, 16000); - test("extract tar.bz2 file", async () => { - await navigate(page); - await inputFile('archives/test.tar.bz2',page); - const files = await response(page); - expect(files).toEqual(checksum); + + test("extract single file from zip", async () => { + await navigate(page,'test-single.html'); + await inputFile('archives/test.zip',page); + const file = await response(page); + expect(file).toEqual(checksum['.gitignore']); }, 16000); }); diff --git a/test/singlefile.test.js b/test/singlefile.test.js deleted file mode 100644 index bd2aa1d..0000000 --- a/test/singlefile.test.js +++ /dev/null @@ -1,62 +0,0 @@ -const {checksum} = require('./checksum'); -const puppeteer = require('puppeteer'); - -const StaticServer = require('static-server'); -const port = 8788; -const server = new StaticServer({ - rootPath: '.', - port: port, - cors: '*', -}); - -const startServer = () => new Promise((resolve,reject) => { - server.start( () => { - console.log('Server listening to', port); - resolve(); - }); -}); - -let page; -let browser; -const width = 800; -const height = 600; - -async function navigate(){ - await page.goto(`http://127.0.0.1:${port}/test/files/test-single.html`); -} -async function inputFile(file){ - const fileInp = await page.$('#file'); - fileInp.uploadFile('test/files/'+file); -} -async function response(){ - await page.waitForSelector('#done'); - return { - filesObj: await page.evaluate(`window.obj`), - file: await page.evaluate(`window.fileObj`) - }; -} - -beforeAll(async () => { - browser = await puppeteer.launch(); - page = await browser.newPage(); - await page.setViewport({ width, height }); - await startServer(); - page.on('console', msg => { - for (let i = 0; i < msg.args().length; ++i) console.log(`${i}: ${msg.args()[i]}`); - }); -}); - -describe("test file listing", () => { - test("extract single file from zip", async () => { - await navigate(); - await inputFile('archives/test.zip'); - const { filesObj, file } = await response(); - expect(filesObj).toEqual(checksum); - expect(file).toEqual(checksum['.gitignore']); - }, 16000); -}); - -afterAll(() => { - server.stop(); - browser.close(); -}); \ No newline at end of file diff --git a/test/testutils.js b/test/testutils.js index 10f7ba2..d70f5ec 100644 --- a/test/testutils.js +++ b/test/testutils.js @@ -31,8 +31,8 @@ module.exports = { server.stop(); browser.close(); }, - navigate: async function (page){ - await page.goto(`http://127.0.0.1:${port}/test/files/index.html`); + navigate: async function (page, path = 'index.html') { + await page.goto(`http://127.0.0.1:${port}/test/files/${path}`); }, inputFile: async function (file,page){ const fileInp = await page.$('#file');