From 10d7eaed809dde721b582d4b3228a48bbec50884 Mon Sep 17 00:00:00 2001 From: Pavel Date: Tue, 7 Mar 2023 20:07:52 +0400 Subject: [PATCH] feat(test): Automate smoke tests for JS Client [DXJ-293] (#282) --- package.json | 45 +- packages/@tests/aqua/src/index.ts | 10 +- packages/@tests/frameworks/cra-ts/src/App.tsx | 26 - .../@tests/frameworks/cra-ts/tsconfig.json | 26 - .../{smoke_node => smoke/node}/.gitignore | 0 .../{smoke_node => smoke/node}/package.json | 2 +- packages/@tests/smoke/node/src/index.ts | 4 + packages/@tests/smoke/node/tsconfig.json | 7 + .../cra-ts => smoke/web-cra-ts}/.gitignore | 0 .../cra-ts => smoke/web-cra-ts}/README.md | 0 .../cra-ts => smoke/web-cra-ts}/package.json | 6 +- .../web-cra-ts}/public/favicon.ico | Bin .../web-cra-ts}/public/index.html | 2 +- .../web-cra-ts}/public/logo192.png | Bin .../web-cra-ts}/public/logo512.png | Bin .../web-cra-ts}/public/manifest.json | 0 .../web-cra-ts}/public/robots.txt | 0 .../cra-ts => smoke/web-cra-ts}/src/App.css | 0 .../web-cra-ts}/src/App.test.tsx_ | 0 packages/@tests/smoke/web-cra-ts/src/App.tsx | 48 ++ .../cra-ts => smoke/web-cra-ts}/src/index.css | 0 .../cra-ts => smoke/web-cra-ts}/src/index.tsx | 3 - .../cra-ts => smoke/web-cra-ts}/src/logo.svg | 0 .../web-cra-ts}/src/react-app-env.d.ts | 0 .../web-cra-ts}/src/reportWebVitals.ts | 0 .../web-cra-ts}/src/setupTests.ts | 0 .../@tests/smoke/web-cra-ts/test/index.ts | 45 ++ .../@tests/smoke/web-cra-ts/tsconfig.json | 20 + .../{smoke_web => smoke/web}/.gitignore | 0 .../{smoke_web => smoke/web}/package.json | 15 +- .../web}/public/index.html | 10 +- .../{smoke_web => smoke/web}/public/index.js | 51 +- packages/@tests/smoke/web/src/index.ts | 45 ++ packages/@tests/smoke/web/tsconfig.json | 7 + packages/@tests/smoke_node/src/index.ts | 4 - packages/@tests/test-utils/package.json | 26 + packages/@tests/test-utils/src/index.ts | 37 ++ .../{smoke_node => test-utils}/tsconfig.json | 0 packages/core/js-peer/tsconfig.json | 3 +- pnpm-lock.yaml | 557 ++++++++++++++++-- 40 files changed, 830 insertions(+), 169 deletions(-) delete mode 100644 packages/@tests/frameworks/cra-ts/src/App.tsx delete mode 100644 packages/@tests/frameworks/cra-ts/tsconfig.json rename packages/@tests/{smoke_node => smoke/node}/.gitignore (100%) rename packages/@tests/{smoke_node => smoke/node}/package.json (91%) create mode 100644 packages/@tests/smoke/node/src/index.ts create mode 100644 packages/@tests/smoke/node/tsconfig.json rename packages/@tests/{frameworks/cra-ts => smoke/web-cra-ts}/.gitignore (100%) rename packages/@tests/{frameworks/cra-ts => smoke/web-cra-ts}/README.md (100%) rename packages/@tests/{frameworks/cra-ts => smoke/web-cra-ts}/package.json (87%) rename packages/@tests/{frameworks/cra-ts => smoke/web-cra-ts}/public/favicon.ico (100%) rename packages/@tests/{frameworks/cra-ts => smoke/web-cra-ts}/public/index.html (95%) rename packages/@tests/{frameworks/cra-ts => smoke/web-cra-ts}/public/logo192.png (100%) rename packages/@tests/{frameworks/cra-ts => smoke/web-cra-ts}/public/logo512.png (100%) rename packages/@tests/{frameworks/cra-ts => smoke/web-cra-ts}/public/manifest.json (100%) rename packages/@tests/{frameworks/cra-ts => smoke/web-cra-ts}/public/robots.txt (100%) rename packages/@tests/{frameworks/cra-ts => smoke/web-cra-ts}/src/App.css (100%) rename packages/@tests/{frameworks/cra-ts => smoke/web-cra-ts}/src/App.test.tsx_ (100%) create mode 100644 packages/@tests/smoke/web-cra-ts/src/App.tsx rename packages/@tests/{frameworks/cra-ts => smoke/web-cra-ts}/src/index.css (100%) rename packages/@tests/{frameworks/cra-ts => smoke/web-cra-ts}/src/index.tsx (90%) rename packages/@tests/{frameworks/cra-ts => smoke/web-cra-ts}/src/logo.svg (100%) rename packages/@tests/{frameworks/cra-ts => smoke/web-cra-ts}/src/react-app-env.d.ts (100%) rename packages/@tests/{frameworks/cra-ts => smoke/web-cra-ts}/src/reportWebVitals.ts (100%) rename packages/@tests/{frameworks/cra-ts => smoke/web-cra-ts}/src/setupTests.ts (100%) create mode 100644 packages/@tests/smoke/web-cra-ts/test/index.ts create mode 100644 packages/@tests/smoke/web-cra-ts/tsconfig.json rename packages/@tests/{smoke_web => smoke/web}/.gitignore (100%) rename packages/@tests/{smoke_web => smoke/web}/package.json (63%) rename packages/@tests/{smoke_web => smoke/web}/public/index.html (59%) rename packages/@tests/{smoke_web => smoke/web}/public/index.js (66%) create mode 100644 packages/@tests/smoke/web/src/index.ts create mode 100644 packages/@tests/smoke/web/tsconfig.json delete mode 100644 packages/@tests/smoke_node/src/index.ts create mode 100644 packages/@tests/test-utils/package.json create mode 100644 packages/@tests/test-utils/src/index.ts rename packages/@tests/{smoke_node => test-utils}/tsconfig.json (100%) diff --git a/package.json b/package.json index 155b680e..38f96612 100644 --- a/package.json +++ b/package.json @@ -1,24 +1,25 @@ { - "name": "common-dev-deps", - "version": "0.1.0", - "main": "./dist/index.js", - "typings": "./dist/index.d.ts", - "type": "module", - "engines": { - "node": ">=10", - "pnpm": ">=3" - }, - "scripts": { - "simulate-cdn": "http-server -p 8765 ./packages/client/js-client.web.standalone/dist" - }, - "author": "Fluence Labs", - "license": "Apache-2.0", - "devDependencies": { - "http-server": "14.1.1", - "@types/node": "18.13.0", - "ts-node": "10.9.1", - "typescript": "4.7", - "@fluencelabs/aqua-lib": "0.6.0", - "@fluencelabs/aqua": "0.9.1-374" - } + "name": "common-dev-deps", + "version": "0.1.0", + "main": "./dist/index.js", + "typings": "./dist/index.d.ts", + "type": "module", + "engines": { + "node": ">=10", + "pnpm": ">=3" + }, + "scripts": { + "simulate-cdn": "http-server -p 8765 ./packages/client/js-client.web.standalone/dist" + }, + "author": "Fluence Labs", + "license": "Apache-2.0", + "devDependencies": { + "http-server": "14.1.1", + "puppeteer": "19.7.2", + "@types/node": "18.13.0", + "ts-node": "10.9.1", + "typescript": "4.7", + "@fluencelabs/aqua-lib": "0.6.0", + "@fluencelabs/aqua": "0.9.1-374" + } } diff --git a/packages/@tests/aqua/src/index.ts b/packages/@tests/aqua/src/index.ts index 7ae3447f..c795d88b 100644 --- a/packages/@tests/aqua/src/index.ts +++ b/packages/@tests/aqua/src/index.ts @@ -3,11 +3,13 @@ import { Fluence } from '@fluencelabs/js-client.api'; import { kras, randomKras } from '@fluencelabs/fluence-network-environment'; import { registerHelloWorld, smokeTest } from './_aqua/smoke_test.js'; +// Relay running on local machine // const relay = { // multiaddr: '/ip4/127.0.0.1/tcp/4310/ws/p2p/12D3KooWKEprYXUXqoV5xSBeyqrWLpQLLH4PXfvVkDJtmcqmh5V3', // peerId: '12D3KooWKEprYXUXqoV5xSBeyqrWLpQLLH4PXfvVkDJtmcqmh5V3', // }; +// Currently the tests executes some calls to registry. And they fail for a single local node setup. So we use kras instead. const relay = randomKras(); function generateRandomUint8Array() { @@ -27,7 +29,9 @@ const optsWithRandomKeyPair = () => { } as const; }; -export const main = async () => { +export type TestResult = { res: string | null; errors: string[]; hello: string }; + +export const runTest = async (): Promise => { try { Fluence.onConnectionStateChange((state) => console.info('connection state changed: ', state)); @@ -58,6 +62,8 @@ export const main = async () => { } else { console.log('aqua finished, result', res); } + + return { res, errors, hello }; } finally { console.log('disconnecting from Fluence Network...'); await Fluence.disconnect(); @@ -66,7 +72,7 @@ export const main = async () => { }; export const runMain = () => { - main() + runTest() .then(() => console.log('done!')) .catch((err) => console.error('error: ', err)); }; diff --git a/packages/@tests/frameworks/cra-ts/src/App.tsx b/packages/@tests/frameworks/cra-ts/src/App.tsx deleted file mode 100644 index a53698aa..00000000 --- a/packages/@tests/frameworks/cra-ts/src/App.tsx +++ /dev/null @@ -1,26 +0,0 @@ -import React from 'react'; -import logo from './logo.svg'; -import './App.css'; - -function App() { - return ( -
-
- logo -

- Edit src/App.tsx and save to reload. -

- - Learn React - -
-
- ); -} - -export default App; diff --git a/packages/@tests/frameworks/cra-ts/tsconfig.json b/packages/@tests/frameworks/cra-ts/tsconfig.json deleted file mode 100644 index a273b0cf..00000000 --- a/packages/@tests/frameworks/cra-ts/tsconfig.json +++ /dev/null @@ -1,26 +0,0 @@ -{ - "compilerOptions": { - "target": "es5", - "lib": [ - "dom", - "dom.iterable", - "esnext" - ], - "allowJs": true, - "skipLibCheck": true, - "esModuleInterop": true, - "allowSyntheticDefaultImports": true, - "strict": true, - "forceConsistentCasingInFileNames": true, - "noFallthroughCasesInSwitch": true, - "module": "esnext", - "moduleResolution": "node", - "resolveJsonModule": true, - "isolatedModules": true, - "noEmit": true, - "jsx": "react-jsx" - }, - "include": [ - "src" - ] -} diff --git a/packages/@tests/smoke_node/.gitignore b/packages/@tests/smoke/node/.gitignore similarity index 100% rename from packages/@tests/smoke_node/.gitignore rename to packages/@tests/smoke/node/.gitignore diff --git a/packages/@tests/smoke_node/package.json b/packages/@tests/smoke/node/package.json similarity index 91% rename from packages/@tests/smoke_node/package.json rename to packages/@tests/smoke/node/package.json index 7e4903f1..6451dcc7 100644 --- a/packages/@tests/smoke_node/package.json +++ b/packages/@tests/smoke/node/package.json @@ -11,7 +11,7 @@ "type": "module", "scripts": { "build": "tsc", - "_test": "node --loader ts-node/esm ./src/index.ts" + "test": "node --loader ts-node/esm ./src/index.ts" }, "repository": "https://github.com/fluencelabs/fluence-js", "author": "Fluence Labs", diff --git a/packages/@tests/smoke/node/src/index.ts b/packages/@tests/smoke/node/src/index.ts new file mode 100644 index 00000000..7cd822d8 --- /dev/null +++ b/packages/@tests/smoke/node/src/index.ts @@ -0,0 +1,4 @@ +import '@fluencelabs/js-client.node'; +import { runTest } from '@test/aqua_for_test'; + +runTest().then(() => console.log('Smoke tests succeed!')); diff --git a/packages/@tests/smoke/node/tsconfig.json b/packages/@tests/smoke/node/tsconfig.json new file mode 100644 index 00000000..32d340ac --- /dev/null +++ b/packages/@tests/smoke/node/tsconfig.json @@ -0,0 +1,7 @@ +{ + "extends": "../../../../tsconfig.json", + "compilerOptions": { + "outDir": "./dist" + }, + "exclude": ["node_modules", "dist"] +} diff --git a/packages/@tests/frameworks/cra-ts/.gitignore b/packages/@tests/smoke/web-cra-ts/.gitignore similarity index 100% rename from packages/@tests/frameworks/cra-ts/.gitignore rename to packages/@tests/smoke/web-cra-ts/.gitignore diff --git a/packages/@tests/frameworks/cra-ts/README.md b/packages/@tests/smoke/web-cra-ts/README.md similarity index 100% rename from packages/@tests/frameworks/cra-ts/README.md rename to packages/@tests/smoke/web-cra-ts/README.md diff --git a/packages/@tests/frameworks/cra-ts/package.json b/packages/@tests/smoke/web-cra-ts/package.json similarity index 87% rename from packages/@tests/frameworks/cra-ts/package.json rename to packages/@tests/smoke/web-cra-ts/package.json index 455abc76..7a55e778 100644 --- a/packages/@tests/frameworks/cra-ts/package.json +++ b/packages/@tests/smoke/web-cra-ts/package.json @@ -2,6 +2,7 @@ "name": "cra-ts", "version": "0.1.0", "private": true, + "type": "module", "dependencies": { "@fluencelabs/js-client.api": "workspace:^", "@test/aqua_for_test": "workspace:^", @@ -18,8 +19,11 @@ "typescript": "4.9.5", "web-vitals": "2.1.4" }, - "devDependencies": {}, + "devDependencies": { + "@test/test-utils": "workspace:^" + }, "scripts": { + "commented_out_test": "node --loader ts-node/esm ./test/index.ts", "start": "react-scripts start", "build": "react-scripts build", "_test": "react-scripts test", diff --git a/packages/@tests/frameworks/cra-ts/public/favicon.ico b/packages/@tests/smoke/web-cra-ts/public/favicon.ico similarity index 100% rename from packages/@tests/frameworks/cra-ts/public/favicon.ico rename to packages/@tests/smoke/web-cra-ts/public/favicon.ico diff --git a/packages/@tests/frameworks/cra-ts/public/index.html b/packages/@tests/smoke/web-cra-ts/public/index.html similarity index 95% rename from packages/@tests/frameworks/cra-ts/public/index.html rename to packages/@tests/smoke/web-cra-ts/public/index.html index 726ab18d..5e519444 100644 --- a/packages/@tests/frameworks/cra-ts/public/index.html +++ b/packages/@tests/smoke/web-cra-ts/public/index.html @@ -7,7 +7,7 @@ - +