Skip to content

Commit 1b6ab88

Browse files
committed
updates tests to config.json + fix build module types
1 parent 0443d0c commit 1b6ab88

13 files changed

+73
-40
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
node_modules/
1+
node_modules/
2+
dist/

package.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
{
22
"name": "@threefold/root",
3-
"private": true,
3+
"publishConfig": {
4+
"access": "public"
5+
},
6+
"private": false,
47
"workspaces": [
58
"packages/*"
69
],
@@ -21,6 +24,5 @@
2124
"prettier": "^3.5.1",
2225
"ts-node": "^10.9.2",
2326
"typescript": "^5.7.3"
24-
},
25-
"packageManager": "yarn@4.7.0"
27+
}
2628
}

packages/registrar_client/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ more example script can be found [here](./scripts/)
8585

8686
## Tests
8787

88-
before running tests make sure to set base url of the client in test file
88+
- Before running the tests set your base url in `tests/config.json`
8989

9090
then run with:
9191

packages/registrar_client/jest.config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1+
12
// jest.config.js
23
module.exports = {
34
preset: "ts-jest/presets/default-esm",
45
transform: {
5-
"^.+\\.(ts|tsx)$": ["ts-jest", { useESM: true }],
6+
"^.+\\.(ts|tsx)$": ["ts-jest", { useESM: true, tsconfig: "tsconfig-node.json" }],
67
},
78
extensionsToTreatAsEsm: [".ts", ".tsx"],
89
testEnvironment: "node",

packages/registrar_client/package.json

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,15 @@
55
"keywords": [],
66
"author": "Salma Elsoly <salmaelsoly@gmail.com>",
77
"license": "ISC",
8-
"main": "./dist/src/index.js",
9-
"types": "./dist/src/index.d.ts",
8+
"main": "./dist/node/src/index.js",
9+
"module": "./dist/es/src/index.js",
10+
"exports": {
11+
".": {
12+
"import": "./dist/es/src/index.js",
13+
"require": "./dist/node/src/index.js"
14+
}
15+
},
16+
"types": "./dist/es/src/index.d.ts",
1017
"engines": {
1118
"node": ">=20.10.0"
1219
},
@@ -15,7 +22,7 @@
1522
"test": "tests"
1623
},
1724
"files": [
18-
"dist"
25+
"/dist"
1926
],
2027
"repository": {
2128
"type": "git",
@@ -25,7 +32,9 @@
2532
"test": "jest",
2633
"format": "prettier --write .",
2734
"lint": "eslint src/**/*.ts",
28-
"build": "tsc"
35+
"lint:fix": "eslint src/**/*.ts --fix",
36+
"node-build": "tsc --build tsconfig-node.json",
37+
"es-build": "tsc --build tsconfig-es.json"
2938
},
3039
"bugs": {
3140
"url": "https://github.com/threefoldtech/tfgridv4-sdk-ts/issues"
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"baseUrl": "http://localhost:8080/v1"
3+
}

packages/registrar_client/tests/integration_tests/account.spec.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
import { describe, test, expect } from "@jest/globals";
2-
import tweetnacl from "tweetnacl";
3-
import base64 from "base64-js";
42
import { RegistrarClient } from "../../src/client/client";
53
import { UpdateAccountRequest } from "../../src/types/account";
6-
4+
import { generateKeypair } from "../utils";
5+
import config from "../config.json";
76
describe("test account module", () => {
8-
const keyPair = tweetnacl.sign.keyPair();
9-
const publicKey = base64.fromByteArray(keyPair.publicKey);
10-
const privateKey = base64.fromByteArray(keyPair.secretKey);
7+
const { publicKey, privateKey } = generateKeypair();
118

12-
const client = new RegistrarClient({ baseURL: "http://localhost:8080/v1", privateKey: privateKey });
9+
const client = new RegistrarClient({ baseURL: config.baseUrl, privateKey: privateKey });
1310

1411
let twinID = 1;
1512
test("create account", async () => {

packages/registrar_client/tests/integration_tests/farm.spec.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
import { describe, test, expect } from "@jest/globals";
2-
import tweetnacl from "tweetnacl";
3-
import base64 from "base64-js";
42
import { RegistrarClient } from "../../src/client/client";
3+
import { generateKeypair } from "../utils";
4+
import config from "../config.json";
55

66
describe("test farm module", () => {
7-
const keyPair = tweetnacl.sign.keyPair();
8-
const privateKey = base64.fromByteArray(keyPair.secretKey);
9-
10-
const client = new RegistrarClient({ baseURL: "http://localhost:8080/v1", privateKey: privateKey });
7+
const { privateKey } = generateKeypair();
8+
const client = new RegistrarClient({ baseURL: config.baseUrl, privateKey: privateKey });
119

1210
let twinID = 1;
1311
let farmID = 1;

packages/registrar_client/tests/integration_tests/node.spec.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
import { describe, test, expect } from "@jest/globals";
22
import { NodeRegistrationRequest, UptimeReportRequest, NodesFilter } from "../../src/types/node";
33
import { RegistrarClient } from "../../src/client/client";
4-
import tweetnacl from "tweetnacl";
5-
import base64 from "base64-js";
4+
import { generateKeypair } from "../utils";
5+
import config from "../config.json";
66

77
describe("test node module", () => {
8-
const keyPair = tweetnacl.sign.keyPair();
9-
const privateKey = base64.fromByteArray(keyPair.secretKey);
8+
const { privateKey } = generateKeypair();
109

11-
const client = new RegistrarClient({ baseURL: "http://localhost:8080/v1", privateKey: privateKey });
10+
const client = new RegistrarClient({ baseURL: config.baseUrl, privateKey: privateKey });
1211

1312
let twinID = 1;
1413
let nodeID = 1;

packages/registrar_client/tests/integration_tests/zos.spec.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
import { describe, test, expect } from "@jest/globals";
22
import { RegistrarClient } from "../../src/client/client";
3+
import { generateKeypair } from "../utils";
4+
import config from "../config.json";
35

46
describe("test zos module", () => {
5-
const client = new RegistrarClient({ baseURL: "https://registrar.dev4.grid.tf/v1", privateKey: "private_key" });
7+
const { privateKey } = generateKeypair();
8+
9+
const client = new RegistrarClient({ baseURL: config.baseUrl, privateKey: privateKey });
610

711
test("get zos version", async () => {
812
const zos = await client.zos.getZosVersion();
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import tweetnacl from 'tweetnacl';
2+
import base64 from 'base64-js';
3+
4+
export function generateKeypair() {
5+
const keyPair = tweetnacl.sign.keyPair();
6+
const publicKey = base64.fromByteArray(keyPair.publicKey);
7+
const privateKey = base64.fromByteArray(keyPair.secretKey);
8+
return { publicKey, privateKey };
9+
10+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"compilerOptions": {
3+
"target": "ESNext",
4+
"module": "esnext",
5+
"outDir": "./dist/es",
6+
"moduleResolution": "node",
7+
"resolveJsonModule": true,
8+
"esModuleInterop": true,
9+
"forceConsistentCasingInFileNames": true,
10+
"declaration": true,
11+
"strict": true,
12+
"skipLibCheck": true,
13+
},
14+
"include": ["./src", "scripts"],
15+
"exclude": ["./tests"]
16+
}

packages/registrar_client/tsconfig.json renamed to packages/registrar_client/tsconfig-node.json

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,14 @@
11
{
22
"compilerOptions": {
3-
/* Language and Environment */
4-
"target": "ESNext",
5-
"resolveJsonModule": true,
6-
7-
/* Modules */
3+
"target":"ESNext",
84
"module": "commonjs",
9-
/* Emit */
10-
11-
"outDir": "./dist",
5+
"outDir": "./dist/node",
6+
"resolveJsonModule": true,
127
"esModuleInterop": true,
138
"forceConsistentCasingInFileNames": true,
149
"declaration": true,
15-
16-
/* Type Checking */
1710
"strict": true,
18-
"skipLibCheck": true
11+
"skipLibCheck": true,
1912
},
2013
"include": ["./src", "scripts"],
2114
"exclude": ["./tests"]

0 commit comments

Comments
 (0)