From 5e897321683c4f38b42bb6b635c77bf1473657ba Mon Sep 17 00:00:00 2001 From: weipeng Date: Wed, 24 Jan 2024 12:12:49 +0800 Subject: [PATCH] chore(JavaScript): Fix JavaScript test CI (#1355) 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 --- .github/workflows/ci.yml | 2 +- javascript/jest.config.js | 25 +++++--- javascript/package.json | 6 +- javascript/packages/fury/package.json | 6 +- javascript/test/reader.test.ts | 51 +++++++-------- javascript/test/string.test.ts | 91 ++++++++++++--------------- javascript/test/writer.test.ts | 4 +- 7 files changed, 87 insertions(+), 98 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 973358f430..df5ffb8ad0 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 }} diff --git a/javascript/jest.config.js b/javascript/jest.config.js index 7059d3bbf1..4b9f5e81a1 100644 --- a/javascript/jest.config.js +++ b/javascript/jest.config.js @@ -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: [ @@ -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: { @@ -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 + // } + // } }; \ No newline at end of file diff --git a/javascript/package.json b/javascript/package.json index e8c6b3df74..a0345c208e 100644 --- a/javascript/package.json +++ b/javascript/package.json @@ -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" } } diff --git a/javascript/packages/fury/package.json b/javascript/packages/fury/package.json index 9875851818..7283cd1900 100644 --- a/javascript/packages/fury/package.json +++ b/javascript/packages/fury/package.json @@ -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", diff --git a/javascript/test/reader.test.ts b/javascript/test/reader.test.ts index 0e0e6dc699..a707d3937d 100644 --- a/javascript/test/reader.test.ts +++ b/javascript/test/reader.test.ts @@ -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', () => { diff --git a/javascript/test/string.test.ts b/javascript/test/string.test.ts index a736f7925c..8093719638 100644 --- a/javascript/test/string.test.ts +++ b/javascript/test/string.test.ts @@ -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) + }); +}); diff --git a/javascript/test/writer.test.ts b/javascript/test/writer.test.ts index caf9e599ff..71d11c84e1 100644 --- a/javascript/test/writer.test.ts +++ b/javascript/test/writer.test.ts @@ -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', () => {