Skip to content

Commit

Permalink
Add node test for checking exported symbols (#2835)
Browse files Browse the repository at this point in the history
* Add node test for checking exported symbols

Signed-off-by: Prateek Kumar <[email protected]>
  • Loading branch information
prateek-kumar-improving authored Feb 7, 2025
1 parent e651fdb commit 3a4d7dc
Show file tree
Hide file tree
Showing 14 changed files with 331 additions and 83 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/build-node-wrapper/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,11 @@ runs:
rm -rf node_modules && rm -rf package-lock.json && npm install
cd rust-client
rm -rf node_modules && rm -rf package-lock.json && npm install
- name: npm install for /npm/glide package
shell: bash
working-directory: ./node/npm/glide
run: |
rm -rf node_modules && rm -rf package-lock.json && npm install
- name: Build
shell: bash
working-directory: ./node
Expand Down
24 changes: 24 additions & 0 deletions .github/workflows/node-create-package-file/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,27 @@ runs:
envsubst < package.json.tmpl > "package.json"
cat package.json
echo $(ls *json*)
- name: Create package.json file in npm/glide package
shell: bash
working-directory: ./node/npm/glide
run: |
name="valkey-glide"
export node_os="${{ inputs.named_os }}"
export node_arch="${{ inputs.arch }}"
echo "The workflow is: ${{env.EVENT_NAME}}"
if ${{ env.EVENT_NAME == 'workflow_dispatch' }}; then
R_VERSION="${{ env.INPUT_VERSION }}"
else
R_VERSION=${GITHUB_REF:11}
fi
echo "RELEASE_VERSION=${R_VERSION}" >> $GITHUB_ENV
export package_version=${R_VERSION}
export scope=`if [ "${{ inputs.npm_scope }}" != '' ]; then echo "${{ inputs.npm_scope }}/"; fi`
export MUSL_FLAG=`if [[ "${{ inputs.target }}" =~ .*"musl".* ]]; then echo "-musl"; fi`
export pkg_name="${name}-${node_os}${MUSL_FLAG}-${node_arch}"
export dev_dependency_name="${scope}${pkg_name}"
# Create package.json and append devDependency
mv package.json package.json.tmpl
envsubst < package.json.tmpl > "package.json"
jq --arg dev_dependency_name "$dev_dependency_name" --arg path "../.." '.devDependencies += {($dev_dependency_name): $path}' package.json > package.tmpl.json && mv package.tmpl.json package.json
cat package.json
44 changes: 22 additions & 22 deletions node/DEVELOPER.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ Software Dependencies

If your Nodejs version is below the supported version specified in the client's [documentation](https://github.com/valkey-io/valkey-glide/blob/main/node/README.md#nodejs-supported-version), you can upgrade it using [NVM](https://github.com/nvm-sh/nvm?tab=readme-ov-file#install--update-script).

- npm
- git
- GCC
- pkg-config
- protoc (protobuf compiler)
- openssl
- openssl-dev
- rustup
- npm
- git
- GCC
- pkg-config
- protoc (protobuf compiler)
- openssl
- openssl-dev
- rustup

**Dependencies installation for Ubuntu**

Expand Down Expand Up @@ -107,16 +107,16 @@ Before starting this step, make sure you've installed all software requirments.
5. Integrating the built GLIDE package into your project:
Add the package to your project using the folder path with the command `npm install <path to GLIDE>/node`.
- For a fast build, execute `npm run build`. This will perform a full, unoptimized build, which is suitable for developing tests. Keep in mind that performance is significantly affected in an unoptimized build, so it's required to build with the `build:release` or `build:benchmark` option when measuring performance.
- If your modifications are limited to the TypeScript code, run `npm run build-external` to build the external package without rebuilding the internal package.
- If your modifications are limited to the Rust code, execute `npm run build-internal` to build the internal package and generate TypeScript code.
- To generate Node's protobuf files, execute `npm run build-protobuf`. Keep in mind that protobuf files are generated as part of full builds (e.g., `build`, `build:release`, etc.).
- For a fast build, execute `npm run build`. This will perform a full, unoptimized build, which is suitable for developing tests. Keep in mind that performance is significantly affected in an unoptimized build, so it's required to build with the `build:release` or `build:benchmark` option when measuring performance.
- If your modifications are limited to the TypeScript code, run `npm run build-external` to build the external package without rebuilding the internal package.
- If your modifications are limited to the Rust code, execute `npm run build-internal` to build the internal package and generate TypeScript code.
- To generate Node's protobuf files, execute `npm run build-protobuf`. Keep in mind that protobuf files are generated as part of full builds (e.g., `build`, `build:release`, etc.).
> Note: Once building completed, you'll find the compiled JavaScript code in the `node/build-ts` folder.

### Troubleshooting

- If the build fails after running `npx tsc` because `glide-rs` isn't found, check if your npm version is in the range 9.0.0-9.4.1, and if so, upgrade it. 9.4.2 contains a fix to a change introduced in 9.0.0 that is required in order to build the library.
- If the build fails after running `npx tsc` because `glide-rs` isn't found, check if your npm version is in the range 9.0.0-9.4.1, and if so, upgrade it. 9.4.2 contains a fix to a change introduced in 9.0.0 that is required in order to build the library.
### Test
Expand Down Expand Up @@ -202,13 +202,13 @@ Development on the Node wrapper may involve changes in either the TypeScript or
**TypeScript:**
- ESLint
- Prettier
- ESLint
- Prettier
**Rust:**
- clippy
- fmt
- clippy
- fmt
#### Running the linters
Expand All @@ -231,8 +231,8 @@ Development on the Node wrapper may involve changes in either the TypeScript or
### Recommended extensions for VS Code
- [Prettier - Code formatter](https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode) - JavaScript / TypeScript formatter.
- [ESLint](https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint) - linter.
- [Jest Runner](https://marketplace.visualstudio.com/items?itemName=firsttris.vscode-jest-runner) - in-editor test runner.
- [Jest Test Explorer](https://marketplace.visualstudio.com/items?itemName=kavod-io.vscode-jest-test-adapter) - adapter to the VSCode testing UI.
- [rust-analyzer](https://marketplace.visualstudio.com/items?itemName=rust-lang.rust-analyzer) - Rust language support for VSCode.
- [Prettier - Code formatter](https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode) - JavaScript / TypeScript formatter.
- [ESLint](https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint) - linter.
- [Jest Runner](https://marketplace.visualstudio.com/items?itemName=firsttris.vscode-jest-runner) - in-editor test runner.
- [Jest Test Explorer](https://marketplace.visualstudio.com/items?itemName=kavod-io.vscode-jest-test-adapter) - adapter to the VSCode testing UI.
- [rust-analyzer](https://marketplace.visualstudio.com/items?itemName=rust-lang.rust-analyzer) - Rust language support for VSCode.
8 changes: 4 additions & 4 deletions node/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@ The release of Valkey GLIDE was tested on the following platforms:

Linux:

- Ubuntu 22.04.1 (x86_64 and aarch64)
- Amazon Linux 2023 (AL2023) (x86_64)
- Ubuntu 22.04.1 (x86_64 and aarch64)
- Amazon Linux 2023 (AL2023) (x86_64)

macOS:

- macOS 14.7 (Apple silicon/aarch_64)
- macOS 14.7 (Apple silicon/aarch_64)

Alpine:

- node:alpine (default on aarch64 and x86_64)
- node:alpine (default on aarch64 and x86_64)

## NodeJS supported version

Expand Down
70 changes: 18 additions & 52 deletions node/npm/glide/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,71 +4,37 @@
* Copyright Valkey GLIDE Project Contributors - SPDX Identifier: Apache-2.0
*/

import { GLIBC, MUSL, familySync } from "detect-libc";
import { GLIBC, familySync } from "detect-libc";
import { arch, platform } from "process";

let globalObject = global as unknown;

/* eslint-disable @typescript-eslint/no-require-imports */
function loadNativeBinding() {
let nativeBinding = null;
let nativeStr = process.env.native_binding;

switch (platform) {
case "linux":
switch (arch) {
case "x64":
switch (familySync()) {
case GLIBC:
nativeBinding = require("@scope/valkey-glide-linux-x64");
break;
case MUSL:
nativeBinding = require("@scope/valkey-glide-linux-musl-x64");
break;
default:
nativeBinding = require("@scope/valkey-glide-linux-x64");
break;
}
if (nativeStr == undefined) {
const prefix = familySync() == GLIBC ? "" : "-musl";
nativeStr = `${platform}${prefix}-${arch}`;

break;
case "arm64":
switch (familySync()) {
case GLIBC:
nativeBinding = require("@scope/valkey-glide-linux-arm64");
break;
case MUSL:
nativeBinding = require("@scope/valkey-glide-linux-musl-arm64");
break;
default:
nativeBinding = require("@scope/valkey-glide-linux-arm64");
break;
}

break;
default:
throw new Error(
`Unsupported OS: ${platform}, architecture: ${arch}`,
);
}

break;
case "darwin":
switch (arch) {
case "arm64":
nativeBinding = require("@scope/valkey-glide-darwin-arm64");
break;
default:
throw new Error(
`Unsupported OS: ${platform}, architecture: ${arch}`,
);
}

break;
default:
if (
!["x64", "arm64"].includes(arch) ||
!["linux", "darwin"].includes(platform)
) {
throw new Error(
`Unsupported OS: ${platform}, architecture: ${arch}`,
);
}
}

let scope = process.env.scope || "@scope";

if (scope == "@scope") {
scope = "@valkey/";
}

const nativeBinding = require(`${scope}valkey-glide-${nativeStr}`);

if (!nativeBinding) {
throw new Error(`Failed to load native binding`);
}
Expand Down
32 changes: 32 additions & 0 deletions node/npm/glide/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/* eslint no-undef: off */
module.exports = {
preset: "ts-jest",
transform: {
"^.+\\.(t|j)s$": ["ts-jest", { isolatedModules: true }],
},
testEnvironment: "node",
testRegex: "/tests/.*\\.(test|spec)?\\.(ts|tsx)$",
moduleFileExtensions: [
"ts",
"tsx",
"js",
"jsx",
"json",
"node",
"cjs",
"mjs",
],
testTimeout: 600000,
reporters: [
"default",
[
"./node_modules/jest-html-reporter",
{
includeFailureMsg: true,
includeSuiteFailure: true,
executionTimeWarningThreshold: 60,
sort: "status",
},
],
],
};
7 changes: 6 additions & 1 deletion node/npm/glide/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "${scope}${pkg_name}",
"name": "valkey-glide",
"types": "build-ts/index.d.ts",
"version": "${package_version}",
"description": "General Language Independent Driver for the Enterprise (GLIDE) for Valkey",
Expand Down Expand Up @@ -33,6 +33,11 @@
},
"homepage": "https://github.com/valkey-io/valkey-glide#readme",
"devDependencies": {
"@jest/globals": "^29.7.0",
"@types/jest": "^29.5.14",
"ts-jest": "^29.2.5",
"jest": "^29.7.0",
"jest-html-reporter": "^3.10.2",
"@types/node": "^18.11.18",
"@typescript-eslint/eslint-plugin": "^5.48.0",
"@typescript-eslint/parser": "^5.48.0",
Expand Down
Loading

0 comments on commit 3a4d7dc

Please sign in to comment.