Skip to content

Commit 36c7619

Browse files
author
Akim
authored
fix(tests): Repair integration tests [fixes DXJ-506] (#364)
* Add test server * remove headless * Support for web-cra * Review fixes and bug fixes * Add error message
1 parent 29ec812 commit 36c7619

File tree

18 files changed

+215
-137
lines changed

18 files changed

+215
-137
lines changed

.eslintrc.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"license-header",
1919
"unused-imports"
2020
],
21-
"ignorePatterns": ["**/node_modules/**/*", "**/dist/**/*"],
21+
"ignorePatterns": ["**/node_modules/", "**/dist/", "**/build/", "**/public/"],
2222
"rules": {
2323
"eqeqeq": [
2424
"error",

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ node_modules/
77

88
# Build directory
99
**/dist
10+
**/public

packages/@tests/smoke/web-cra-ts/test/index.ts

+7-6
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ import { fileURLToPath } from "url";
44

55
import {
66
CDN_PUBLIC_PATH,
7+
createSymlinkIfNotExists,
8+
JS_CLIENT_DEPS_PATH,
79
startContentServer,
810
stopServer,
911
} from "@test/test-utils";
10-
import { access, symlink } from "fs/promises";
1112

1213
const port = 3001;
1314
const uri = `http://localhost:${port}/`;
@@ -16,11 +17,11 @@ const publicPath = join(__dirname, "../build/");
1617

1718
const test = async () => {
1819
const localServer = await startContentServer(port, publicPath);
19-
try {
20-
await access(join(publicPath, "source"));
21-
} catch {
22-
await symlink(CDN_PUBLIC_PATH, join(publicPath, "source"));
23-
}
20+
await createSymlinkIfNotExists(CDN_PUBLIC_PATH, join(publicPath, "source"));
21+
await createSymlinkIfNotExists(
22+
JS_CLIENT_DEPS_PATH,
23+
join(publicPath, "node_modules"),
24+
);
2425

2526
console.log("starting puppeteer...");
2627
const browser = await puppeteer.launch();

packages/@tests/smoke/web/public/index.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,9 @@ const getRelayTime = () => {
8585

8686
const main = async () => {
8787
console.log("starting fluence...");
88-
fluence.defaultClient = await fluence.clientFactory(relay, {});
88+
fluence.defaultClient = await fluence.clientFactory(relay, {
89+
CDNUrl: "http://localhost:3000",
90+
});
8991
console.log("started fluence");
9092

9193
console.log("getting relay time...");

packages/@tests/smoke/web/src/index.ts

+8-6
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,13 @@
1414
* limitations under the License.
1515
*/
1616

17-
import { symlink, access } from "fs/promises";
1817
import { dirname, join } from "path";
1918
import { fileURLToPath } from "url";
2019

2120
import {
2221
CDN_PUBLIC_PATH,
22+
createSymlinkIfNotExists,
23+
JS_CLIENT_DEPS_PATH,
2324
startContentServer,
2425
stopServer,
2526
} from "@test/test-utils";
@@ -33,11 +34,12 @@ const publicPath = join(__dirname, "../public/");
3334
const test = async () => {
3435
const localServer = await startContentServer(port, publicPath);
3536

36-
try {
37-
await access(join(publicPath, "source"));
38-
} catch {
39-
await symlink(CDN_PUBLIC_PATH, join(publicPath, "source"));
40-
}
37+
await createSymlinkIfNotExists(CDN_PUBLIC_PATH, join(publicPath, "source"));
38+
39+
await createSymlinkIfNotExists(
40+
JS_CLIENT_DEPS_PATH,
41+
join(publicPath, "node_modules"),
42+
);
4143

4244
console.log("starting puppeteer...");
4345
const browser = await puppeteer.launch();

packages/@tests/test-utils/src/index.ts

+33
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17+
import { access, symlink } from "fs/promises";
1718
import { createServer } from "http";
1819
import type { Server } from "http";
1920
import { dirname, join } from "path";
@@ -28,10 +29,26 @@ export const CDN_PUBLIC_PATH = join(
2829
"../../../core/js-client/dist/browser",
2930
);
3031

32+
export const JS_CLIENT_DEPS_PATH = join(
33+
__dirname,
34+
"../../../core/js-client/node_modules",
35+
);
36+
3137
export const startCdn = (port: number) => {
3238
return startContentServer(port, CDN_PUBLIC_PATH);
3339
};
3440

41+
export const createSymlinkIfNotExists = async (
42+
target: string,
43+
path: string,
44+
) => {
45+
try {
46+
await access(path);
47+
} catch {
48+
await symlink(target, path);
49+
}
50+
};
51+
3552
export const startContentServer = (
3653
port: number,
3754
publicDir: string,
@@ -44,6 +61,22 @@ export const startContentServer = (
4461
source: "/js-client.min.js",
4562
destination: "/source/index.umd.cjs",
4663
},
64+
// TODO:
65+
// something like this
66+
// {
67+
// source: "/@fluencelabs/:name(\\w+)@:version([\\d.]+)/:path*",
68+
// destination: "/deps/@fluencelabs/:name/:path",
69+
// }
70+
// not supported for some reason. Need to manually iterate over all possible paths
71+
{
72+
source: "/@fluencelabs/:name([\\w-]+)@:version([\\d.]+)/dist/:asset",
73+
destination: "/node_modules/@fluencelabs/:name/dist/:asset",
74+
},
75+
{
76+
source:
77+
"/@fluencelabs/:name([\\w-]+)@:version([\\d.]+)/dist/:prefix/:asset",
78+
destination: "/node_modules/@fluencelabs/:name/dist/:prefix/:asset",
79+
},
4780
],
4881
headers: [
4982
{

packages/core/interfaces/src/commonTypes.ts

-8
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,6 @@ import { InterfaceToType, MaybePromise } from "./utils.js";
2323
*/
2424
export type PeerIdB58 = string;
2525

26-
/**
27-
* Node of the Fluence network specified as a pair of node's multiaddr and it's peer id
28-
*/
29-
export type Node = {
30-
peerId: PeerIdB58;
31-
multiaddr: string;
32-
};
33-
3426
/**
3527
* Additional information about a service call
3628
* @typeparam ArgName

packages/core/interfaces/src/compilerSupport/compilerSupportInterface.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
*/
1616

1717
import { JSONValue } from "../commonTypes.js";
18-
import { IFluenceInternalApi } from "../fluenceClient.js";
1918

2019
import {
2120
FnConfig,
@@ -38,11 +37,12 @@ export type PassedArgs = { [key: string]: JSONValue | ArgCallbackFunction };
3837
/**
3938
* Arguments for callAquaFunction function
4039
*/
40+
// TODO: move to js-client side
4141
export interface CallAquaFunctionArgs {
4242
/**
4343
* Peer to call the function on
4444
*/
45-
peer: IFluenceInternalApi;
45+
peer: unknown;
4646

4747
/**
4848
* Function definition
@@ -79,7 +79,7 @@ export interface RegisterServiceArgs {
7979
/**
8080
* Peer to register the service on
8181
*/
82-
peer: IFluenceInternalApi;
82+
peer: unknown;
8383

8484
/**
8585
* Service definition

packages/core/interfaces/src/index.ts

-1
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,4 @@
1717
export * from "./compilerSupport/aquaTypeDefinitions.js";
1818
export * from "./compilerSupport/compilerSupportInterface.js";
1919
export * from "./commonTypes.js";
20-
export * from "./fluenceClient.js";
2120
export * from "./future.js";

packages/core/js-client/src/clientPeer/ClientPeer.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,6 @@
1414
* limitations under the License.
1515
*/
1616

17-
import {
18-
ClientConfig,
19-
ConnectionState,
20-
IFluenceClient,
21-
RelayOptions,
22-
} from "@fluencelabs/interfaces";
23-
2417
import {
2518
RelayConnection,
2619
RelayConnectionConfig,
@@ -32,6 +25,13 @@ import { IMarineHost } from "../marine/interfaces.js";
3225
import { relayOptionToMultiaddr } from "../util/libp2pUtils.js";
3326
import { logger } from "../util/logger.js";
3427

28+
import {
29+
ClientConfig,
30+
IFluenceClient,
31+
ConnectionState,
32+
RelayOptions,
33+
} from "./types.js";
34+
3535
const log = logger("client");
3636

3737
const DEFAULT_TTL_MS = 7000;

packages/core/interfaces/src/fluenceClient.ts renamed to packages/core/js-client/src/clientPeer/types.ts

+75-59
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,18 @@
1414
* limitations under the License.
1515
*/
1616

17-
import type { Node } from "./commonTypes.js";
17+
/**
18+
* Peer ID's id as a base58 string (multihash/CIDv0).
19+
*/
20+
export type PeerIdB58 = string;
21+
22+
/**
23+
* Node of the Fluence network specified as a pair of node's multiaddr and it's peer id
24+
*/
25+
export type Node = {
26+
peerId: PeerIdB58;
27+
multiaddr: string;
28+
};
1829

1930
/**
2031
* A node in Fluence network a client can connect to.
@@ -37,64 +48,6 @@ export type KeyPairOptions = {
3748
source: "random" | Uint8Array;
3849
};
3950

40-
/**
41-
* Configuration used when initiating Fluence Client
42-
*/
43-
export interface ClientConfig {
44-
/**
45-
* Specify the KeyPair to be used to identify the Fluence Peer.
46-
* Will be generated randomly if not specified
47-
*/
48-
keyPair?: KeyPairOptions;
49-
50-
/**
51-
* Options to configure the connection to the Fluence network
52-
*/
53-
connectionOptions?: {
54-
/**
55-
* When the peer established the connection to the network it sends a ping-like message to check if it works correctly.
56-
* The options allows to specify the timeout for that message in milliseconds.
57-
* If not specified the default timeout will be used
58-
*/
59-
skipCheckConnection?: boolean;
60-
61-
/**
62-
* The dialing timeout in milliseconds
63-
*/
64-
dialTimeoutMs?: number;
65-
66-
/**
67-
* The maximum number of inbound streams for the libp2p node.
68-
* Default: 1024
69-
*/
70-
maxInboundStreams?: number;
71-
72-
/**
73-
* The maximum number of outbound streams for the libp2p node.
74-
* Default: 1024
75-
*/
76-
maxOutboundStreams?: number;
77-
};
78-
79-
/**
80-
* Sets the default TTL for all particles originating from the peer with no TTL specified.
81-
* If the originating particle's TTL is defined then that value will be used
82-
* If the option is not set default TTL will be 7000
83-
*/
84-
defaultTtlMs?: number;
85-
86-
/**
87-
* Enables\disabled various debugging features
88-
*/
89-
debug?: {
90-
/**
91-
* If set to true, newly initiated particle ids will be printed to console.
92-
* Useful to see what particle id is responsible for aqua function
93-
*/
94-
printParticleId?: boolean;
95-
};
96-
}
97-
9851
/**
9952
* Fluence JS Client connection states as string literals
10053
*/
@@ -153,3 +106,66 @@ export interface IFluenceClient extends IFluenceInternalApi {
153106
*/
154107
getRelayPeerId(): string;
155108
}
109+
110+
/**
111+
* Configuration used when initiating Fluence Client
112+
*/
113+
export interface ClientConfig {
114+
/**
115+
* Specify the KeyPair to be used to identify the Fluence Peer.
116+
* Will be generated randomly if not specified
117+
*/
118+
keyPair?: KeyPairOptions;
119+
120+
/**
121+
* Options to configure the connection to the Fluence network
122+
*/
123+
connectionOptions?: {
124+
/**
125+
* When the peer established the connection to the network it sends a ping-like message to check if it works correctly.
126+
* The options allows to specify the timeout for that message in milliseconds.
127+
* If not specified the default timeout will be used
128+
*/
129+
skipCheckConnection?: boolean;
130+
131+
/**
132+
* The dialing timeout in milliseconds
133+
*/
134+
dialTimeoutMs?: number;
135+
136+
/**
137+
* The maximum number of inbound streams for the libp2p node.
138+
* Default: 1024
139+
*/
140+
maxInboundStreams?: number;
141+
142+
/**
143+
* The maximum number of outbound streams for the libp2p node.
144+
* Default: 1024
145+
*/
146+
maxOutboundStreams?: number;
147+
};
148+
149+
/**
150+
* Sets the default TTL for all particles originating from the peer with no TTL specified.
151+
* If the originating particle's TTL is defined then that value will be used
152+
* If the option is not set default TTL will be 7000
153+
*/
154+
defaultTtlMs?: number;
155+
156+
/**
157+
* Property for passing custom CDN Url to load dependencies from browser. https://unpkg.com used by default
158+
*/
159+
CDNUrl?: string;
160+
161+
/**
162+
* Enables\disabled various debugging features
163+
*/
164+
debug?: {
165+
/**
166+
* If set to true, newly initiated particle ids will be printed to console.
167+
* Useful to see what particle id is responsible for aqua function
168+
*/
169+
printParticleId?: boolean;
170+
};
171+
}

0 commit comments

Comments
 (0)