Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: standardize lodash-es usage across packages #265

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,15 @@ module.exports = {
},
env: {
browser: true,
node: true,
},
overrides: [
{
files: ["*.cjs"],
rules: {
"@typescript-eslint/no-var-requires": "off",
"@typescript-eslint/no-unsafe-assignment": "off"
}
}
]
};
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
"example": "cd ./packages/example && yarn dev",
"example-build": "cd ./packages/example && yarn --registry 'https://registry.npmjs.org' && yarn build",
"update-version": "lerna version --no-git-tag-version --exact",
"swap-lock-registry": "npx swap-lock-registry --yarn --parallel --url https://registry.yarnpkg.com yarn.lock"
"swap-lock-registry": "npx swap-lock-registry --yarn --parallel --url https://registry.yarnpkg.com yarn.lock",
"test:e2e": "cd ./packages/e2e && yarn test:headed",
"test:e2e:hub": "cd ./packages/providers/inpage-providers-hub && yarn test:headed"
},
"devDependencies": {
"@testing-library/react-hooks": "^7.0.2",
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/versionInfo.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

const version = '2.1.21';
const version = '2.1.23';
const versionBuild = '2020-0101-1';

export default {
Expand Down
4 changes: 4 additions & 0 deletions packages/e2e/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules/
test-results/
playwright-report/
playwright/.cache/
20 changes: 20 additions & 0 deletions packages/e2e/dotEnvInit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import dotenv from 'dotenv';
import path from 'path';
import { fileURLToPath } from 'url';

function setupDotEnv() {
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

const results = [
dotenv.config({
path: path.resolve(__dirname, '../../.env'),
}),
];
const errorResult = results.find((result) => result.error);

if (errorResult) {
throw errorResult.error;
}
}
setupDotEnv();
45 changes: 45 additions & 0 deletions packages/e2e/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
"private": true,
"name": "@onekeyfe/e2e",
"version": "2.1.23",
"keywords": [
"cross-inpage-provider"
],
"author": "[email protected]",
"repository": "https://github.com/OneKeyHQ/cross-inpage-provider",
"license": "Apache-2.0",
"publishConfig": {
"access": "public"
},
"type": "module",
"files": [
"dist/*"
],
"exports": {
"types": "./dist/index.d.ts",
"import": "./dist/index.js",
"require": "./dist/cjs/index.js"
},
"types": "./dist/index.d.ts",
"module": "./dist/index.js",
"main": "./dist/cjs/index.js",
"scripts": {
"env": "node dotEnvInit.js",
"report": "yarn env && npx playwright show-report",
"test": "yarn env && npx playwright test",
"test:headed": "yarn env && npx playwright test --headed && yarn report",
"test:ui": "yarn env && npx playwright test --ui"
},
"dependencies": {
"@onekeyfe/inpage-providers-hub": "2.1.23",
"@onekeyfe/cross-inpage-provider-injected": "2.1.23",
"@onekeyfe/cross-inpage-provider-types": "2.1.23",
"lodash-es": "^4.17.21"
},
"devDependencies": {
"@playwright/test": "^1.49.1",
"@types/lodash-es": "^4.17.12",
"@types/node": "^20.12.7",
"playwright": "^1.49.1"
}
}
22 changes: 22 additions & 0 deletions packages/e2e/playwright.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { defineConfig, devices } from '@playwright/test';

export default defineConfig({
testDir: './tests',
testMatch: ['**/*.e2e.ts', '**/*.e2e.js'],
fullyParallel: true,
forbidOnly: !!process.env.CI,
retries: process.env.CI ? 2 : 0,
workers: process.env.CI ? 1 : undefined,
reporter: 'html',
use: {
baseURL: 'http://localhost:3000',
trace: 'on-first-retry',
},
projects: [
{
name: 'chromium',
use: { ...devices['Desktop Chrome'] },
},
],
outputDir: 'test-results',
});
39 changes: 39 additions & 0 deletions packages/e2e/playwright2.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { defineConfig, devices } from '@playwright/test';

/**
* Read environment variables from file.
* https://github.com/motdotla/dotenv
*/
// require('dotenv').config();

/**
* See https://playwright.dev/docs/test-configuration.
*/
export default defineConfig({
testDir: './src',
testMatch: '*.spec.ts',
timeout: 1000 * 60,
fullyParallel: false,
forbidOnly: !!process.env.CI,
retries: 0,
workers: process.env.CI ? 1 : undefined,
reporter: [['html', { outputFolder: 'reports' }]],

use: {
screenshot: 'on',
trace: 'on',
// video: 'on',
},

projects: [
{
name: 'chromium',
use: { ...devices['Desktop Chrome'], viewport: { width: 1920, height: 800 } },
},

{
name: 'Mobile Chrome',
use: { ...devices['iPhone 6'] },
},
],
});
64 changes: 64 additions & 0 deletions packages/e2e/tests/bing.e2e.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// 在文件顶部添加这个声明
declare global {
interface Window {
$1key: {
hello: () => string;
};
}
}

import { expect, test } from '@playwright/test';

test.skip('Bing search test', async ({ page }) => {
// 打开 Bing
await page.goto('https://www.baidu.com');

// 等待搜索输入框出现并输入内容
const searchInput = page.locator('#kw');
await searchInput.fill('hemoglobin consists of click to select chainsmokers songs');
await searchInput.press('Enter');

// 等待搜索结果出现
await page.waitForSelector('.result.c-container.xpath-log.new-pmd');

// 获取第二个搜索结果
const secondResult = page.locator('.result.c-container.xpath-log.new-pmd').nth(1);

// 使用 evaluate 来高亮元素
await secondResult.evaluate((element) => {
element.style.backgroundColor = 'yellow';
element.style.border = '2px solid red';
});

const init1key = () => {
window.$1key = {
hello: () => 'world',
};
};

// 注入全局变量
await page.evaluate(init1key);

// 验证 $1key 全局变量存在
const hasOneKey = await page.evaluate(() => {
return window.$1key !== undefined;
});
expect(hasOneKey).toBe(true);

// 验证 $1key.hello 方法存在且可调用
const hasHelloMethod = await page.evaluate<string>(() => {
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call
const result = window.$1key ? window.$1key.hello() : '';
return result;
});
expect(hasHelloMethod).toBe('world');

// 截个图(可选)
await page.screenshot({ path: 'test-results/screenshots/bing-search.png' });

// 验证搜索结果存在
await expect(secondResult).toBeVisible();

// 设置浏览器在测试完成后保持打开状态
await page.pause();
});
37 changes: 37 additions & 0 deletions packages/e2e/tests/dapp.e2e.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import * as fs from 'fs';
import * as path from 'path';

import { connectButtonData } from '@onekeyfe/inpage-providers-hub';

const injectedCode = fs.readFileSync(
path.resolve(
'node_modules/@onekeyfe/cross-inpage-provider-injected/dist/injected/injectedNative.js',
),
'utf-8',
);

import { expect, test } from '@playwright/test';

test('dapp-test', async ({ page }) => {
console.log(connectButtonData.sitesConfig[0]);

// await page.goto('https://dapp-example.onekeytest.com');
// https://app.uniswap.org/
await page.goto('https://app.uniswap.org/');

// eval injectedCode
await page.evaluate(injectedCode);

// 验证 $onekey 全局变量存在
const hasOneKey = await page.evaluate(() => {
// @ts-ignore
return window.$onekey !== undefined;
});
expect(hasOneKey).toBe(true);

// 截个图(可选)
await page.screenshot({ path: 'test-results/screenshots/dapp-test.png' });

// 设置浏览器在测试完成后保持打开状态
await page.pause();
});
6 changes: 6 additions & 0 deletions packages/e2e/tests/example.e2e.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { test, expect } from '@playwright/test';

test.skip('basic test', async ({ page }) => {
await page.goto('https://example.walletconnect.org');
await expect(page).toHaveTitle(/React/);
});
11 changes: 11 additions & 0 deletions packages/e2e/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"baseUrl": ".",
"paths": {
"@/*": ["./src/*"]
}
},
"include": ["**/*.ts", "**/*.tsx", "dotEnvInit.js"],
"exclude": ["node_modules"]
}
58 changes: 58 additions & 0 deletions packages/e2e/yarn.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1


"@playwright/test@^1.49.1":
version "1.49.1"
resolved "https://registry.yarnpkg.com/@playwright/test/-/test-1.49.1.tgz#55fa360658b3187bfb6371e2f8a64f50ef80c827"
integrity sha512-Ky+BVzPz8pL6PQxHqNRW1k3mIyv933LML7HktS8uik0bUXNCdPhoS/kLihiO1tMf/egaJb4IutXd7UywvXEW+g==
dependencies:
playwright "1.49.1"

"@types/lodash-es@^4.17.12":
version "4.17.12"
resolved "https://registry.yarnpkg.com/@types/lodash-es/-/lodash-es-4.17.12.tgz#65f6d1e5f80539aa7cfbfc962de5def0cf4f341b"
integrity sha512-0NgftHUcV4v34VhXm8QBSftKVXtbkBG3ViCjs6+eJ5a6y6Mi/jiFGPc1sC7QK+9BFhWrURE3EOggmWaSxL9OzQ==
dependencies:
"@types/lodash" "*"

"@types/lodash@*":
version "4.17.13"
resolved "https://registry.yarnpkg.com/@types/lodash/-/lodash-4.17.13.tgz#786e2d67cfd95e32862143abe7463a7f90c300eb"
integrity sha512-lfx+dftrEZcdBPczf9d0Qv0x+j/rfNCMuC6OcfXmO8gkfeNAY88PgKUbvG56whcN23gc27yenwF6oJZXGFpYxg==

"@types/node@^20.12.7":
version "20.17.10"
resolved "https://registry.yarnpkg.com/@types/node/-/node-20.17.10.tgz#3f7166190aece19a0d1d364d75c8b0b5778c1e18"
integrity sha512-/jrvh5h6NXhEauFFexRin69nA0uHJ5gwk4iDivp/DeoEua3uwCUto6PC86IpRITBOs4+6i2I56K5x5b6WYGXHA==
dependencies:
undici-types "~6.19.2"

[email protected]:
version "2.3.2"
resolved "https://registry.yarnpkg.com/fsevents/-/fsevents-2.3.2.tgz#8a526f78b8fdf4623b709e0b975c52c24c02fd1a"
integrity sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==

lodash-es@^4.17.21:
version "4.17.21"
resolved "https://registry.yarnpkg.com/lodash-es/-/lodash-es-4.17.21.tgz#43e626c46e6591b7750beb2b50117390c609e3ee"
integrity sha512-mKnC+QJ9pWVzv+C4/U3rRsHapFfHvQFoFB92e52xeyGMcX6/OlIl78je1u8vePzYZSkkogMPJ2yjxxsb89cxyw==

[email protected]:
version "1.49.1"
resolved "https://registry.yarnpkg.com/playwright-core/-/playwright-core-1.49.1.tgz#32c62f046e950f586ff9e35ed490a424f2248015"
integrity sha512-BzmpVcs4kE2CH15rWfzpjzVGhWERJfmnXmniSyKeRZUs9Ws65m+RGIi7mjJK/euCegfn3i7jvqWeWyHe9y3Vgg==

[email protected], playwright@^1.49.1:
version "1.49.1"
resolved "https://registry.yarnpkg.com/playwright/-/playwright-1.49.1.tgz#830266dbca3008022afa7b4783565db9944ded7c"
integrity sha512-VYL8zLoNTBxVOrJBbDuRgDWa3i+mfQgDTrL8Ah9QXZ7ax4Dsj0MSq5bYgytRnDVVe+njoKnfsYkH3HzqVj5UZA==
dependencies:
playwright-core "1.49.1"
optionalDependencies:
fsevents "2.3.2"

undici-types@~6.19.2:
version "6.19.8"
resolved "https://registry.yarnpkg.com/undici-types/-/undici-types-6.19.8.tgz#35111c9d1437ab83a7cdc0abae2f26d88eda0a02"
integrity sha512-ve2KP6f/JnbPBFyobGHuerC9g1FYGn/F8n1LWTwNxCEzd6IfqTwUQcNXgEtmmQ6DlRrC1hrSrBnCZPokRrDHjw==
4 changes: 3 additions & 1 deletion packages/example/server/wrappers/walletsData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@ export function tryParsePublicKey(stateInit: StateInit): Buffer | null {
if (wallet.init.code.equals(stateInit.code)) {
return loadData(stateInit.data.beginParse()).publicKey;
}
} catch (e) {}
} catch (e) {
// ignore
}
}

return null;
Expand Down
4 changes: 4 additions & 0 deletions packages/injected/webpack.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ const commonConfig = {
// secp256k1 required in @solana/web3.js index.iife.js
// './precomputed/secp256k1': path.resolve(__dirname, 'development/resolveAlias/secp256k1-mock'),
// '@solana/web3.js': path.resolve(__dirname, 'development/resolveAlias/@solana-web3'),
tronweb: path.resolve(
__dirname,
'node_modules/@onekeyfe/inpage-providers-hub/node_modules/@onekeyfe/onekey-tron-provider/node_modules/tronweb/dist/TronWeb.js',
),
},
extensions: ['.js', '.jsx', '.ts', '.tsx', '.d.ts'],
fallback: {
Expand Down
3 changes: 3 additions & 0 deletions packages/providers/inpage-providers-hub/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"prebuild": "rm -rf dist",
"build": "tsc && tsc --project tsconfig.cjs.json",
"test": "npx playwright test",
"test:headed": "npx playwright test --headed",
"test:report": "npx playwright show-report reports",
"start": "tsc --watch"
},
Expand All @@ -50,10 +51,12 @@
"@onekeyfe/onekey-ton-provider": "2.1.23",
"@onekeyfe/onekey-tron-provider": "2.1.23",
"@onekeyfe/onekey-webln-provider": "2.1.23",
"lodash-es": "^4.17.21",
"web3": "^1.7.3"
},
"devDependencies": {
"@playwright/test": "^1.43.1",
"@types/lodash-es": "^4.17.12",
"@types/node": "^20.12.7",
"playwright": "^1.43.1"
}
Expand Down
Loading
Loading