From 127517ba363d099eba8de6ed230744e0008e8b9d Mon Sep 17 00:00:00 2001 From: weipeng Date: Wed, 2 Aug 2023 23:59:40 +0800 Subject: [PATCH] [JavaScript] detect platform wrong (#832) fix: add uint8 test --- javascript/packages/fury/lib/util.ts | 2 +- javascript/packages/fury/package.json | 2 +- .../struct.test.ts} | 0 javascript/test/reader.test.ts | 57 +++++++++++++++++++ 4 files changed, 59 insertions(+), 2 deletions(-) rename javascript/test/{protocol.test.ts => protocol/struct.test.ts} (100%) create mode 100644 javascript/test/reader.test.ts diff --git a/javascript/packages/fury/lib/util.ts b/javascript/packages/fury/lib/util.ts index f9dc7ee720..4565cafa27 100644 --- a/javascript/packages/fury/lib/util.ts +++ b/javascript/packages/fury/lib/util.ts @@ -44,4 +44,4 @@ export const safePropName = (prop: string) => { return prop; } -export const isNodeEnv = typeof process === "object" && process.env.ECMA_ONLY === 'true' && typeof require === "function"; \ No newline at end of file +export const isNodeEnv = typeof process === "object" && process.env.ECMA_ONLY !== 'true' && typeof require === "function"; \ No newline at end of file diff --git a/javascript/packages/fury/package.json b/javascript/packages/fury/package.json index 536802ab63..a4f02ec7c7 100644 --- a/javascript/packages/fury/package.json +++ b/javascript/packages/fury/package.json @@ -1,6 +1,6 @@ { "name": "@furyjs/fury", - "version": "0.0.16", + "version": "0.0.17", "description": "A blazing fast multi-language serialization framework powered by jit and zero-copy", "main": "dist/index.js", "scripts": { diff --git a/javascript/test/protocol.test.ts b/javascript/test/protocol/struct.test.ts similarity index 100% rename from javascript/test/protocol.test.ts rename to javascript/test/protocol/struct.test.ts diff --git a/javascript/test/reader.test.ts b/javascript/test/reader.test.ts new file mode 100644 index 0000000000..bb1b5d879f --- /dev/null +++ b/javascript/test/reader.test.ts @@ -0,0 +1,57 @@ +/* + * Copyright 2023 The Fury Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { Config } from '@furyjs/fury/lib/type'; +import { BinaryWriter } from '@furyjs/fury/lib/writer'; +import { describe, expect, test } from '@jest/globals'; +const hps = process.env.enableHps ? require('@furyjs/hps') : null; + + + +[ + { + useLatin1: true, + hps, + }, + { + useLatin1: false, + hps, + } +].forEach((config: Config) => { + describe('writer', () => { + test('should uint8 work', () => { + const writer = BinaryWriter(config); + { + writer.uint8(10); + var ab = writer.dump(); + expect(ab.byteLength).toBe(1); + expect(ab[0]).toBe(10); + expect(writer.getCursor()).toBe(1); + } + + { + writer.uint8(256); + var ab = writer.dump(); + + expect(ab.byteLength).toBe(2); + expect(ab[1]).toBe(0); + expect(writer.getCursor()).toBe(2); + } + }); + }); +}) + +