Skip to content

Commit

Permalink
chore(JavaScript): Fix JavaScript test CI (#1355)
Browse files Browse the repository at this point in the history
1. JavaScript codebase contains a c++ module which requires the nodejs
version greater than 20, we should ignore it when the version is not
satisfied to prevent it from breaking test ci
2. Remove coverage threshold temporarily before the xlang protocol
release
3. Add 14.x and 16.x to the docker envs

#1350
  • Loading branch information
theweipeng authored Jan 24, 2024
1 parent ad19645 commit 5e89732
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 98 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [14.x, 20.x]
node-version: [14.x, 16.x, 18.x, 20.x]
steps:
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
Expand Down
25 changes: 16 additions & 9 deletions javascript/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,11 @@
*/

/** @type {import('ts-jest').JestConfigWithTsJest} */
const semver = require("semver");
const hpsEnable = semver.gt(process.versions.node, '20.0.0')

module.exports = {
collectCoverage: true,
collectCoverage: hpsEnable,
preset: 'ts-jest',
testEnvironment: 'node',
collectCoverageFrom: [
Expand All @@ -28,6 +31,9 @@ module.exports = {
"!**/build/**",
"!packages/fury/lib/murmurHash3.ts"
],
"testPathIgnorePatterns" : [
hpsEnable ? null : "(.*)/hps.test.ts$",
].filter(Boolean),
transform: {
'\\.ts$': ['ts-jest', {
tsconfig: {
Expand All @@ -38,12 +44,13 @@ module.exports = {
}
}],
},
coverageThreshold: {
global: {
branches: 91,
functions: 99,
lines: 98,
statements: 98
}
}
// todo: JavaScript codebase is iterating rapidly, remove this restriction temporary
// coverageThreshold: {
// global: {
// branches: 91,
// functions: 99,
// lines: 98,
// statements: 98
// }
// }
};
6 changes: 5 additions & 1 deletion javascript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
"@stylistic/eslint-plugin": "^1.5.1",
"@types/js-beautify": "^1.14.3",
"eslint": "^8.55.0",
"js-beautify": "^1.14.11"
"js-beautify": "^1.14.11",
"jest": "^29.5.0",
"jest-junit": "^16.0.0",
"ts-jest": "^29.0.2",
"typescript": "^4.8.4"
}
}
6 changes: 1 addition & 5 deletions javascript/packages/fury/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,7 @@
"@typescript-eslint/parser": "^5.40.0",
"benchmark": "^2.1.4",
"eslint": "^8.25.0",
"jest": "^29.5.0",
"jest-junit": "^16.0.0",
"protobufjs": "^7.2.4",
"ts-jest": "^29.0.2",
"typescript": "^4.8.4"
"protobufjs": "^7.2.4"
},
"dependencies": {
"node-gyp": "^9.4.0",
Expand Down
51 changes: 21 additions & 30 deletions javascript/test/reader.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,42 +17,33 @@
* under the License.
*/

import { alloc } from '@furyjs/fury/lib/platformBuffer';
import { BinaryReader } from '@furyjs/fury/lib/reader';
import { Config } from '@furyjs/fury/lib/type';
import { BinaryWriter } from '@furyjs/fury/lib/writer';
import { alloc } from '../packages/fury/lib/platformBuffer';
import { BinaryReader } from '../packages/fury/lib/reader';
import { BinaryWriter } from '../packages/fury/lib/writer';
import { describe, expect, test } from '@jest/globals';
const hps = process.env.enableHps ? require('@furyjs/hps') : null;


describe('writer', () => {
test('should uint8 work', () => {
const writer = BinaryWriter({});
{
writer.uint8(10);
var ab = writer.dump();
expect(ab.byteLength).toBe(1);
expect(ab[0]).toBe(10);
expect(writer.getCursor()).toBe(1);
}

[
{
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();

{
writer.uint8(256);
var ab = writer.dump();

expect(ab.byteLength).toBe(2);
expect(ab[1]).toBe(0);
expect(writer.getCursor()).toBe(2);
}
});
expect(ab.byteLength).toBe(2);
expect(ab[1]).toBe(0);
expect(writer.getCursor()).toBe(2);
}
});
})
});


describe('reader', () => {
Expand Down
91 changes: 41 additions & 50 deletions javascript/test/string.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,56 +19,47 @@

import Fury, { TypeDescription, InternalSerializerType, Type } from '../packages/fury/index';
import {describe, expect, test} from '@jest/globals';
const hps = require('@furyjs/hps');
[
{
hps,
},
{
hps: null,
}
].forEach(config => {
describe('string', () => {
test('should latin1 string work', () => {

const fury = new Fury(config);
const input = fury.serialize("123")
const result = fury.deserialize(
input
);
expect(result).toEqual("123")
});

test('should utf8 string work', () => {

const fury = new Fury(config);
const input = fury.serialize("我是Fury, 你好!😁א")
const result = fury.deserialize(
input
);
expect(result).toEqual("我是Fury, 你好!😁א")
});

test('should long latin1 string work', () => {
const str = new Array(100).fill("123").join();
const fury = new Fury(config);
const input = fury.serialize(str)
const result = fury.deserialize(
input
);
expect(result).toEqual(str)
});

test('should long utf8 string work', () => {
const str = new Array(10).fill("我是Fury, 你好!😁א").join();
const fury = new Fury(config);
const input = fury.serialize(str)
const result = fury.deserialize(
input
);
expect(result).toEqual(str)
});
const config = {};

describe('string', () => {
test('should latin1 string work', () => {

const fury = new Fury(config);
const input = fury.serialize("123")
const result = fury.deserialize(
input
);
expect(result).toEqual("123")
});

test('should utf8 string work', () => {

const fury = new Fury(config);
const input = fury.serialize("我是Fury, 你好!😁א")
const result = fury.deserialize(
input
);
expect(result).toEqual("我是Fury, 你好!😁א")
});

})

test('should long latin1 string work', () => {
const str = new Array(100).fill("123").join();
const fury = new Fury(config);
const input = fury.serialize(str)
const result = fury.deserialize(
input
);
expect(result).toEqual(str)
});

test('should long utf8 string work', () => {
const str = new Array(10).fill("我是Fury, 你好!😁א").join();
const fury = new Fury(config);
const input = fury.serialize(str)
const result = fury.deserialize(
input
);
expect(result).toEqual(str)
});
});
4 changes: 2 additions & 2 deletions javascript/test/writer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
* under the License.
*/

import { OwnershipError } from '@furyjs/fury/lib/error';
import { BinaryWriter } from '@furyjs/fury/lib/writer';
import { OwnershipError } from '../packages/fury/lib/error';
import { BinaryWriter } from '../packages/fury/lib/writer';
import { describe, expect, test } from '@jest/globals';

describe('writer', () => {
Expand Down

0 comments on commit 5e89732

Please sign in to comment.