Skip to content

Commit

Permalink
[JavaScript] detect platform wrong (#832)
Browse files Browse the repository at this point in the history
fix: add uint8 test
  • Loading branch information
theweipeng authored Aug 2, 2023
1 parent 0a99c71 commit 127517b
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 2 deletions.
2 changes: 1 addition & 1 deletion javascript/packages/fury/lib/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
export const isNodeEnv = typeof process === "object" && process.env.ECMA_ONLY !== 'true' && typeof require === "function";
2 changes: 1 addition & 1 deletion javascript/packages/fury/package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
File renamed without changes.
57 changes: 57 additions & 0 deletions javascript/test/reader.test.ts
Original file line number Diff line number Diff line change
@@ -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);
}
});
});
})


0 comments on commit 127517b

Please sign in to comment.