add tests for File and test based operations. Only unzip to go
This commit is contained in:
parent
2019ae43d7
commit
b8cb7e9ba8
@ -42,6 +42,14 @@ class File {
|
|||||||
get size() {
|
get size() {
|
||||||
return this.data.length;
|
return this.data.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return lastModified as Date
|
||||||
|
*/
|
||||||
|
get lastModifiedDate() {
|
||||||
|
return new Date(this.lastModified);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default File;
|
export default File;
|
||||||
|
@ -13,12 +13,6 @@ export default [
|
|||||||
"Label",
|
"Label",
|
||||||
"Comment",
|
"Comment",
|
||||||
|
|
||||||
// Exclude file ops until HTML5 File Object can be mimicked
|
|
||||||
// "Tar",
|
|
||||||
// "Untar",
|
|
||||||
"Unzip",
|
|
||||||
"Zip",
|
|
||||||
|
|
||||||
// esprima doesn't work in .mjs
|
// esprima doesn't work in .mjs
|
||||||
"JavaScriptBeautify",
|
"JavaScriptBeautify",
|
||||||
"JavaScriptMinify",
|
"JavaScriptMinify",
|
||||||
|
@ -30,6 +30,7 @@ global.ENVIRONMENT_IS_WEB = function() {
|
|||||||
import TestRegister from "../lib/TestRegister";
|
import TestRegister from "../lib/TestRegister";
|
||||||
import "./tests/nodeApi";
|
import "./tests/nodeApi";
|
||||||
import "./tests/ops";
|
import "./tests/ops";
|
||||||
|
import "./tests/File";
|
||||||
|
|
||||||
const testStatus = {
|
const testStatus = {
|
||||||
allTestsPassing: true,
|
allTestsPassing: true,
|
||||||
|
20
tests/node/tests/File.mjs
Normal file
20
tests/node/tests/File.mjs
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
import assert from "assert";
|
||||||
|
import it from "../assertionHandler";
|
||||||
|
import TestRegister from "../../lib/TestRegister";
|
||||||
|
import File from "../../../src/node/File";
|
||||||
|
|
||||||
|
TestRegister.addApiTests([
|
||||||
|
it("File: should exist", () => {
|
||||||
|
assert(File);
|
||||||
|
}),
|
||||||
|
|
||||||
|
it("File: Should have same properties as DOM File object", () => {
|
||||||
|
const uint8Array = new Uint8Array(Buffer.from("hello"));
|
||||||
|
const file = new File([uint8Array], "name.txt");
|
||||||
|
assert.equal(file.name, "name.txt");
|
||||||
|
assert(typeof file.lastModified, "number");
|
||||||
|
assert(file.lastModifiedDate instanceof Date);
|
||||||
|
assert.equal(file.size, uint8Array.length);
|
||||||
|
assert.equal(file.type, "text/plain");
|
||||||
|
}),
|
||||||
|
]);
|
@ -387,7 +387,7 @@ TestRegister.addApiTests([
|
|||||||
|
|
||||||
it("Operation arguments: should be accessible from operation object if op has array arg", () => {
|
it("Operation arguments: should be accessible from operation object if op has array arg", () => {
|
||||||
assert.ok(chef.toCharcode.argOptions);
|
assert.ok(chef.toCharcode.argOptions);
|
||||||
assert.equal(chef.unzip.argOptions, undefined);
|
assert.deepEqual(chef.unzip.argOptions, {});
|
||||||
}),
|
}),
|
||||||
|
|
||||||
it("Operation arguments: should have key for each array-based argument in operation", () => {
|
it("Operation arguments: should have key for each array-based argument in operation", () => {
|
||||||
|
@ -35,6 +35,9 @@ import {
|
|||||||
} from "../../../src/node/index";
|
} from "../../../src/node/index";
|
||||||
import chef from "../../../src/node/index";
|
import chef from "../../../src/node/index";
|
||||||
import TestRegister from "../../lib/TestRegister";
|
import TestRegister from "../../lib/TestRegister";
|
||||||
|
import File from "../../../src/node/File";
|
||||||
|
|
||||||
|
global.File = File;
|
||||||
|
|
||||||
TestRegister.addApiTests([
|
TestRegister.addApiTests([
|
||||||
|
|
||||||
@ -971,5 +974,48 @@ ExifImageWidth: 57
|
|||||||
ExifImageHeight: 57`);
|
ExifImageHeight: 57`);
|
||||||
}),
|
}),
|
||||||
|
|
||||||
|
it("Tar", () => {
|
||||||
|
const tarred = chef.tar("some file content", {
|
||||||
|
filename: "test.txt"
|
||||||
|
});
|
||||||
|
assert.strictEqual(tarred.type, 7);
|
||||||
|
assert.strictEqual(tarred.value.size, 2048);
|
||||||
|
assert.strictEqual(tarred.value.data.toString().substr(0, 8), "test.txt");
|
||||||
|
}),
|
||||||
|
|
||||||
|
it("Untar", () => {
|
||||||
|
const tarred = chef.tar("some file content", {
|
||||||
|
filename: "filename.txt",
|
||||||
|
});
|
||||||
|
const untarred = chef.untar(tarred);
|
||||||
|
assert.strictEqual(untarred.type, 8);
|
||||||
|
assert.strictEqual(untarred.value.length, 1);
|
||||||
|
assert.strictEqual(untarred.value[0].name, "filename.txt");
|
||||||
|
assert.strictEqual(untarred.value[0].data.toString(), "some file content");
|
||||||
|
}),
|
||||||
|
|
||||||
|
it("Zip", () => {
|
||||||
|
const zipped = chef.zip("some file content", {
|
||||||
|
filename: "sample.zip",
|
||||||
|
comment: "added",
|
||||||
|
operaringSystem: "Unix",
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.strictEqual(zipped.type, 7);
|
||||||
|
assert.equal(zipped.value.data.toString().indexOf("sample.zip"), 30);
|
||||||
|
assert.equal(zipped.value.data.toString().indexOf("added"), 122);
|
||||||
|
}),
|
||||||
|
|
||||||
|
// it("Unzip", () => {
|
||||||
|
// const zipped = chef.zip("some file content", {
|
||||||
|
// filename: "zipped.zip",
|
||||||
|
// comment: "zippy",
|
||||||
|
// });
|
||||||
|
// const unzipped = chef.unzip(zipped);
|
||||||
|
|
||||||
|
// assert.equal(unzipped.type, 8);
|
||||||
|
// assert.equal(unzipped.value = "zipped.zip");
|
||||||
|
// }),
|
||||||
|
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user