Skip to content

Commit

Permalink
Merge pull request #4 from LedgerHQ/feature/DSDK-67-setup-jest
Browse files Browse the repository at this point in the history
[DSDK-67] Setup unit test
  • Loading branch information
jdabbech-ledger authored Jan 17, 2024
2 parents 2c443d1 + a41c52a commit 1d8aca8
Show file tree
Hide file tree
Showing 19 changed files with 1,832 additions and 202 deletions.
33 changes: 12 additions & 21 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,19 @@ jobs:
steps:
- uses: actions/checkout@v3

- name: Install Node.js
uses: actions/setup-node@v3
with:
node-version: 18
- uses: ./actions/setup-toolchain-composite

- uses: pnpm/action-setup@v2
name: Install pnpm

- name: Get pnpm store directory
run: |
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
- name: Lint
run: pnpm lint

- uses: actions/cache@v3
name: Setup pnpm cache
with:
path: ${{ env.STORE_PATH }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-
test:
runs-on: [device-sdk-4xlarge-linux]
env:
CI_JOB_NUMBER: 1
steps:
- uses: actions/checkout@v3

- name: Install dependencies
run: pnpm install
- uses: ./actions/setup-toolchain-composite

- name: Lint
run: pnpm lint
- name: Test
run: pnpm test
89 changes: 88 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,88 @@
Ledger Device SDK
<p align="center">
<img src="https://user-images.githubusercontent.com/9203826/154288895-670f5c23-81a1-4307-a080-1af83f7f8356.svg" align="center" alt="Ledger" />
<h2 align="center">Web Device SDK</h2>
<p align="center">
<!-- Update with each individual package version -->
<!-- Enable and display when CI set up -->
<!-- <a href="https://github.com/LedgerHQ/platform-sdk/actions">
<img alt="Tests Passing" src="https://github.com/LedgerHQ/platform-sdk/workflows/CI/badge.svg" />
</a> -->
<a href="https://www.typescriptlang.org/">
<img alt="TypeScript" src="https://img.shields.io/badge/TypeScript-007ACC?style=for-the-badge&logo=typescript&logoColor=white" />
</a>
<a href="https://eslint.org/">
<img alt="ESlint" src="https://img.shields.io/badge/eslint-3A33D1?style=for-the-badge&logo=eslint&logoColor=white" />
</a>
<a href="https://prettier.io/">
<img alt="Prettier" src="https://img.shields.io/badge/prettier-1A2C34?style=for-the-badge&logo=prettier&logoColor=F7BA3E" />
</a>
<a href="https://jestjs.io/">
<img alt="Jest" src="https://img.shields.io/badge/Jest-323330?style=for-the-badge&logo=Jest&logoColor=white" />
</a>
<br />
<a href="https://nextjs.org/">
<img alt="NextJs" src="https://img.shields.io/badge/Next.js-000?logo=nextdotjs&logoColor=fff&style=for-the-badge" />
</a>
<a href="https://vercel.com/">
<img alt="Vercel" src="https://img.shields.io/badge/Vercel-000000?style=for-the-badge&logo=vercel&logoColor=white" />
</a>
<a href="https://www.npmjs.com/">
<img alt="NPM" src="https://img.shields.io/badge/npm-CB3837?style=for-the-badge&logo=npm&logoColor=white" />
</a>
</p>

<p align="center">
<a href="https://developers.ledger.com/docs/live-app/start-here/">Ledger Developer Portal</a>
·
<a href="https://github.com/LedgerHQ/device-sdk-ts/issues/new/choose">Report Bug</a>
·
<a href="https://github.com/LedgerHQ/device-sdk-ts/issues/new/choose">Request Feature</a>
</p>
<!-- Also add monorepo docuzaurus doc when available -->
</p>

# About

This monorepo hosts the Device SDK for Web.
Written in Typescript.


# How does it works

The Device SDK defines an interface for applications to interact with Ledger wallets.

```mermaid
flowchart LR;
application(Application) <--JSON-RPC--> wallet(Wallet);
```

<!-- TODO: link to reference implementations of client and server once available -->


# Modules description

This project uses [turbo monorepo](https://turbo.build/repo/docs) to build and release different packages on NPM registry and a sample demo app on Vercel.

A brief description of this project packages:

* `@ledgerhq/device-sdk-sample` in `apps/sample`: React Next web app used to test & demonstrate the Web Device SDK
* `@ledgerhq/eslint-config-dsdk` in `packages/config/eslint`: internal package which contains eslint shared config. Used by `extends: ["@ledgerhq/dsdk"]` in `.eslintrc`.
* `@ledgerhq/jest-config-dsdk` in `packages/config/jest`: internal package which contains jest shared config. Used by `preset: "@ledgerhq/jest-config-dsdk"` in `jest.config.ts`
* `@ledgerhq/tsconfig-dsdk` in `packages/config/typescript`: internal package which contains typescript shared config. Used by `"extends": "@ledgerhq/tsconfig-dsdk/sdk"` in `tsconfig.json`
* `@ledgerhq/device-sdk-core` in `packages/core`: external package that contains the core of the Web SDK
* `@ledgerhq/device-sdk-signer` in `packages/signer`: external package
* `@ledgerhq/device-sdk-trusted-apps` in `packages/trusted-apps`: external package
* `@ledgerhq/device-sdk-ui` in `packages/ui`: external package


# CI

This project uses Github CI.


# Scripting

In order to avoid task repetition, we can add some scripts the corresponding package's script folder, on in a root script folder if it concerns multiple packages.
A script is a `.mjs` file interpreted by [zx](https://github.com/google/zx).


30 changes: 30 additions & 0 deletions actions/setup-toolchain-composite/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: "Setup Device SDK toolchain"
description: "Composite job to setup the CI tools for Device SDK"

runs:
using: "composite"
steps:
- name: Install Node.js
uses: actions/setup-node@v3
with:
node-version: 18

- uses: pnpm/action-setup@v2
name: Install pnpm

- name: Get pnpm store directory
shell: bash
run: |
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
- uses: actions/cache@v3
name: Setup pnpm cache
with:
path: ${{ env.STORE_PATH }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-
- name: Install dependencies
shell: bash
run: pnpm install
19 changes: 10 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,25 @@
"apps/*"
],
"scripts": {
"build": "turbo build",
"dev": "turbo dev",
"lint": "turbo run lint",
"lint:fix": "turbo run lint:fix",
"build": "turbo build --log-order=grouped",
"dev": "turbo dev --log-order=grouped",
"lint": "turbo run lint --log-order=grouped",
"lint:fix": "turbo run lint:fix --log-order=grouped",
"test": "turbo run test --log-order=grouped",
"core": "pnpm --filter @ledgerhq/device-sdk-core",
"signer": "pnpm --filter @ledgerhq/device-sdk-signer",
"trusted-apps": "pnpm --filter @ledgerhq/device-sdk-trusted-apps",
"ui": "pnpm --filter @ledgerhq/device-sdk-ui",
"sample": "pnpm --filter @ledgerhq/device-sdk-sample",
"test": "echo \"Error: no test specified\" && exit 1"
"sample": "pnpm --filter @ledgerhq/device-sdk-sample"
},
"devDependencies": {
"@ledgerhq/eslint-config-dsdk": "workspace:*",
"@ledgerhq/tsconfig-dsdk": "workspace:*",
"@types/jest": "^29.5.11",
"@types/node": "^20.10.6",
"eslint": "^8.56.0",
"jest": "^29.7.0",
"lint-staged": "^15.2.0",
"prettier": "^3.1.1",
"turbo": "^1.11.2",
"eslint": "^8.56.0",
"typescript": "^5.3.3",
"zx": "^7.2.3"
},
Expand Down
9 changes: 9 additions & 0 deletions packages/config/jest/jest-preset.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/** @type {import('jest').Config} */
const config = {
preset: "ts-jest",
transform: {
"^.+\\.ts$": "ts-jest",
},
};

module.exports = config;
11 changes: 11 additions & 0 deletions packages/config/jest/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "@ledgerhq/jest-config-dsdk",
"version": "1.0.0",
"main": "jest-preset.js",
"types": "node_modules/ts-jest/dist/index.d.ts",
"private": true,
"devDependencies": {
"ts-jest": "^29.1.1",
"ts-node": "^10.9.2"
}
}
1 change: 0 additions & 1 deletion packages/config/typescript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
"devDependencies": {
"@tsconfig/recommended": "^1.0.3",
"@types/eslint": "^8.44.9",
"@types/node": "^20",
"@types/react": "^18",
"@types/react-dom": "^18"
}
Expand Down
2 changes: 1 addition & 1 deletion packages/config/typescript/sdk.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"compilerOptions": {
"target": "esnext",
"lib": ["esnext", "dom"],
"types": ["reflect-metadata"],
"types": ["reflect-metadata", "jest", "node"],
"sourceMap": true,
"declaration": true,
"declarationMap": true,
Expand Down
7 changes: 7 additions & 0 deletions packages/core/jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import type { JestConfigWithTsJest } from "@ledgerhq/jest-config-dsdk";

const config: JestConfigWithTsJest = {
preset: "@ledgerhq/jest-config-dsdk",
};

export default config;
5 changes: 3 additions & 2 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@
"lint": "eslint --cache --ext .ts \"src\"",
"lint:fix": "eslint --cache --fix --ext .ts \"src\"",
"feature": "zx scripts/add-feature.mjs",
"test": "echo \"Error: no test specified\" && exit 1"
"test": "jest --passWithNoTests"
},
"dependencies": {
"inversify": "^6.0.2",
"reflect-metadata": "^0.2.1"
},
"devDependencies": {
"@ledgerhq/eslint-config-dsdk": "workspace:*",
"@ledgerhq/tsconfig-dsdk": "workspace:*"
"@ledgerhq/tsconfig-dsdk": "workspace:*",
"@ledgerhq/jest-config-dsdk": "workspace:*"
}
}
7 changes: 7 additions & 0 deletions packages/signer/jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import type { JestConfigWithTsJest } from "@ledgerhq/jest-config-dsdk";

const config: JestConfigWithTsJest = {
preset: "@ledgerhq/jest-config-dsdk",
};

export default config;
5 changes: 3 additions & 2 deletions packages/signer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@
"dev": "tsc --watch",
"lint": "eslint --cache --ext .ts \"src\"",
"lint:fix": "eslint --cache --fix --ext .ts \"src\"",
"test": "echo \"Error: no test specified\" && exit 1"
"test": "jest --passWithNoTests"
},
"dependencies": {
"inversify": "^6.0.2",
"reflect-metadata": "^0.2.1"
},
"devDependencies": {
"@ledgerhq/tsconfig-dsdk": "workspace:*",
"@ledgerhq/eslint-config-dsdk": "workspace:*"
"@ledgerhq/eslint-config-dsdk": "workspace:*",
"@ledgerhq/jest-config-dsdk": "workspace:*"
}
}
7 changes: 7 additions & 0 deletions packages/signer/tests/index.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { Hello } from "../src";

describe("signer", () => {
it("should be Hello World", () => {
expect(Hello).toEqual("World");
});
});
7 changes: 7 additions & 0 deletions packages/trusted-apps/jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import type { JestConfigWithTsJest } from "@ledgerhq/jest-config-dsdk";

const config: JestConfigWithTsJest = {
preset: "@ledgerhq/jest-config-dsdk",
};

export default config;
5 changes: 3 additions & 2 deletions packages/trusted-apps/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@
"lint": "eslint --cache --ext .ts \"src\"",
"lint:fix": "eslint --cache --fix --ext .ts \"src\"",
"dev": "tsc --watch",
"test": "echo \"Error: no test specified\" && exit 1"
"test": "jest --passWithNoTests"
},
"dependencies": {
"inversify": "^6.0.2",
"reflect-metadata": "^0.2.1"
},
"devDependencies": {
"@ledgerhq/tsconfig-dsdk": "workspace:*",
"@ledgerhq/eslint-config-dsdk": "workspace:*"
"@ledgerhq/eslint-config-dsdk": "workspace:*",
"@ledgerhq/jest-config-dsdk": "workspace:*"
}
}
7 changes: 7 additions & 0 deletions packages/ui/jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import type { JestConfigWithTsJest } from "@ledgerhq/jest-config-dsdk";

const config: JestConfigWithTsJest = {
preset: "@ledgerhq/jest-config-dsdk",
};

export default config;
5 changes: 3 additions & 2 deletions packages/ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@
"dev": "tsc --watch",
"lint": "eslint --cache --ext .ts \"src\"",
"lint:fix": "eslint --cache --fix --ext .ts \"src\"",
"test": "echo \"Error: no test specified\" && exit 1"
"test": "jest --passWithNoTests"
},
"dependencies": {
"inversify": "^6.0.2",
"reflect-metadata": "^0.2.1"
},
"devDependencies": {
"@ledgerhq/tsconfig-dsdk": "workspace:*",
"@ledgerhq/eslint-config-dsdk": "workspace:*"
"@ledgerhq/eslint-config-dsdk": "workspace:*",
"@ledgerhq/jest-config-dsdk": "workspace:*"
}
}
Loading

0 comments on commit 1d8aca8

Please sign in to comment.