Skip to content

Commit 6229019

Browse files
committed
update test to work with mocha
1 parent 44b1006 commit 6229019

File tree

1 file changed

+39
-35
lines changed

1 file changed

+39
-35
lines changed

test/issue_130/test.js

Lines changed: 39 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,54 @@
11
"use strict";
22

3-
(function () {
4-
var fs = require("fs");
5-
var path = require("path");
6-
var Zip = require("../../adm-zip");
3+
const assert = require("assert");
4+
const fs = require("fs");
5+
const pth = require("path");
6+
const Zip = require("../../adm-zip");
7+
const rimraf = require("rimraf");
78

8-
// init the final zip file
9-
var writeZip = new Zip();
9+
describe("ADM-ZIP - Issues", () => {
10+
const destination = pth.resolve("./test/xxx");
11+
const unzipped = pth.join(destination, "unzipped");
1012

11-
// file in root folder
12-
writeZip.addFile("root_file.txt", "root");
13+
// clean up folder content
14+
afterEach((done) => rimraf(destination, done));
1315

14-
// add folder
15-
writeZip.addFile("sub/", Buffer.alloc(0));
16+
it("Issue 130 - Created zip's under Windows are corrupt", () => {
17+
// init the final zip file
18+
const writeZip = new Zip();
1619

17-
// file in sub folder
18-
writeZip.addFile("sub/sub_file.txt", "sub");
20+
// file in root folder
21+
writeZip.addFile("root_file.txt", "root");
1922

20-
// files from local folder
21-
writeZip.addLocalFolder("nested", "nested");
23+
// add folder
24+
writeZip.addFile("sub/", Buffer.alloc(0));
2225

23-
// write to disk
24-
writeZip.writeZip("test.zip");
26+
// file in sub folder
27+
writeZip.addFile("sub/sub_file.txt", "sub");
2528

26-
// read zip from disk
27-
var readZip = new Zip("test.zip");
29+
// files from local folder
30+
writeZip.addLocalFolder(pth.resolve("./test/issue_130", "nested"), "nested");
2831

29-
// unpack everything
30-
readZip.extractAllTo("unzipped", true);
32+
// write to disk
33+
writeZip.writeZip(pth.join(destination, "test.zip"));
3134

32-
// assert the files
33-
var assert = function (content, expectedContent, errMsg) {
34-
if (content !== expectedContent) {
35-
throw new Error(errMsg);
36-
}
37-
};
35+
// read zip from disk
36+
const readZip = new Zip(pth.join(destination, "test.zip"));
3837

39-
var fileRoot = fs.readFileSync(path.join("unzipped", "root_file.txt"), "utf8");
40-
assert(fileRoot, "root", "root file not correct");
38+
// unpack everything
39+
readZip.extractAllTo(unzipped, true);
4140

42-
var fileSub = fs.readFileSync(path.join("unzipped", "sub", "sub_file.txt"), "utf8");
43-
assert(fileSub, "sub", "sub file not correct");
41+
// assert the files
42+
const fileRoot = fs.readFileSync(pth.join(unzipped, "root_file.txt"), "utf8");
43+
assert(fileRoot === "root", "root file not correct");
4444

45-
var fileNested = fs.readFileSync(path.join("unzipped", "nested", "nested_file.txt"), "utf8");
46-
assert(fileNested, "nested", "nested file not correct");
45+
const fileSub = fs.readFileSync(pth.join(unzipped, "sub/sub_file.txt"), "utf8");
46+
assert(fileSub === "sub", "sub file not correct");
4747

48-
var fileDeeper = fs.readFileSync(path.join("unzipped", "nested", "deeper", "deeper_file.txt"), "utf8");
49-
assert(fileDeeper, "deeper", "deeper file not correct");
50-
})();
48+
const fileNested = fs.readFileSync(pth.join(unzipped, "nested/nested_file.txt"), "utf8");
49+
assert(fileNested === "nested", "nested file not correct");
50+
51+
const fileDeeper = fs.readFileSync(pth.join(unzipped, "nested/deeper/deeper_file.txt"), "utf8");
52+
assert(fileDeeper === "deeper", "deeper file not correct");
53+
});
54+
});

0 commit comments

Comments
 (0)