Skip to content

Commit

Permalink
chore: test all libs + all apps
Browse files Browse the repository at this point in the history
  • Loading branch information
elbywan authored and valpinkman committed May 17, 2022
1 parent a97107b commit 97d48df
Show file tree
Hide file tree
Showing 38 changed files with 249 additions and 131 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Test Libs
name: Test

on:
push:
Expand Down Expand Up @@ -48,8 +48,8 @@ jobs:
run: tzutil /s "Eastern Standard Time"
if: runner.os == 'Windows'
- name: Install dependencies
run: pnpm i --filter="!./apps" --no-frozen-lockfile
- name: Build and Test affected libraries
run: pnpm i
- name: Build and Test affected packages
run: pnpm test -- --since=origin/${{ github.event_name == 'pull_request' && github.event.pull_request.base.ref || github.event.inputs.since_branch || 'develop' }}
shell: bash
- name: (On Failure) Upload react-ui test results
Expand Down
9 changes: 9 additions & 0 deletions .pnpmfile.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,15 @@ function readPackage(pkg, context) {
kind: "peerDependencies",
}
),
addDependencies(
"eslint-plugin-jest",
{
"jest": "*",
},
{
kind: "peerDependencies",
}
),
],
pkg,
context
Expand Down
1 change: 1 addition & 0 deletions apps/ledger-live-desktop/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ module.exports = {
"react-hooks/exhaustive-deps": "warn", // Checks effect dependencies
"no-use-before-define": "off",
"@typescript-eslint/no-use-before-define": ["error"],
"flowtype/no-types-missing-file-annotation": 0,
},
},
],
Expand Down
2 changes: 2 additions & 0 deletions apps/ledger-live-desktop/.flowconfig
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ flow-defs
module.system.node.resolve_dirname=./src
module.system.node.resolve_dirname=node_modules
module.name_mapper='^~' ->'<PROJECT_ROOT>/src'
module.name_mapper='^@ledgerhq/react-ui/\(.*\)' ->'<PROJECT_ROOT>/../../libs/ui/packages/react/lib/\1'
munge_underscores=true
esproposal.optional_chaining=enable

Expand All @@ -31,3 +32,4 @@ esproposal.optional_chaining=enable
<PROJECT_ROOT>/node_modules/@ledgerhq/live-common/lib/partners/icons/react/*
<PROJECT_ROOT>/node_modules/@ledgerhq/live-common/lib/partners/react.jsarn
<PROJECT_ROOT>/node_modules/@ledgerhq/live-common/lib/apps/hw.js*
.*/libs/ledger-live-common/.*
4 changes: 4 additions & 0 deletions apps/ledger-live-desktop/flow-typed/exenv_v1.x.x.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
declare module "exenv" {
declare export default any;
declare export var canUseDOM: any;
}
3 changes: 3 additions & 0 deletions apps/ledger-live-desktop/flow-typed/memoize-one_v5.x.x.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
declare module "memoize-one" {
declare export default any;
}
16 changes: 16 additions & 0 deletions apps/ledger-live-desktop/flow-typed/npm/md5_v2.x.x.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// flow-typed signature: 198b480a6b35dbf3a74cb37d21258b00
// flow-typed version: c6154227d1/md5_v2.x.x/flow_>=v0.104.x

// @flow

declare module "md5" {
declare module.exports: (
message: string | Buffer,
options?: {
asString?: boolean,
asBytes?: boolean,
encoding?: string,
...
}
) => string;
}
38 changes: 38 additions & 0 deletions apps/ledger-live-desktop/flow-typed/npm/prop-types_v15.x.x.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// flow-typed signature: c93a723cbeb4d2f95d6a472157f6052f
// flow-typed version: 61b795e5b6/prop-types_v15.x.x/flow_>=v0.104.x

type $npm$propTypes$ReactPropsCheckType = (
props: any,
propName: string,
componentName: string,
href?: string
) => ?Error;

// Copied from: https://github.com/facebook/flow/blob/0938da8d7293d0077fbe95c3a3e0eebadb57b012/lib/react.js#L433-L449
declare module 'prop-types' {
declare var array: React$PropType$Primitive<Array<any>>;
declare var bool: React$PropType$Primitive<boolean>;
declare var func: React$PropType$Primitive<(...a: Array<any>) => mixed>;
declare var number: React$PropType$Primitive<number>;
declare var object: React$PropType$Primitive<{ +[string]: mixed, ... }>;
declare var string: React$PropType$Primitive<string>;
declare var symbol: React$PropType$Primitive<Symbol>;
declare var any: React$PropType$Primitive<any>;
declare var arrayOf: React$PropType$ArrayOf;
declare var element: React$PropType$Primitive<any>;
declare var elementType: React$PropType$Primitive<any>;
declare var instanceOf: React$PropType$InstanceOf;
declare var node: React$PropType$Primitive<any>;
declare var objectOf: React$PropType$ObjectOf;
declare var oneOf: React$PropType$OneOf;
declare var oneOfType: React$PropType$OneOfType;
declare var shape: React$PropType$Shape;

declare function checkPropTypes<V>(
propTypes: { [key: $Keys<V>]: $npm$propTypes$ReactPropsCheckType, ... },
values: V,
location: string,
componentName: string,
getStack: ?() => ?string
): void;
}
3 changes: 3 additions & 0 deletions apps/ledger-live-desktop/flow-typed/performance-now_v0.2.x.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
declare module "performance-now" {
declare export default any;
}
3 changes: 3 additions & 0 deletions apps/ledger-live-desktop/flow-typed/raf_v3.x.x.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
declare module "raf" {
declare export default any;
}
14 changes: 8 additions & 6 deletions apps/ledger-live-desktop/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"lint": "eslint src tools static --ext .js,.json,.ts,.tsx",
"prettier": "prettier --write \"{src,tools}/**/*.{js,json}\"",
"prettier:check": "prettier -c \"{src,tools}/**/*.{js,json}\"",
"flow-typed": "yarn run install-flow-typed",
"flow-typed": "pnpm install-flow-typed",
"install-flow-typed": "flow-typed install -s",
"preinstall-deps": "rimraf node_modules/paralleljs/package.json",
"install-deps": "electron-builder install-app-deps",
Expand All @@ -34,11 +34,12 @@
"build-ci": "cross-env STAGING=1 node ./tools/dist --ci -v",
"draft-release": "node ./tools/dist draft",
"release": "node ./tools/dist --publish -v",
"ci": "node ./tools/ci.js",
"test": "jest src",
"playwright": "nyc playwright test --config=tests/playwright.config.ts",
"playwright-update-snapshots": "yarn playwright --update-snapshots",
"playwright-recorder": "playwright test tests/specs/recorder.spec.ts"
"test": "pnpm test:jest && pnpm test:codecheck && pnpm test:playwright",
"test:codecheck": "node ./tools/ci.js",
"test:jest": "jest src --silent --ci --coverage --json --testLocationInResults --outputFile=report.json",
"test:playwright": "nyc playwright test --config=tests/playwright.config.ts",
"test:playwright:update-snapshots": "pnpm test:playwright --update-snapshots",
"test:playwright:recorder": "playwright test tests/specs/recorder.spec.ts"
},
"dependencies": {
"@electron/remote": "^1.2.1",
Expand Down Expand Up @@ -165,6 +166,7 @@
"@storybook/addon-links": "^6.3.12",
"@storybook/react": "^6.3.12",
"@types/react-router-dom": "^5.3.2",
"@types/react-select": "^4",
"@types/redux-actions": "^2.6.2",
"@typescript-eslint/eslint-plugin": "^5.12.1",
"@typescript-eslint/parser": "^5.12.1",
Expand Down
2 changes: 1 addition & 1 deletion apps/ledger-live-desktop/src/renderer/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ async function init() {
const libcoreVersion = await command("libcoreGetVersion")().toPromise();
logger.log("libcore", libcoreVersion);
} catch (error) {
logger.error(error)
logger.error(error);
}

window.addEventListener("keydown", (e: SyntheticKeyboardEvent<any>) => {
Expand Down
2 changes: 1 addition & 1 deletion apps/ledger-live-desktop/tools/ci.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const tasks = new Listr(
title: "Run flow",
task: async () => {
try {
const { stdout } = await execa("pnpm", ["flow"]);
const { stdout } = await execa("pnpm", ["flow", __dirname]);
return stdout;
} catch (error) {
process.stderr.write(error.message);
Expand Down
8 changes: 4 additions & 4 deletions apps/ledger-live-desktop/tools/dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,9 @@ const buildTasks = args => [
await exec("npm", ["run", ...commands], {
env: args.publish
? {
SENTRY_URL:
"https://[email protected]/274561",
}
SENTRY_URL:
"https://[email protected]/274561",
}
: {},
});
},
Expand Down Expand Up @@ -220,7 +220,7 @@ yargs
.command(
"check",
"Run health checks",
() => { },
() => {},
args => runTasks(healthChecksTasks, args),
)
.command(
Expand Down
16 changes: 12 additions & 4 deletions apps/ledger-live-desktop/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,29 @@
"isolatedModules": true,
"module": "commonjs",
"jsx": "react",
"lib": ["es6", "dom"],
"lib": [
"es6",
"dom"
],
"moduleResolution": "node",
"resolveJsonModule": true,
"strict": true,
"target": "esnext",
"baseUrl": ".",
"paths": {
"~/*": ["src/*"]
"~/*": [
"src/*"
]
},
"skipLibCheck": true,
"sourceMap": true,
"outDir": "tests/tests-out",
"rootDir": "./src"
},
"include": ["tests", "src/**/*"],
"include": [
"tests",
"src/**/*"
],
"exclude": [
"node_modules",
"babel.config.js",
Expand All @@ -30,4 +38,4 @@
"./scripts",
"./lib"
]
}
}
2 changes: 1 addition & 1 deletion apps/ledger-live-mobile/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
"prettier": "prettier --write \"src/**/*.js\"",
"lint": "eslint src --fix --ext .js,.json",
"flow": "flow",
"test": "pnpm lint --quiet",
"test": "pnpm lint --quiet && pnpm flow",
"sync-flowtyped": "NODE_OPTIONS=--max_old_space_size=10000 flow-typed install -s -o && rm flow-typed/npm/axios_*",
"sync-locales": "./scripts/sync-locales.sh",
"test-deep-links": "ws --spa ./deep-links-test-page.html"
Expand Down
6 changes: 3 additions & 3 deletions apps/ledger-live-mobile/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import React, {
useMemo,
useEffect,
} from "react";
import { connect, useDispatch, useSelector } from "react-redux";
import * as Sentry from "@sentry/react-native";
import { useDispatch, useSelector } from "react-redux";

import {
StyleSheet,
View,
Expand Down Expand Up @@ -99,7 +99,7 @@ checkLibs({
NotEnoughBalance,
React,
log,
Transport
Transport,
});

// useScreens();
Expand Down
5 changes: 5 additions & 0 deletions libs/ledgerjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
"name": "ledger-libs",
"private": true,
"version": "0.0.0",
"scripts": {
"test": "pnpm lint && pnpm test:jest",
"lint": "eslint packages/**/src --no-error-on-unmatched-pattern --ext .ts,.tsx -c .eslintrc.json",
"test:jest": "jest"
},
"devDependencies": {
"@types/jest": "^27.4.1",
"@typescript-eslint/eslint-plugin": "^4.33.0",
Expand Down
6 changes: 2 additions & 4 deletions libs/ledgerjs/packages/cryptoassets/src/currencies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1453,8 +1453,7 @@ const cryptocurrenciesById: Record<string, CryptoCurrency> = {
],
explorerViews: [
{
tx:
"https://www.kin.org/blockchainInfoPage/?&dataType=public&header=Transaction&id=$hash",
tx: "https://www.kin.org/blockchainInfoPage/?&dataType=public&header=Transaction&id=$hash",
address:
"https://www.kin.org/blockchainAccount/?&dataType=public&header=accountID&id=$address",
},
Expand Down Expand Up @@ -2211,8 +2210,7 @@ const cryptocurrenciesById: Record<string, CryptoCurrency> = {
units: ethereumUnits("SGB", "SGB"),
explorerViews: [
{
tx:
"https://songbird-explorer.flare.network/tx/$hash/internal-transactions",
tx: "https://songbird-explorer.flare.network/tx/$hash/internal-transactions",
address:
"https://songbird-explorer.flare.network/address/$address/transactions",
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// @flow
import { identifyTargetId } from "../src/";

import { identifyTargetId } from "../lib/";

test("check that known targetIds match known devices", () => {
const knownTargetIds = {
Expand Down
20 changes: 8 additions & 12 deletions libs/ledgerjs/packages/errors/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,8 @@ export const FirmwareNotRecognized = createCustomErrorClass(
export const HardResetFail = createCustomErrorClass("HardResetFail");
export const InvalidXRPTag = createCustomErrorClass("InvalidXRPTag");
export const InvalidAddress = createCustomErrorClass("InvalidAddress");
export const InvalidAddressBecauseDestinationIsAlsoSource = createCustomErrorClass(
"InvalidAddressBecauseDestinationIsAlsoSource"
);
export const InvalidAddressBecauseDestinationIsAlsoSource =
createCustomErrorClass("InvalidAddressBecauseDestinationIsAlsoSource");
export const LatestMCUInstalledError = createCustomErrorClass(
"LatestMCUInstalledError"
);
Expand Down Expand Up @@ -117,9 +116,8 @@ export const NotEnoughBalanceInParentAccount = createCustomErrorClass(
export const NotEnoughSpendableBalance = createCustomErrorClass(
"NotEnoughSpendableBalance"
);
export const NotEnoughBalanceBecauseDestinationNotCreated = createCustomErrorClass(
"NotEnoughBalanceBecauseDestinationNotCreated"
);
export const NotEnoughBalanceBecauseDestinationNotCreated =
createCustomErrorClass("NotEnoughBalanceBecauseDestinationNotCreated");
export const NoAccessToCamera = createCustomErrorClass("NoAccessToCamera");
export const NotEnoughGas = createCustomErrorClass("NotEnoughGas");
export const NotSupportedLegacyAddress = createCustomErrorClass(
Expand All @@ -128,12 +126,10 @@ export const NotSupportedLegacyAddress = createCustomErrorClass(
export const GasLessThanEstimate = createCustomErrorClass(
"GasLessThanEstimate"
);
export const PasswordsDontMatchError = createCustomErrorClass(
"PasswordsDontMatch"
);
export const PasswordIncorrectError = createCustomErrorClass(
"PasswordIncorrect"
);
export const PasswordsDontMatchError =
createCustomErrorClass("PasswordsDontMatch");
export const PasswordIncorrectError =
createCustomErrorClass("PasswordIncorrect");
export const RecommendSubAccountsToEmpty = createCustomErrorClass(
"RecommendSubAccountsToEmpty"
);
Expand Down
8 changes: 5 additions & 3 deletions libs/ledgerjs/packages/hw-app-btc/src/bip32.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@ export function pubkeyFromXpub(xpub: string): Buffer {
return xpubBuf.slice(xpubBuf.length - 33);
}

export function getXpubComponents(
xpub: string
): { chaincode: Buffer; pubkey: Buffer; version: number } {
export function getXpubComponents(xpub: string): {
chaincode: Buffer;
pubkey: Buffer;
version: number;
} {
const xpubBuf: Buffer = bs58check.decode(xpub);
return {
chaincode: xpubBuf.slice(13, 13 + 32),
Expand Down
10 changes: 2 additions & 8 deletions libs/ledgerjs/packages/hw-app-btc/src/getTrustedInput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,8 @@ export async function getTrustedInput(
transaction: Transaction,
additionals: Array<string> = []
): Promise<string> {
const {
version,
inputs,
outputs,
locktime,
nExpiryHeight,
extraData,
} = transaction;
const { version, inputs, outputs, locktime, nExpiryHeight, extraData } =
transaction;

if (!outputs || !locktime) {
throw new Error("getTrustedInput: locktime & outputs is expected");
Expand Down
Loading

0 comments on commit 97d48df

Please sign in to comment.