mirror of
https://github.com/fluencelabs/fluence-js.git
synced 2025-06-27 23:01:33 +00:00
feat(js-client)!: Adding strictes eslint and ts config to all packages [fixes DXJ-464] (#355)
* introduce eslint * Fix all eslint errors * Eslint fix and some touches * Fix tests * Fix misc errors * change semver * change semver #2 * Fix path * Fix path #2 * freeze lock file in CI * fix package install * Fix formatting of surrounding files * Add empty prettier config * Fix formatting * Fix build errors * Remove unused deps * remove changelog from formatting * deps cleanup * make resource importers async * Refactor * Fix error message * remove comment * more refactoring * Update packages/core/js-client/src/compilerSupport/registerService.ts Co-authored-by: shamsartem <shamsartem@gmail.com> * refactoring * refactoring fix * optimize import * Update packages/@tests/smoke/node/src/index.ts Co-authored-by: shamsartem <shamsartem@gmail.com> * Revert package * Fix pnpm lock * Lint-fix * Fix CI * Update tests * Fix build * Fix import * Use forked threads dep * Use fixed version * Update threads * Fix lint * Fix test * Fix test * Add polyfill for assert * Add subpath import * Fix tests * Fix deps --------- Co-authored-by: shamsartem <shamsartem@gmail.com>
This commit is contained in:
6
packages/@tests/.eslintrc.json
Normal file
6
packages/@tests/.eslintrc.json
Normal file
@ -0,0 +1,6 @@
|
||||
{
|
||||
"ignorePatterns": ["**/*.css"],
|
||||
"rules": {
|
||||
"no-console": "off"
|
||||
}
|
||||
}
|
@ -53,3 +53,6 @@ func marineTest(wasm64: string) -> f64:
|
||||
<- res
|
||||
|
||||
|
||||
func callHappy(a: string, b: f64, c: f64, d: string -> f64) -> f64:
|
||||
res <- d("abc")
|
||||
<- res
|
||||
|
@ -1,29 +1,29 @@
|
||||
{
|
||||
"name": "@test/aqua_for_test",
|
||||
"version": "0.1.0",
|
||||
"description": "Shared aqua code for tests",
|
||||
"main": "./dist/index.js",
|
||||
"typings": "./dist/index.d.ts",
|
||||
"engines": {
|
||||
"node": ">=10",
|
||||
"pnpm": ">=3"
|
||||
},
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"build": "tsc",
|
||||
"compile-aqua": "fluence aqua -i ./_aqua -o ./src/_aqua"
|
||||
},
|
||||
"repository": "https://github.com/fluencelabs/fluence-js",
|
||||
"author": "Fluence Labs",
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"@fluencelabs/js-client": "workspace:^",
|
||||
"base64-js": "1.5.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@fluencelabs/cli": "0.7.2",
|
||||
"@fluencelabs/registry": "0.8.2",
|
||||
"@fluencelabs/aqua-lib": "0.6.0",
|
||||
"@fluencelabs/trust-graph": "3.1.2"
|
||||
}
|
||||
"name": "@test/aqua_for_test",
|
||||
"version": "0.1.0",
|
||||
"description": "Shared aqua code for tests",
|
||||
"main": "./dist/index.js",
|
||||
"typings": "./dist/index.d.ts",
|
||||
"engines": {
|
||||
"node": ">=10",
|
||||
"pnpm": ">=3"
|
||||
},
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"build": "tsc",
|
||||
"compile-aqua": "fluence aqua -i ./_aqua -o ./src/_aqua"
|
||||
},
|
||||
"repository": "https://github.com/fluencelabs/fluence-js",
|
||||
"author": "Fluence Labs",
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"base64-js": "1.5.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@fluencelabs/aqua-lib": "0.6.0",
|
||||
"@fluencelabs/cli": "0.7.2",
|
||||
"@fluencelabs/js-client": "workspace:^",
|
||||
"@fluencelabs/registry": "0.8.2",
|
||||
"@fluencelabs/trust-graph": "3.1.2"
|
||||
}
|
||||
}
|
||||
|
@ -8,13 +8,14 @@
|
||||
* Aqua version: 0.12.0
|
||||
*
|
||||
*/
|
||||
import type { IFluenceClient as IFluenceClient$$, CallParams as CallParams$$ } from '@fluencelabs/js-client';
|
||||
import type {
|
||||
IFluenceClient as IFluenceClient$$,
|
||||
CallParams as CallParams$$,
|
||||
} from "@fluencelabs/js-client";
|
||||
import {
|
||||
v5_callFunction as callFunction$$,
|
||||
v5_registerService as registerService$$,
|
||||
} from '@fluencelabs/js-client';
|
||||
|
||||
|
||||
v5_callFunction as callFunction$$,
|
||||
v5_registerService as registerService$$,
|
||||
} from "@fluencelabs/js-client";
|
||||
|
||||
// Services
|
||||
|
||||
@ -30,49 +31,42 @@ export const test_script = `
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 0])
|
||||
)
|
||||
)
|
||||
`
|
||||
|
||||
`;
|
||||
|
||||
export function test(config?: { ttl?: number }): Promise<void>;
|
||||
|
||||
export function test(
|
||||
config?: {ttl?: number}
|
||||
): Promise<void>;
|
||||
|
||||
export function test(
|
||||
peer: IFluenceClient$$,
|
||||
config?: {ttl?: number}
|
||||
peer: IFluenceClient$$,
|
||||
config?: { ttl?: number },
|
||||
): Promise<void>;
|
||||
|
||||
export function test(...args: any) {
|
||||
|
||||
|
||||
return callFunction$$(
|
||||
args,
|
||||
{
|
||||
"functionName" : "test",
|
||||
"arrow" : {
|
||||
"tag" : "arrow",
|
||||
"domain" : {
|
||||
"tag" : "labeledProduct",
|
||||
"fields" : {
|
||||
|
||||
}
|
||||
return callFunction$$(
|
||||
args,
|
||||
{
|
||||
functionName: "test",
|
||||
arrow: {
|
||||
tag: "arrow",
|
||||
domain: {
|
||||
tag: "labeledProduct",
|
||||
fields: {},
|
||||
},
|
||||
"codomain" : {
|
||||
"tag" : "nil"
|
||||
}
|
||||
codomain: {
|
||||
tag: "nil",
|
||||
},
|
||||
},
|
||||
names: {
|
||||
relay: "-relay-",
|
||||
getDataSrv: "getDataSrv",
|
||||
callbackSrv: "callbackSrv",
|
||||
responseSrv: "callbackSrv",
|
||||
responseFnName: "response",
|
||||
errorHandlingSrv: "errorHandlingSrv",
|
||||
errorFnName: "error",
|
||||
},
|
||||
},
|
||||
"names" : {
|
||||
"relay" : "-relay-",
|
||||
"getDataSrv" : "getDataSrv",
|
||||
"callbackSrv" : "callbackSrv",
|
||||
"responseSrv" : "callbackSrv",
|
||||
"responseFnName" : "response",
|
||||
"errorHandlingSrv" : "errorHandlingSrv",
|
||||
"errorFnName" : "error"
|
||||
}
|
||||
},
|
||||
test_script
|
||||
)
|
||||
test_script,
|
||||
);
|
||||
}
|
||||
|
||||
/* eslint-enable */
|
||||
/* eslint-enable */
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,84 +1,117 @@
|
||||
import { fromByteArray } from 'base64-js';
|
||||
import { Fluence } from '@fluencelabs/js-client';
|
||||
import type { ClientConfig } from '@fluencelabs/js-client';
|
||||
import { registerHelloWorld, helloTest, marineTest, resourceTest } from './_aqua/smoke_test.js';
|
||||
import { test as particleTest } from './_aqua/finalize_particle.js';
|
||||
import { wasm } from './wasmb64.js';
|
||||
/**
|
||||
* Copyright 2023 Fluence Labs Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { Fluence } from "@fluencelabs/js-client";
|
||||
import type { ClientConfig } from "@fluencelabs/js-client";
|
||||
import { fromByteArray } from "base64-js";
|
||||
|
||||
import { test as particleTest } from "./_aqua/finalize_particle.js";
|
||||
import {
|
||||
registerHelloWorld,
|
||||
helloTest,
|
||||
marineTest,
|
||||
} from "./_aqua/smoke_test.js";
|
||||
import { wasm } from "./wasmb64.js";
|
||||
|
||||
const relay = {
|
||||
multiaddr: '/ip4/127.0.0.1/tcp/9991/ws/p2p/12D3KooWBM3SdXWqGaawQDGQ6JprtwswEg3FWGvGhmgmMez1vRbR',
|
||||
peerId: '12D3KooWBM3SdXWqGaawQDGQ6JprtwswEg3FWGvGhmgmMez1vRbR',
|
||||
multiaddr:
|
||||
"/ip4/127.0.0.1/tcp/9991/ws/p2p/12D3KooWBM3SdXWqGaawQDGQ6JprtwswEg3FWGvGhmgmMez1vRbR",
|
||||
peerId: "12D3KooWBM3SdXWqGaawQDGQ6JprtwswEg3FWGvGhmgmMez1vRbR",
|
||||
};
|
||||
|
||||
function generateRandomUint8Array() {
|
||||
const uint8Array = new Uint8Array(32);
|
||||
for (let i = 0; i < uint8Array.length; i++) {
|
||||
uint8Array[i] = Math.floor(Math.random() * 256);
|
||||
}
|
||||
return uint8Array;
|
||||
const uint8Array = new Uint8Array(32);
|
||||
|
||||
for (let i = 0; i < uint8Array.length; i++) {
|
||||
uint8Array[i] = Math.floor(Math.random() * 256);
|
||||
}
|
||||
|
||||
return uint8Array;
|
||||
}
|
||||
|
||||
const optsWithRandomKeyPair = (): ClientConfig => {
|
||||
return {
|
||||
keyPair: {
|
||||
type: 'Ed25519',
|
||||
source: generateRandomUint8Array(),
|
||||
},
|
||||
} as const;
|
||||
return {
|
||||
keyPair: {
|
||||
type: "Ed25519",
|
||||
source: generateRandomUint8Array(),
|
||||
},
|
||||
} as const;
|
||||
};
|
||||
|
||||
export type TestResult = { type: 'success'; data: string } | { type: 'failure'; error: string };
|
||||
export type TestResult =
|
||||
| { type: "success"; data: string }
|
||||
| { type: "failure"; error: string };
|
||||
|
||||
export const runTest = async (): Promise<TestResult> => {
|
||||
try {
|
||||
Fluence.onConnectionStateChange((state) => console.info('connection state changed: ', state));
|
||||
try {
|
||||
Fluence.onConnectionStateChange((state) => {
|
||||
console.info("connection state changed: ", state);
|
||||
});
|
||||
|
||||
console.log('connecting to Fluence Network...');
|
||||
console.log('multiaddr: ', relay.multiaddr);
|
||||
await Fluence.connect(relay, optsWithRandomKeyPair());
|
||||
console.log("connecting to Fluence Network...");
|
||||
console.log("multiaddr: ", relay.multiaddr);
|
||||
await Fluence.connect(relay, optsWithRandomKeyPair());
|
||||
|
||||
console.log('connected');
|
||||
console.log("connected");
|
||||
|
||||
const relayPeerId = (await Fluence.getClient()).getRelayPeerId();
|
||||
console.log('relay:', relayPeerId);
|
||||
const relayPeerId = Fluence.getClient().getRelayPeerId();
|
||||
console.log("relay:", relayPeerId);
|
||||
|
||||
await registerHelloWorld({
|
||||
hello(str) {
|
||||
return 'Hello, ' + str + '!';
|
||||
},
|
||||
});
|
||||
registerHelloWorld({
|
||||
hello(str) {
|
||||
return "Hello, " + str + "!";
|
||||
},
|
||||
});
|
||||
|
||||
const client = await Fluence.getClient();
|
||||
const client = Fluence.getClient();
|
||||
|
||||
console.log('my peer id: ', client.getPeerId());
|
||||
console.log('my sk id: ', fromByteArray(client.getPeerSecretKey()));
|
||||
console.log("my peer id: ", client.getPeerId());
|
||||
console.log("my sk id: ", fromByteArray(client.getPeerSecretKey()));
|
||||
|
||||
console.log('running hello test...');
|
||||
const hello = await helloTest();
|
||||
console.log('hello test finished, result: ', hello);
|
||||
console.log("running hello test...");
|
||||
const hello = await helloTest();
|
||||
console.log("hello test finished, result: ", hello);
|
||||
|
||||
console.log('running marine test...');
|
||||
const marine = await marineTest(wasm);
|
||||
console.log("running marine test...");
|
||||
const marine = await marineTest(wasm);
|
||||
|
||||
console.log('running particle test...');
|
||||
await particleTest();
|
||||
|
||||
console.log('marine test finished, result: ', marine);
|
||||
console.log("running particle test...");
|
||||
await particleTest();
|
||||
|
||||
const returnVal = {
|
||||
hello,
|
||||
marine,
|
||||
};
|
||||
return { type: 'success', data: JSON.stringify(returnVal) };
|
||||
} finally {
|
||||
console.log('disconnecting from Fluence Network...');
|
||||
await Fluence.disconnect();
|
||||
console.log('disconnected');
|
||||
}
|
||||
console.log("marine test finished, result: ", marine);
|
||||
|
||||
const returnVal = {
|
||||
hello,
|
||||
marine,
|
||||
};
|
||||
|
||||
return { type: "success", data: JSON.stringify(returnVal) };
|
||||
} finally {
|
||||
console.log("disconnecting from Fluence Network...");
|
||||
await Fluence.disconnect();
|
||||
console.log("disconnected");
|
||||
}
|
||||
};
|
||||
|
||||
export const runMain = () => {
|
||||
runTest()
|
||||
.then(() => console.log('done!'))
|
||||
.catch((err) => console.error('error: ', err));
|
||||
runTest()
|
||||
.then(() => {
|
||||
console.log("done!");
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error("error: ", err);
|
||||
});
|
||||
};
|
||||
|
File diff suppressed because one or more lines are too long
@ -1,8 +1,9 @@
|
||||
{
|
||||
"extends": "../../../tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"outDir": "./dist",
|
||||
"module": "NodeNext"
|
||||
},
|
||||
"exclude": ["node_modules", "dist"]
|
||||
"extends": "../../../tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"outDir": "./dist",
|
||||
"module": "NodeNext"
|
||||
},
|
||||
"include": ["src/**/*"],
|
||||
"exclude": ["node_modules", "dist"]
|
||||
}
|
||||
|
@ -1,23 +1,23 @@
|
||||
{
|
||||
"name": "@test/smoke",
|
||||
"version": "0.1.0",
|
||||
"description": "Smoke test",
|
||||
"main": "./dist/index.js",
|
||||
"typings": "./dist/index.d.ts",
|
||||
"engines": {
|
||||
"node": ">=10",
|
||||
"pnpm": ">=3"
|
||||
},
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"build": "tsc",
|
||||
"test": "node --loader ts-node/esm ./src/index.ts"
|
||||
},
|
||||
"repository": "https://github.com/fluencelabs/fluence-js",
|
||||
"author": "Fluence Labs",
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"@fluencelabs/js-client": "workspace:*",
|
||||
"@test/aqua_for_test": "workspace:*"
|
||||
}
|
||||
"name": "@test/smoke",
|
||||
"version": "0.1.0",
|
||||
"description": "Smoke test",
|
||||
"main": "./dist/index.js",
|
||||
"typings": "./dist/index.d.ts",
|
||||
"engines": {
|
||||
"node": ">=10",
|
||||
"pnpm": ">=3"
|
||||
},
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"build": "tsc",
|
||||
"test": "node --loader ts-node/esm ./src/index.ts"
|
||||
},
|
||||
"repository": "https://github.com/fluencelabs/fluence-js",
|
||||
"author": "Fluence Labs",
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"@fluencelabs/js-client": "workspace:*",
|
||||
"@test/aqua_for_test": "workspace:*"
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,21 @@
|
||||
import '@fluencelabs/js-client';
|
||||
import { runTest } from '@test/aqua_for_test';
|
||||
/**
|
||||
* Copyright 2023 Fluence Labs Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
runTest().then(() => console.log('Smoke tests succeed!'));
|
||||
import "@fluencelabs/js-client";
|
||||
import { runTest } from "@test/aqua_for_test";
|
||||
|
||||
await runTest();
|
||||
console.log("Smoke tests succeed!");
|
||||
|
@ -1,7 +1,7 @@
|
||||
{
|
||||
"extends": "../../../../tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"outDir": "./dist"
|
||||
},
|
||||
"exclude": ["node_modules", "dist"]
|
||||
"extends": "../../../../tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"outDir": "./dist"
|
||||
},
|
||||
"exclude": ["node_modules", "dist"]
|
||||
}
|
||||
|
@ -1,51 +1,50 @@
|
||||
{
|
||||
"name": "cra-ts",
|
||||
"version": "0.1.0",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"dependencies": {
|
||||
"@test/aqua_for_test": "workspace:^",
|
||||
"@testing-library/jest-dom": "5.16.5",
|
||||
"@testing-library/react": "13.4.0",
|
||||
"@testing-library/user-event": "13.5.0",
|
||||
"@types/jest": "27.5.2",
|
||||
"@types/node": "16.18.12",
|
||||
"@types/react": "18.0.27",
|
||||
"@types/react-dom": "18.0.10",
|
||||
"react": "^18.2.0",
|
||||
"react-dom": "^18.2.0",
|
||||
"react-scripts": "5.0.1",
|
||||
"typescript": "4.9.5",
|
||||
"web-vitals": "2.1.4"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@test/test-utils": "workspace:^",
|
||||
"puppeteer": "19.7.2"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "node --loader ts-node/esm ./test/index.ts",
|
||||
"simulate-cdn": "http-server -p 8766 ../../../client/js-client.web.standalone/dist",
|
||||
"start": "react-scripts start",
|
||||
"build": "react-scripts build",
|
||||
"_test": "react-scripts test",
|
||||
"eject": "react-scripts eject"
|
||||
},
|
||||
"eslintConfig": {
|
||||
"extends": [
|
||||
"react-app",
|
||||
"react-app/jest"
|
||||
]
|
||||
},
|
||||
"browserslist": {
|
||||
"production": [
|
||||
">0.2%",
|
||||
"not dead",
|
||||
"not op_mini all"
|
||||
],
|
||||
"development": [
|
||||
"last 1 chrome version",
|
||||
"last 1 firefox version",
|
||||
"last 1 safari version"
|
||||
]
|
||||
}
|
||||
"name": "cra-ts",
|
||||
"version": "0.1.0",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"dependencies": {
|
||||
"@test/aqua_for_test": "workspace:*",
|
||||
"@testing-library/jest-dom": "5.16.5",
|
||||
"@testing-library/react": "13.4.0",
|
||||
"@testing-library/user-event": "13.5.0",
|
||||
"@types/jest": "27.5.2",
|
||||
"@types/node": "16.18.12",
|
||||
"@types/react": "18.0.27",
|
||||
"@types/react-dom": "18.0.10",
|
||||
"react": "^18.2.0",
|
||||
"react-dom": "^18.2.0",
|
||||
"react-scripts": "5.0.1",
|
||||
"web-vitals": "2.1.4"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@test/test-utils": "workspace:*",
|
||||
"puppeteer": "19.7.2"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "node --loader ts-node/esm ./test/index.ts",
|
||||
"simulate-cdn": "http-server -p 8766 ../../../client/js-client.web.standalone/dist",
|
||||
"start": "react-scripts start",
|
||||
"build": "react-scripts build",
|
||||
"_test": "react-scripts test",
|
||||
"eject": "react-scripts eject"
|
||||
},
|
||||
"eslintConfig": {
|
||||
"extends": [
|
||||
"react-app",
|
||||
"react-app/jest"
|
||||
]
|
||||
},
|
||||
"browserslist": {
|
||||
"production": [
|
||||
">0.2%",
|
||||
"not dead",
|
||||
"not op_mini all"
|
||||
],
|
||||
"development": [
|
||||
"last 1 chrome version",
|
||||
"last 1 firefox version",
|
||||
"last 1 safari version"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
@ -1,40 +1,49 @@
|
||||
import { runTest, TestResult } from '@test/aqua_for_test';
|
||||
import React from 'react';
|
||||
import logo from './logo.svg';
|
||||
import './App.css';
|
||||
import { runTest, TestResult } from "@test/aqua_for_test";
|
||||
import React from "react";
|
||||
import logo from "./logo.svg";
|
||||
import "./App.css";
|
||||
|
||||
function App() {
|
||||
const [result, setResult] = React.useState<TestResult | null>(null);
|
||||
const [result, setResult] = React.useState<TestResult | null>(null);
|
||||
|
||||
const onButtonClick = () => {
|
||||
runTest()
|
||||
.then((res) => {
|
||||
setResult(res);
|
||||
})
|
||||
.catch((err) => {
|
||||
setResult({ type: 'failure', error: err.toString() });
|
||||
});
|
||||
};
|
||||
const onButtonClick = () => {
|
||||
runTest()
|
||||
.then((res) => {
|
||||
setResult(res);
|
||||
})
|
||||
.catch((err) => {
|
||||
setResult({ type: "failure", error: err.toString() });
|
||||
});
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="App">
|
||||
<header className="App-header">
|
||||
<img src={logo} className="App-logo" alt="logo" />
|
||||
<p>
|
||||
Edit <code>src/App.tsx</code> and save to reload.
|
||||
</p>
|
||||
<button id="btn" onClick={onButtonClick}>
|
||||
Click to run test
|
||||
</button>
|
||||
return (
|
||||
<div className="App">
|
||||
<header className="App-header">
|
||||
<img src={logo} className="App-logo" alt="logo" />
|
||||
<p>
|
||||
Edit <code>src/App.tsx</code> and save to reload.
|
||||
</p>
|
||||
<button id="btn" onClick={onButtonClick}>
|
||||
Click to run test
|
||||
</button>
|
||||
|
||||
{result && result.type === 'success' && <div id="res">{result.data}</div>}
|
||||
{result && result.type === 'failure' && <div id="error">{result.error}</div>}
|
||||
<a className="App-link" href="https://reactjs.org" target="_blank" rel="noopener noreferrer">
|
||||
Learn React
|
||||
</a>
|
||||
</header>
|
||||
</div>
|
||||
);
|
||||
{result && result.type === "success" && (
|
||||
<div id="res">{result.data}</div>
|
||||
)}
|
||||
{result && result.type === "failure" && (
|
||||
<div id="error">{result.error}</div>
|
||||
)}
|
||||
<a
|
||||
className="App-link"
|
||||
href="https://reactjs.org"
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
>
|
||||
Learn React
|
||||
</a>
|
||||
</header>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default App;
|
||||
|
@ -1,13 +1,13 @@
|
||||
body {
|
||||
margin: 0;
|
||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
|
||||
'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
|
||||
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen",
|
||||
"Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue",
|
||||
sans-serif;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
-moz-osx-font-smoothing: grayscale;
|
||||
}
|
||||
|
||||
code {
|
||||
font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New',
|
||||
font-family: source-code-pro, Menlo, Monaco, Consolas, "Courier New",
|
||||
monospace;
|
||||
}
|
||||
|
@ -1,14 +1,16 @@
|
||||
import React from 'react';
|
||||
import ReactDOM from 'react-dom/client';
|
||||
import './index.css';
|
||||
import App from './App';
|
||||
import reportWebVitals from './reportWebVitals';
|
||||
import React from "react";
|
||||
import ReactDOM from "react-dom/client";
|
||||
import "./index.css";
|
||||
import App from "./App";
|
||||
import reportWebVitals from "./reportWebVitals";
|
||||
|
||||
const root = ReactDOM.createRoot(document.getElementById('root') as HTMLElement);
|
||||
const root = ReactDOM.createRoot(
|
||||
document.getElementById("root") as HTMLElement,
|
||||
);
|
||||
root.render(
|
||||
<React.StrictMode>
|
||||
<App />
|
||||
</React.StrictMode>,
|
||||
<React.StrictMode>
|
||||
<App />
|
||||
</React.StrictMode>,
|
||||
);
|
||||
|
||||
// If you want to start measuring performance in your app, pass a function
|
||||
|
@ -1,8 +1,8 @@
|
||||
import { ReportHandler } from 'web-vitals';
|
||||
import { ReportHandler } from "web-vitals";
|
||||
|
||||
const reportWebVitals = (onPerfEntry?: ReportHandler) => {
|
||||
if (onPerfEntry && onPerfEntry instanceof Function) {
|
||||
import('web-vitals').then(({ getCLS, getFID, getFCP, getLCP, getTTFB }) => {
|
||||
import("web-vitals").then(({ getCLS, getFID, getFCP, getLCP, getTTFB }) => {
|
||||
getCLS(onPerfEntry);
|
||||
getFID(onPerfEntry);
|
||||
getFCP(onPerfEntry);
|
||||
|
@ -2,4 +2,4 @@
|
||||
// allows you to do things like:
|
||||
// expect(element).toHaveTextContent(/react/i)
|
||||
// learn more: https://github.com/testing-library/jest-dom
|
||||
import '@testing-library/jest-dom';
|
||||
import "@testing-library/jest-dom";
|
||||
|
@ -1,49 +1,53 @@
|
||||
import puppeteer from 'puppeteer';
|
||||
import { dirname, join } from 'path';
|
||||
import { fileURLToPath } from 'url';
|
||||
import puppeteer from "puppeteer";
|
||||
import { dirname, join } from "path";
|
||||
import { fileURLToPath } from "url";
|
||||
|
||||
import { CDN_PUBLIC_PATH, startContentServer, stopServer } from '@test/test-utils';
|
||||
import { access, symlink } from 'fs/promises';
|
||||
import {
|
||||
CDN_PUBLIC_PATH,
|
||||
startContentServer,
|
||||
stopServer,
|
||||
} from "@test/test-utils";
|
||||
import { access, symlink } from "fs/promises";
|
||||
|
||||
const port = 3001;
|
||||
const uri = `http://localhost:${port}/`;
|
||||
const __dirname = dirname(fileURLToPath(import.meta.url));
|
||||
const publicPath = join(__dirname, '../build/');
|
||||
const publicPath = join(__dirname, "../build/");
|
||||
|
||||
const test = async () => {
|
||||
const localServer = await startContentServer(port, publicPath);
|
||||
try {
|
||||
await access(join(publicPath, 'source'))
|
||||
} catch {
|
||||
await symlink(CDN_PUBLIC_PATH, join(publicPath, 'source'));
|
||||
}
|
||||
const localServer = await startContentServer(port, publicPath);
|
||||
try {
|
||||
await access(join(publicPath, "source"));
|
||||
} catch {
|
||||
await symlink(CDN_PUBLIC_PATH, join(publicPath, "source"));
|
||||
}
|
||||
|
||||
console.log('starting puppeteer...');
|
||||
const browser = await puppeteer.launch();
|
||||
const page = (await browser.pages())[0];
|
||||
console.log("starting puppeteer...");
|
||||
const browser = await puppeteer.launch();
|
||||
const page = (await browser.pages())[0];
|
||||
|
||||
// uncomment to debug what's happening inside the browser
|
||||
// page.on('console', (msg) => console.log('// from console: ', msg.text()));
|
||||
// uncomment to debug what's happening inside the browser
|
||||
// page.on('console', (msg) => console.log('// from console: ', msg.text()));
|
||||
|
||||
console.log('going to the page in browser...');
|
||||
await page.goto(uri);
|
||||
console.log("going to the page in browser...");
|
||||
await page.goto(uri);
|
||||
|
||||
console.log('clicking button...');
|
||||
await page.click('#btn');
|
||||
console.log("clicking button...");
|
||||
await page.click("#btn");
|
||||
|
||||
console.log('waiting for result to appear...');
|
||||
const elem = await page.waitForSelector('#res');
|
||||
console.log("waiting for result to appear...");
|
||||
const elem = await page.waitForSelector("#res");
|
||||
|
||||
console.log('getting the content of result div...');
|
||||
const content = await elem?.evaluate((x) => x.textContent);
|
||||
console.log('raw result: ', content);
|
||||
console.log("getting the content of result div...");
|
||||
const content = await elem?.evaluate((x) => x.textContent);
|
||||
console.log("raw result: ", content);
|
||||
|
||||
await browser.close();
|
||||
await stopServer(localServer);
|
||||
await browser.close();
|
||||
await stopServer(localServer);
|
||||
|
||||
if (!content) {
|
||||
throw new Error('smoke test failed!');
|
||||
}
|
||||
if (!content) {
|
||||
throw new Error("smoke test failed!");
|
||||
}
|
||||
};
|
||||
|
||||
test().then(() => console.log('smoke tests succeed!'));
|
||||
test().then(() => console.log("smoke tests succeed!"));
|
||||
|
@ -1,20 +1,20 @@
|
||||
{
|
||||
"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", "test"]
|
||||
"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", "test"]
|
||||
}
|
||||
|
@ -1,28 +1,28 @@
|
||||
{
|
||||
"name": "@tests/smoke_web",
|
||||
"version": "0.1.0",
|
||||
"description": "Smoke test web",
|
||||
"main": "./dist/index.js",
|
||||
"typings": "./dist/index.d.ts",
|
||||
"engines": {
|
||||
"node": ">=10",
|
||||
"pnpm": ">=3"
|
||||
},
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"build": "tsc",
|
||||
"simulate-cdn": "http-server -p 8765 ../../../client/js-client.web.standalone/dist",
|
||||
"test": "node --loader ts-node/esm ./src/index.ts",
|
||||
"serve": "http-server public"
|
||||
},
|
||||
"repository": "https://github.com/fluencelabs/fluence-js",
|
||||
"author": "Fluence Labs",
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"@fluencelabs/js-client": "workspace:^",
|
||||
"@test/test-utils": "workspace:../../test-utils"
|
||||
},
|
||||
"devDependencies": {
|
||||
"puppeteer": "19.7.2"
|
||||
}
|
||||
"name": "@tests/smoke_web",
|
||||
"version": "0.1.0",
|
||||
"description": "Smoke test web",
|
||||
"main": "./dist/index.js",
|
||||
"typings": "./dist/index.d.ts",
|
||||
"engines": {
|
||||
"node": ">=10",
|
||||
"pnpm": ">=3"
|
||||
},
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"build": "tsc",
|
||||
"simulate-cdn": "http-server -p 8765 ../../../client/js-client.web.standalone/dist",
|
||||
"test": "node --loader ts-node/esm ./src/index.ts",
|
||||
"serve": "http-server public"
|
||||
},
|
||||
"repository": "https://github.com/fluencelabs/fluence-js",
|
||||
"author": "Fluence Labs",
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"@fluencelabs/js-client": "workspace:*",
|
||||
"@test/test-utils": "workspace:*"
|
||||
},
|
||||
"devDependencies": {
|
||||
"puppeteer": "19.7.2"
|
||||
}
|
||||
}
|
||||
|
@ -1,12 +1,13 @@
|
||||
const fluence = globalThis.fluence;
|
||||
|
||||
const relay = {
|
||||
multiaddr: '/ip4/127.0.0.1/tcp/9991/ws/p2p/12D3KooWBM3SdXWqGaawQDGQ6JprtwswEg3FWGvGhmgmMez1vRbR',
|
||||
peerId: '12D3KooWBM3SdXWqGaawQDGQ6JprtwswEg3FWGvGhmgmMez1vRbR',
|
||||
multiaddr:
|
||||
"/ip4/127.0.0.1/tcp/9991/ws/p2p/12D3KooWBM3SdXWqGaawQDGQ6JprtwswEg3FWGvGhmgmMez1vRbR",
|
||||
peerId: "12D3KooWBM3SdXWqGaawQDGQ6JprtwswEg3FWGvGhmgmMez1vRbR",
|
||||
};
|
||||
|
||||
const getRelayTime = () => {
|
||||
const script = `
|
||||
const script = `
|
||||
(xor
|
||||
(seq
|
||||
(seq
|
||||
@ -36,75 +37,75 @@ const getRelayTime = () => {
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 3])
|
||||
)`;
|
||||
|
||||
const def = {
|
||||
functionName: 'getRelayTime',
|
||||
arrow: {
|
||||
tag: 'arrow',
|
||||
domain: {
|
||||
tag: 'labeledProduct',
|
||||
fields: {
|
||||
relayPeerId: {
|
||||
tag: 'scalar',
|
||||
name: 'string',
|
||||
},
|
||||
},
|
||||
},
|
||||
codomain: {
|
||||
tag: 'unlabeledProduct',
|
||||
items: [
|
||||
{
|
||||
tag: 'scalar',
|
||||
name: 'u64',
|
||||
},
|
||||
],
|
||||
},
|
||||
const def = {
|
||||
functionName: "getRelayTime",
|
||||
arrow: {
|
||||
tag: "arrow",
|
||||
domain: {
|
||||
tag: "labeledProduct",
|
||||
fields: {
|
||||
relayPeerId: {
|
||||
tag: "scalar",
|
||||
name: "string",
|
||||
},
|
||||
},
|
||||
names: {
|
||||
relay: '-relay-',
|
||||
getDataSrv: 'getDataSrv',
|
||||
callbackSrv: 'callbackSrv',
|
||||
responseSrv: 'callbackSrv',
|
||||
responseFnName: 'response',
|
||||
errorHandlingSrv: 'errorHandlingSrv',
|
||||
errorFnName: 'error',
|
||||
},
|
||||
};
|
||||
},
|
||||
codomain: {
|
||||
tag: "unlabeledProduct",
|
||||
items: [
|
||||
{
|
||||
tag: "scalar",
|
||||
name: "u64",
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
names: {
|
||||
relay: "-relay-",
|
||||
getDataSrv: "getDataSrv",
|
||||
callbackSrv: "callbackSrv",
|
||||
responseSrv: "callbackSrv",
|
||||
responseFnName: "response",
|
||||
errorHandlingSrv: "errorHandlingSrv",
|
||||
errorFnName: "error",
|
||||
},
|
||||
};
|
||||
|
||||
const config = {};
|
||||
const config = {};
|
||||
|
||||
const args = { relayPeerId: relay.peerId };
|
||||
return fluence.callAquaFunction({
|
||||
args,
|
||||
def,
|
||||
script,
|
||||
config,
|
||||
peer: fluence.defaultClient,
|
||||
});
|
||||
const args = { relayPeerId: relay.peerId };
|
||||
return fluence.callAquaFunction({
|
||||
args,
|
||||
def,
|
||||
script,
|
||||
config,
|
||||
peer: fluence.defaultClient,
|
||||
});
|
||||
};
|
||||
|
||||
const main = async () => {
|
||||
console.log('starting fluence...');
|
||||
fluence.defaultClient = await fluence.clientFactory(relay);
|
||||
console.log('started fluence');
|
||||
console.log("starting fluence...");
|
||||
fluence.defaultClient = await fluence.clientFactory(relay, {});
|
||||
console.log("started fluence");
|
||||
|
||||
console.log('getting relay time...');
|
||||
const relayTime = await getRelayTime();
|
||||
console.log('got relay time, ', relayTime);
|
||||
console.log("getting relay time...");
|
||||
const relayTime = await getRelayTime();
|
||||
console.log("got relay time, ", relayTime);
|
||||
|
||||
console.log('stopping fluence...');
|
||||
await fluence.defaultClient.stop();
|
||||
console.log('stopped fluence...');
|
||||
console.log("stopping fluence...");
|
||||
await fluence.defaultClient.stop();
|
||||
console.log("stopped fluence...");
|
||||
|
||||
return relayTime;
|
||||
return relayTime;
|
||||
};
|
||||
|
||||
const btn = document.getElementById('btn');
|
||||
const btn = document.getElementById("btn");
|
||||
|
||||
btn.addEventListener('click', () => {
|
||||
main().then((res) => {
|
||||
const inner = document.createElement('div');
|
||||
inner.id = 'res';
|
||||
inner.innerText = res;
|
||||
document.getElementById('res-placeholder').appendChild(inner);
|
||||
});
|
||||
btn.addEventListener("click", () => {
|
||||
main().then((res) => {
|
||||
const inner = document.createElement("div");
|
||||
inner.id = "res";
|
||||
inner.innerText = res;
|
||||
document.getElementById("res-placeholder").appendChild(inner);
|
||||
});
|
||||
});
|
||||
|
@ -1,49 +1,76 @@
|
||||
import puppeteer from 'puppeteer';
|
||||
import { dirname, join } from 'path';
|
||||
import { fileURLToPath } from 'url';
|
||||
/**
|
||||
* Copyright 2023 Fluence Labs Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { CDN_PUBLIC_PATH, startCdn, startContentServer, stopServer } from '@test/test-utils';
|
||||
import { symlink, access } from 'fs/promises';
|
||||
import { symlink, access } from "fs/promises";
|
||||
import { dirname, join } from "path";
|
||||
import { fileURLToPath } from "url";
|
||||
|
||||
import {
|
||||
CDN_PUBLIC_PATH,
|
||||
startContentServer,
|
||||
stopServer,
|
||||
} from "@test/test-utils";
|
||||
import puppeteer from "puppeteer";
|
||||
|
||||
const port = 3000;
|
||||
const uri = `http://localhost:${port}/`;
|
||||
const __dirname = dirname(fileURLToPath(import.meta.url));
|
||||
const publicPath = join(__dirname, '../public/');
|
||||
const publicPath = join(__dirname, "../public/");
|
||||
|
||||
const test = async () => {
|
||||
const localServer = await startContentServer(port, publicPath);
|
||||
try {
|
||||
await access(join(publicPath, 'source'))
|
||||
} catch {
|
||||
await symlink(CDN_PUBLIC_PATH, join(publicPath, 'source'));
|
||||
}
|
||||
const localServer = await startContentServer(port, publicPath);
|
||||
|
||||
console.log('starting puppeteer...');
|
||||
const browser = await puppeteer.launch();
|
||||
const page = (await browser.pages())[0];
|
||||
try {
|
||||
await access(join(publicPath, "source"));
|
||||
} catch {
|
||||
await symlink(CDN_PUBLIC_PATH, join(publicPath, "source"));
|
||||
}
|
||||
|
||||
// uncomment to debug what's happening inside the browser
|
||||
// page.on('console', (msg) => console.log('// from console: ', msg.text()));
|
||||
console.log("starting puppeteer...");
|
||||
const browser = await puppeteer.launch();
|
||||
const page = (await browser.pages())[0];
|
||||
|
||||
console.log('going to the page in browser...');
|
||||
await page.goto(uri);
|
||||
// uncomment to debug what's happening inside the browser
|
||||
// page.on('console', (msg) => console.log('// from console: ', msg.text()));
|
||||
|
||||
console.log('clicking button...');
|
||||
await page.click('#btn');
|
||||
console.log("going to the page in browser...");
|
||||
await page.goto(uri);
|
||||
|
||||
console.log('waiting for result to appear...');
|
||||
const elem = await page.waitForSelector('#res');
|
||||
console.log("clicking button...");
|
||||
await page.click("#btn");
|
||||
|
||||
console.log('getting the content of result div...');
|
||||
const content = await elem?.evaluate((x) => x.textContent);
|
||||
console.log('raw result: ', content);
|
||||
console.log("waiting for result to appear...");
|
||||
const elem = await page.waitForSelector("#res");
|
||||
|
||||
await browser.close();
|
||||
await stopServer(localServer);
|
||||
console.log("getting the content of result div...");
|
||||
|
||||
if (!content) {
|
||||
throw new Error('smoke test failed!');
|
||||
}
|
||||
const content = await elem?.evaluate((x) => {
|
||||
return x.textContent;
|
||||
});
|
||||
|
||||
console.log("raw result: ", content);
|
||||
|
||||
await browser.close();
|
||||
await stopServer(localServer);
|
||||
|
||||
if (content == null) {
|
||||
throw new Error("smoke test failed!");
|
||||
}
|
||||
};
|
||||
|
||||
test().then(() => console.log('smoke tests succeed!'));
|
||||
void test().then(() => {
|
||||
console.log("smoke tests succeed!");
|
||||
});
|
||||
|
@ -1,7 +1,7 @@
|
||||
{
|
||||
"extends": "../../../../tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"outDir": "./dist"
|
||||
},
|
||||
"exclude": ["node_modules", "dist"]
|
||||
"extends": "../../../../tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"outDir": "./dist"
|
||||
},
|
||||
"exclude": ["node_modules", "dist", "public"]
|
||||
}
|
||||
|
@ -1,24 +1,24 @@
|
||||
{
|
||||
"name": "@test/test-utils",
|
||||
"version": "0.1.0",
|
||||
"description": "Test utils",
|
||||
"main": "./dist/index.js",
|
||||
"typings": "./dist/index.d.ts",
|
||||
"engines": {
|
||||
"node": ">=10",
|
||||
"pnpm": ">=3"
|
||||
},
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"build": "tsc"
|
||||
},
|
||||
"repository": "https://github.com/fluencelabs/fluence-js",
|
||||
"author": "Fluence Labs",
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"serve-handler": "6.1.5"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/serve-handler": "6.1.1"
|
||||
}
|
||||
"name": "@test/test-utils",
|
||||
"version": "0.1.0",
|
||||
"description": "Test utils",
|
||||
"main": "./dist/index.js",
|
||||
"typings": "./dist/index.d.ts",
|
||||
"engines": {
|
||||
"node": ">=10",
|
||||
"pnpm": ">=3"
|
||||
},
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"build": "tsc"
|
||||
},
|
||||
"repository": "https://github.com/fluencelabs/fluence-js",
|
||||
"author": "Fluence Labs",
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"serve-handler": "6.1.5"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/serve-handler": "6.1.1"
|
||||
}
|
||||
}
|
||||
|
@ -1,48 +1,82 @@
|
||||
import handler from 'serve-handler';
|
||||
import { createServer } from 'http';
|
||||
import type { Server } from 'http';
|
||||
/**
|
||||
* Copyright 2023 Fluence Labs Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { dirname, join } from 'path';
|
||||
import { fileURLToPath } from 'url';
|
||||
import { createServer } from "http";
|
||||
import type { Server } from "http";
|
||||
import { dirname, join } from "path";
|
||||
import { fileURLToPath } from "url";
|
||||
|
||||
import handler from "serve-handler";
|
||||
|
||||
const __dirname = dirname(fileURLToPath(import.meta.url));
|
||||
|
||||
export const CDN_PUBLIC_PATH = join(__dirname, '../../../core/js-client/dist/browser');
|
||||
export const CDN_PUBLIC_PATH = join(
|
||||
__dirname,
|
||||
"../../../core/js-client/dist/browser",
|
||||
);
|
||||
|
||||
export const startCdn = (port: number) => startContentServer(port, CDN_PUBLIC_PATH);
|
||||
export const startCdn = (port: number) => {
|
||||
return startContentServer(port, CDN_PUBLIC_PATH);
|
||||
};
|
||||
|
||||
export const startContentServer = (port: number, publicDir: string): Promise<Server> => {
|
||||
const server = createServer((request, response) => {
|
||||
return handler(request, response, {
|
||||
public: publicDir,
|
||||
rewrites: [{
|
||||
source: '/js-client.min.js',
|
||||
destination: '/source/index.umd.cjs'
|
||||
}],
|
||||
headers: [{
|
||||
source: '**/*',
|
||||
headers: [
|
||||
{ key: 'Cross-Origin-Opener-Policy', value: 'same-origin' },
|
||||
{ key: 'Cross-Origin-Embedder-Policy', value: 'require-corp' }
|
||||
]
|
||||
}]
|
||||
});
|
||||
export const startContentServer = (
|
||||
port: number,
|
||||
publicDir: string,
|
||||
): Promise<Server> => {
|
||||
const server = createServer((request, response) => {
|
||||
void handler(request, response, {
|
||||
public: publicDir,
|
||||
rewrites: [
|
||||
{
|
||||
source: "/js-client.min.js",
|
||||
destination: "/source/index.umd.cjs",
|
||||
},
|
||||
],
|
||||
headers: [
|
||||
{
|
||||
source: "**/*",
|
||||
headers: [
|
||||
{
|
||||
key: "Cross-Origin-Opener-Policy",
|
||||
value: "same-origin",
|
||||
},
|
||||
{
|
||||
key: "Cross-Origin-Embedder-Policy",
|
||||
value: "require-corp",
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
|
||||
return new Promise<Server>((resolve) => {
|
||||
const result = server.listen(port, () => {
|
||||
console.log(`server started on port ${port}`);
|
||||
console.log(`public dir ${publicDir}`);
|
||||
resolve(result);
|
||||
});
|
||||
return new Promise<Server>((resolve) => {
|
||||
const result = server.listen(port, () => {
|
||||
console.log(`server started on port ${port}`);
|
||||
console.log(`public dir ${publicDir}`);
|
||||
resolve(result);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
export const stopServer = (app: Server): Promise<void> => {
|
||||
return new Promise<void>((resolve) => {
|
||||
app.close(() => {
|
||||
console.log('server stopped');
|
||||
resolve();
|
||||
});
|
||||
return new Promise<void>((resolve) => {
|
||||
app.close(() => {
|
||||
console.log("server stopped");
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
};
|
||||
|
@ -1,7 +1,8 @@
|
||||
{
|
||||
"extends": "../../../tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"outDir": "./dist"
|
||||
},
|
||||
"exclude": ["node_modules", "dist"]
|
||||
"extends": "../../../tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"outDir": "./dist"
|
||||
},
|
||||
"include": ["src"],
|
||||
"exclude": ["node_modules", "dist"]
|
||||
}
|
||||
|
Reference in New Issue
Block a user