Skip to content

Commit

Permalink
Set up jest for testing and make small end-to-end test.
Browse files Browse the repository at this point in the history
  • Loading branch information
obi1kenobi committed Dec 5, 2024
1 parent d2c7714 commit ba76254
Show file tree
Hide file tree
Showing 16 changed files with 2,502 additions and 37 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/test_langsmith_nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ jobs:
path: "${{ env.RUST_WORKSPACE_PATH }}/${{ env.BINDINGS_RELATIVE_PATH }}/langsmith-nodejs.*.node"

test-macos-windows-bindings:
name: "Test bindings ${{ matrix.settings.target }} - node@${{ matrix.node }}"
name: "test node@${{ matrix.node }} on ${{ matrix.settings.target }}"
needs:
- build
strategy:
Expand Down Expand Up @@ -197,13 +197,13 @@ jobs:
shell: bash
run: |
# List downloaded bindings
ls -R .
ls .
# Run tests.
yarn test
test-linux-bindings:
name: Test bindings on ${{ matrix.settings.target }} - node@${{ matrix.node }}
name: test node@${{ matrix.node }} on ${{ matrix.settings.target }}
needs:
- build
strategy:
Expand Down Expand Up @@ -260,7 +260,7 @@ jobs:
shell: bash
run: |
# List downloaded bindings
ls -R "$BINDINGS_RELATIVE_PATH"
ls "$BINDINGS_RELATIVE_PATH/"
# Run tests.
docker run \
Expand Down
1 change: 1 addition & 0 deletions rust/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ resolver = "2"
chrono = "0.4.38"
flate2 = "1.0.34"
futures = "0.3.31"
napi = { version = "2.16.13", features = ["napi9", "serde-json"] }
napi = { version = "2.16.13", features = ["napi9", "serde-json", "async"] }
napi-derive = "2.16.13"
napi-build = "2.1.3"
rayon = "1.10.0"
Expand Down
2 changes: 1 addition & 1 deletion rust/crates/langsmith-nodejs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ const { loadBinding } = require('@node-rs/helper')
* `loadBinding` helper will load `langsmith-nodejs.[PLATFORM].node` from `__dirname` first
* If failed to load addon, it will fallback to load from `langsmith-nodejs-[PLATFORM]`
*/
module.exports = loadBinding(__dirname, 'langsmith-nodejs', 'langsmith-nodejs')
module.exports = loadBinding(__dirname, "langsmith-nodejs", "langsmith-nodejs");
13 changes: 13 additions & 0 deletions rust/crates/langsmith-nodejs/integration.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import * as lib from "./index.js";

describe("Bindings", () => {
it("should should minimally work", async () => {
expect(lib.fibonacci(1)).toBe(1);
expect(lib.fibonacci(2)).toBe(1);
expect(lib.fibonacci(3)).toBe(2);
expect(lib.fibonacci(4)).toBe(3);
expect(lib.fibonacci(5)).toBe(5);
expect(lib.fibonacci(6)).toBe(8);
});
});
7 changes: 7 additions & 0 deletions rust/crates/langsmith-nodejs/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/** @type {import('ts-jest').JestConfigWithTsJest} **/
module.exports = {
testEnvironment: "node",
transform: {
"^.+.tsx?$": ["ts-jest", {}],
},
};
4 changes: 2 additions & 2 deletions rust/crates/langsmith-nodejs/npm/darwin-arm64/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "langsmith-nodejs-darwin-arm64",
"version": "0.0.0",
"version": "0.1.0",
"os": [
"darwin"
],
Expand All @@ -15,4 +15,4 @@
"engines": {
"node": ">= 18"
}
}
}
3 changes: 0 additions & 3 deletions rust/crates/langsmith-nodejs/npm/darwin-x64/README.md

This file was deleted.

18 changes: 0 additions & 18 deletions rust/crates/langsmith-nodejs/npm/darwin-x64/package.json

This file was deleted.

4 changes: 2 additions & 2 deletions rust/crates/langsmith-nodejs/npm/linux-x64-gnu/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "langsmith-nodejs-linux-x64-gnu",
"version": "0.0.0",
"version": "0.1.0",
"os": [
"linux"
],
Expand All @@ -15,4 +15,4 @@
"engines": {
"node": ">= 18"
}
}
}
4 changes: 2 additions & 2 deletions rust/crates/langsmith-nodejs/npm/linux-x64-musl/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "langsmith-nodejs-linux-x64-musl",
"version": "0.0.0",
"version": "0.1.0",
"os": [
"linux"
],
Expand All @@ -15,4 +15,4 @@
"engines": {
"node": ">= 18"
}
}
}
4 changes: 2 additions & 2 deletions rust/crates/langsmith-nodejs/npm/win32-x64-msvc/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "langsmith-nodejs-win32-x64-msvc",
"version": "0.0.0",
"version": "0.1.0",
"os": [
"win32"
],
Expand All @@ -15,4 +15,4 @@
"engines": {
"node": ">= 18"
}
}
}
10 changes: 8 additions & 2 deletions rust/crates/langsmith-nodejs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,20 @@
"build": "napi build --platform --release",
"build:debug": "napi build --platform",
"prepublishOnly": "napi prepublish -t npm",
"test": "echo 'run tests here'",
"test": "jest",
"version": "napi version"
},
"dependencies": {
"@node-rs/helper": "^1.2.1"
},
"devDependencies": {
"@napi-rs/cli": "^1.0.0"
"@jest/globals": "^29.5.0",
"@napi-rs/cli": "^1.0.0",
"@tsconfig/recommended": "^1.0.8",
"@types/jest": "^29.5.14",
"jest": "^29.5.0",
"ts-jest": "^29.2.5",
"typescript": "^5.7.2"
},
"napi": {
"name": "langsmith-nodejs",
Expand Down
11 changes: 11 additions & 0 deletions rust/crates/langsmith-nodejs/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#[allow(unused_imports)]
use napi::bindgen_prelude::*;
use napi_derive::napi;

Check warning on line 4 in rust/crates/langsmith-nodejs/src/lib.rs

View workflow job for this annotation

GitHub Actions / Check lint and rustfmt

Diff in /home/runner/work/langsmith-sdk/langsmith-sdk/rust/crates/langsmith-nodejs/src/lib.rs
#[napi]
pub fn fibonacci(n: u32) -> u32 {
match n {
1 | 2 => 1,
_ => fibonacci(n - 1) + fibonacci(n - 2),
}
}
33 changes: 33 additions & 0 deletions rust/crates/langsmith-nodejs/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"extends": "@tsconfig/recommended",
"compilerOptions": {
"target": "ES2021",
"lib": [
"ES2021",
"ES2022.Object"
],
"module": "NodeNext",
"moduleResolution": "nodenext",
"esModuleInterop": true,
"declaration": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"useDefineForClassFields": true,
"strictPropertyInitialization": false,
"stripInternal": true,
"allowJs": true,
"strict": true,
"outDir": "dist"
},
"include": [
"src/**/*"
],
"exclude": [
"node_modules",
"dist",
"coverage"
],
"includeVersion": true
}
Loading

0 comments on commit ba76254

Please sign in to comment.