Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nika-begiashvili committed Jan 23, 2024
1 parent 81fff4b commit 07f4eae
Show file tree
Hide file tree
Showing 12 changed files with 80 additions and 106 deletions.
16 changes: 8 additions & 8 deletions dist/build/compiled/archive-reader.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,18 @@ export declare class ArchiveReader {
private _processed;
constructor(file: File, client: any, worker: any);
/**
* Prepares file for reading
* @returns {Promise<Archive>} archive instance
*/
* Prepares file for reading
* @returns {Promise<Archive>} archive instance
*/
open(): Promise<ArchiveReader>;
/**
* Terminate worker to free up memory
*/
* Terminate worker to free up memory
*/
close(): Promise<void>;
/**
* detect if archive has encrypted data
* @returns {boolean|null} null if could not be determined
*/
* detect if archive has encrypted data
* @returns {boolean|null} null if could not be determined
*/
hasEncryptedData(): Promise<boolean | null>;
/**
* set password to be used when reading archive
Expand Down
2 changes: 1 addition & 1 deletion dist/worker-bundle-node.mjs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/worker-bundle.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"version": "2.0.0",
"description": "extract/create archive files in browser/nodejs, libarchive port in wasm",
"main": "dist/libarchive.js",
"types": "dist/build/compiled/libarchive.d.ts",
"repository": {
"type": "git",
"url": "https://github.com/nika-begiashvili/libarchivejs"
Expand Down
2 changes: 1 addition & 1 deletion src/webworker/archive-writer.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export class ArchiveWriter {

async write(files, compression, format, passphrase = null) {
// In some cases archive size might be bigger than the sum of all files due to header size
let totalSize = files.reduce((acc, { file }) => acc + file.size, 0) + 512;
let totalSize = files.reduce((acc, { file }) => acc + file.size + 128, 0) + 128;

const bufferPtr = this._runCode.malloc(totalSize);
const outputSizePtr = this._runCode.malloc(this._runCode.sizeOfSizeT());
Expand Down
10 changes: 2 additions & 8 deletions test/formats/7z.test.js → test/formats/7z.test.mjs
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
/* eslint-disable no-undef */
const { checksum } = require("../checksum.js");
const {
navigate,
inputFile,
response,
setup,
cleanup,
} = require("../testutils.js");
import { checksum } from "../checksum.js";
import { navigate, inputFile, response, setup, cleanup } from "../testutils.mjs";

let browser, page;

Expand Down
10 changes: 2 additions & 8 deletions test/formats/rar.test.js → test/formats/rar.test.mjs
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
/* eslint-disable no-undef */
const { checksum } = require("../checksum.js");
const {
navigate,
inputFile,
response,
setup,
cleanup,
} = require("../testutils.js");
import { checksum } from "../checksum.js";
import { navigate, inputFile, response, setup, cleanup } from "../testutils.mjs";

let browser, page;

Expand Down
10 changes: 2 additions & 8 deletions test/formats/tar.test.js → test/formats/tar.test.mjs
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
/* eslint-disable no-undef */
const { checksum } = require("../checksum.js");
const {
navigate,
inputFile,
response,
setup,
cleanup,
} = require("../testutils.js");
import { checksum } from "../checksum.js";
import { navigate, inputFile, response, setup, cleanup } from "../testutils.mjs";

let browser, page;

Expand Down
10 changes: 2 additions & 8 deletions test/formats/zip.test.js → test/formats/zip.test.mjs
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
/* eslint-disable no-undef */
const { checksum } = require("../checksum.js");
const {
navigate,
inputFile,
response,
setup,
cleanup,
} = require("../testutils.js");
import { checksum } from "../checksum.js";
import { navigate, inputFile, response, setup, cleanup } from "../testutils.mjs";

let browser, page;

Expand Down
10 changes: 2 additions & 8 deletions test/main.test.js → test/main.test.mjs
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
/* eslint-disable no-undef */
const { checksum } = require("./checksum.js");
const {
navigate,
inputFile,
response,
setup,
cleanup,
} = require("./testutils.js");
import { checksum } from "./checksum.js";
import { navigate, inputFile, response, setup, cleanup } from "./testutils.mjs";

let browser, page;

Expand Down
55 changes: 0 additions & 55 deletions test/testutils.js

This file was deleted.

58 changes: 58 additions & 0 deletions test/testutils.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import StaticServer from "static-server";
import puppeteer from "puppeteer";
import isWsl from "is-wsl";

const port = 8787;
const width = 800;
const height = 600;
const server = new StaticServer({
rootPath: ".",
port: port,
cors: "*",
});

const startServer = () =>
new Promise((resolve) => {
server.start(() => {
console.log("Server listening to", port);
resolve();
});
});

export const setup = async () => {
let browser = isWsl
? await puppeteer.launch({
headless: "new",
executablePath: "google-chrome",
args: ["--no-sandbox"],
})
: await puppeteer.launch({ headless: "new" });

let 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]}`);
});
return { browser, page };
};

export const cleanup = (browser) => {
server.stop();
browser.close();
};

export const navigate = async function (page, path = "index.html") {
await page.goto(`http://127.0.0.1:${port}/test/files/${path}`);
};

export const inputFile = async function (file, page) {
const fileInp = await page.$("#file");
fileInp.uploadFile("test/files/" + file);
};

export const response = async function (page) {
await page.waitForSelector("#done");
return await page.evaluate(`window.obj`);
};

0 comments on commit 07f4eae

Please sign in to comment.