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
This commit is contained in:
Akim
2023-10-18 08:38:49 +07:00
committed by GitHub
parent 29ec812fc1
commit 36c7619b4a
18 changed files with 216 additions and 138 deletions

View File

@ -4,10 +4,11 @@ import { fileURLToPath } from "url";
import {
CDN_PUBLIC_PATH,
createSymlinkIfNotExists,
JS_CLIENT_DEPS_PATH,
startContentServer,
stopServer,
} from "@test/test-utils";
import { access, symlink } from "fs/promises";
const port = 3001;
const uri = `http://localhost:${port}/`;
@ -16,11 +17,11 @@ 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"));
}
await createSymlinkIfNotExists(CDN_PUBLIC_PATH, join(publicPath, "source"));
await createSymlinkIfNotExists(
JS_CLIENT_DEPS_PATH,
join(publicPath, "node_modules"),
);
console.log("starting puppeteer...");
const browser = await puppeteer.launch();

View File

@ -85,7 +85,9 @@ const getRelayTime = () => {
const main = async () => {
console.log("starting fluence...");
fluence.defaultClient = await fluence.clientFactory(relay, {});
fluence.defaultClient = await fluence.clientFactory(relay, {
CDNUrl: "http://localhost:3000",
});
console.log("started fluence");
console.log("getting relay time...");

View File

@ -14,12 +14,13 @@
* limitations under the License.
*/
import { symlink, access } from "fs/promises";
import { dirname, join } from "path";
import { fileURLToPath } from "url";
import {
CDN_PUBLIC_PATH,
createSymlinkIfNotExists,
JS_CLIENT_DEPS_PATH,
startContentServer,
stopServer,
} from "@test/test-utils";
@ -33,11 +34,12 @@ 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"));
}
await createSymlinkIfNotExists(CDN_PUBLIC_PATH, join(publicPath, "source"));
await createSymlinkIfNotExists(
JS_CLIENT_DEPS_PATH,
join(publicPath, "node_modules"),
);
console.log("starting puppeteer...");
const browser = await puppeteer.launch();

View File

@ -14,6 +14,7 @@
* limitations under the License.
*/
import { access, symlink } from "fs/promises";
import { createServer } from "http";
import type { Server } from "http";
import { dirname, join } from "path";
@ -28,10 +29,26 @@ export const CDN_PUBLIC_PATH = join(
"../../../core/js-client/dist/browser",
);
export const JS_CLIENT_DEPS_PATH = join(
__dirname,
"../../../core/js-client/node_modules",
);
export const startCdn = (port: number) => {
return startContentServer(port, CDN_PUBLIC_PATH);
};
export const createSymlinkIfNotExists = async (
target: string,
path: string,
) => {
try {
await access(path);
} catch {
await symlink(target, path);
}
};
export const startContentServer = (
port: number,
publicDir: string,
@ -44,6 +61,22 @@ export const startContentServer = (
source: "/js-client.min.js",
destination: "/source/index.umd.cjs",
},
// TODO:
// something like this
// {
// source: "/@fluencelabs/:name(\\w+)@:version([\\d.]+)/:path*",
// destination: "/deps/@fluencelabs/:name/:path",
// }
// not supported for some reason. Need to manually iterate over all possible paths
{
source: "/@fluencelabs/:name([\\w-]+)@:version([\\d.]+)/dist/:asset",
destination: "/node_modules/@fluencelabs/:name/dist/:asset",
},
{
source:
"/@fluencelabs/:name([\\w-]+)@:version([\\d.]+)/dist/:prefix/:asset",
destination: "/node_modules/@fluencelabs/:name/dist/:prefix/:asset",
},
],
headers: [
{