add dish translation tests for node

This commit is contained in:
d98762625 committed 2019-05-03 13:36:08 +01:00
1 parent aeb08caf77
commit 65a3897f87
7 files changed
+147 -24

No files matched your search

+1 -1
View File
@@ -208,7 +208,7 @@ class Dish {
valid() {
switch (this.type) {
case Dish.BYTE_ARRAY:
if (!(this.value instanceof Array)) {
if (!(this.value instanceof Uint8Array) && !(this.value instanceof Array)) {
return false;
}
+1 -2
View File
@@ -1039,8 +1039,7 @@ class Utils {
if (!Utils.isNode()) {
throw new TypeError("Browser environment cannot support readFileSync");
}
// Resist using node's Buffer.buffer here - this yields a 8192 length byteArray
// regardless of the length of the buffer.
const arrayBuffer = Uint8Array.from(file.data);
return arrayBuffer.buffer;
}
@@ -19,7 +19,6 @@ class DishFile extends DishTranslationType {
static toArrayBuffer() {
DishFile.checkForValue(this.value);
if (Utils.isNode()) {
// TODO
this.value = Utils.readFileSync(this.value);
} else {
return new Promise((resolve, reject) => {
+2 -10
View File
@@ -4,14 +4,13 @@
* @license Apache-2.0
*/
import DishTranslationType from "./DishTranslationType";
import Utils from "../Utils";
import DishString from "./DishString";
import Utils from "../Utils";
/**
* Translation methods for HTML Dishes
*/
class DishHTML extends DishTranslationType {
class DishHTML extends DishString {
/**
* convert the given value to a ArrayBuffer
@@ -22,13 +21,6 @@ class DishHTML extends DishTranslationType {
this.value = this.value ? Utils.strToArrayBuffer(Utils.unescapeHtml(Utils.stripHtmlTags(this.value, true))) : new ArrayBuffer;
}
/**
* convert the given value from a ArrayBuffer
* @param {boolean} notUTF8
*/
static fromArrayBuffer(notUTF8) {
DishString.fromByteArray(this.value, notUTF8);
}
}
export default DishHTML;
@@ -5,6 +5,7 @@
*/
import DishTranslationType from "./DishTranslationType";
import Utils from "../Utils.mjs";
/**
* Translation methods for ListFile Dishes
@@ -16,6 +17,10 @@ class DishListFile extends DishTranslationType {
*/
static toArrayBuffer() {
DishListFile.checkForValue(this.value);
if (Utils.isNode()) {
this.value = this.value.map(file => Uint8Array.from(file.data));
}
this.value = DishListFile.concatenateTypedArrays(...this.value).buffer;
}