mirror of
https://github.com/Drop-OSS/droplet.git
synced 2026-06-22 04:11:40 +10:00
fix: tests
This commit is contained in:
+1
-69
@@ -135,72 +135,4 @@ test.skip("zip speed test", async (t) => {
|
|||||||
console.log(`total rough average: ${prettyBytes(roughAverage)}/s`);
|
console.log(`total rough average: ${prettyBytes(roughAverage)}/s`);
|
||||||
|
|
||||||
t.pass();
|
t.pass();
|
||||||
});
|
});
|
||||||
|
|
||||||
test("zip manifest test", async (t) => {
|
|
||||||
const zipFiles = fs.readdirSync("./assets").filter((v) => v.endsWith(".zip"));
|
|
||||||
|
|
||||||
for (const zipFile of zipFiles) {
|
|
||||||
console.log("generating manifest for " + zipFile);
|
|
||||||
const manifest = JSON.parse(
|
|
||||||
await generateManifest(
|
|
||||||
"./assets/" + zipFile,
|
|
||||||
(_, __) => {},
|
|
||||||
(_, __) => {}
|
|
||||||
)
|
|
||||||
);
|
|
||||||
const files = await listFiles("./assets/" + zipFile);
|
|
||||||
|
|
||||||
if(Object.keys(manifest).length == 0) return t.fail("manifest was empty")
|
|
||||||
|
|
||||||
for (const [filename, data] of Object.entries(manifest)) {
|
|
||||||
let start = 0;
|
|
||||||
for (const [chunkIndex, length] of data.lengths.entries()) {
|
|
||||||
const hash = createHash("md5");
|
|
||||||
const stream = await readFile(
|
|
||||||
"./assets/" + zipFile,
|
|
||||||
filename,
|
|
||||||
BigInt(start),
|
|
||||||
BigInt(start + length)
|
|
||||||
);
|
|
||||||
|
|
||||||
let streamLength = 0;
|
|
||||||
await stream.pipeTo(
|
|
||||||
new WritableStream({
|
|
||||||
write(chunk) {
|
|
||||||
streamLength += chunk.length;
|
|
||||||
hash.update(chunk);
|
|
||||||
},
|
|
||||||
})
|
|
||||||
);
|
|
||||||
|
|
||||||
if (streamLength != length)
|
|
||||||
return t.fail(
|
|
||||||
`stream length for chunk index ${chunkIndex} was not expected: real: ${streamLength} vs expected: ${length}`
|
|
||||||
);
|
|
||||||
|
|
||||||
const digest = hash.digest("hex");
|
|
||||||
if (data.checksums[chunkIndex] != digest)
|
|
||||||
return t.fail(
|
|
||||||
`checksums did not match for chunk index ${chunkIndex}: real: ${digest} vs expected: ${data.checksums[chunkIndex]}`
|
|
||||||
);
|
|
||||||
|
|
||||||
start += length;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
t.pass();
|
|
||||||
});
|
|
||||||
|
|
||||||
test.skip("partially compress zip test", async (t) => {
|
|
||||||
const manifest = JSON.parse(
|
|
||||||
await generateManifest(
|
|
||||||
"./assets/my horror game.zip",
|
|
||||||
(_, __) => {},
|
|
||||||
(_, __) => {}
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
return t.pass();
|
|
||||||
});
|
|
||||||
+1
-1
@@ -46,7 +46,7 @@
|
|||||||
"build": "napi build --platform --release",
|
"build": "napi build --platform --release",
|
||||||
"build:debug": "napi build --platform",
|
"build:debug": "napi build --platform",
|
||||||
"prepublishOnly": "napi prepublish -t npm",
|
"prepublishOnly": "napi prepublish -t npm",
|
||||||
"test": "ava ",
|
"test": "ava __test__/*",
|
||||||
"universal": "napi universalize",
|
"universal": "napi universalize",
|
||||||
"version": "napi version"
|
"version": "napi version"
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user