From 39865529cc4774ed87d18ef9bed437e2eaec7eae Mon Sep 17 00:00:00 2001 From: shyam-raghuwanshi Date: Tue, 9 Jul 2024 23:40:09 +0530 Subject: [PATCH] adding-testcases --- JS/wasm/tests/wasmtestcases/.gitignore | 2 + JS/wasm/tests/wasmtestcases/app.log | 33 +++++++++ JS/wasm/tests/wasmtestcases/build.js | 19 +++++ JS/wasm/tests/wasmtestcases/package.json | 24 +++++++ JS/wasm/tests/wasmtestcases/src/index.js | 8 +++ JS/wasm/tests/wasmtestcases/test/all.test.js | 74 ++++++++++++++++++++ 6 files changed, 160 insertions(+) create mode 100644 JS/wasm/tests/wasmtestcases/.gitignore create mode 100644 JS/wasm/tests/wasmtestcases/app.log create mode 100644 JS/wasm/tests/wasmtestcases/build.js create mode 100644 JS/wasm/tests/wasmtestcases/package.json create mode 100644 JS/wasm/tests/wasmtestcases/src/index.js create mode 100644 JS/wasm/tests/wasmtestcases/test/all.test.js diff --git a/JS/wasm/tests/wasmtestcases/.gitignore b/JS/wasm/tests/wasmtestcases/.gitignore new file mode 100644 index 00000000..9e87c054 --- /dev/null +++ b/JS/wasm/tests/wasmtestcases/.gitignore @@ -0,0 +1,2 @@ +node_modules +bin \ No newline at end of file diff --git a/JS/wasm/tests/wasmtestcases/app.log b/JS/wasm/tests/wasmtestcases/app.log new file mode 100644 index 00000000..e309d982 --- /dev/null +++ b/JS/wasm/tests/wasmtestcases/app.log @@ -0,0 +1,33 @@ +nohup: failed to run command '/home/shyam/pr/EdgeChains/target/release/arakoo': No such file or directory +nohup: failed to run command '/home/shyam/pr/EdgeChains/target/release/arakoo': No such file or directory +nohup: failed to run command '/home/shyam/pr/EdgeChains/target/release/arakoo': No such file or directory +nohup: failed to run command '/home/shyam/pr/EdgeChains/target/release/arakoo': No such file or directory +nohup: failed to run command '/home/shyam/pr/EdgeChains/target/release/arakoo': No such file or directory +nohup: failed to run command '/home/shyam/pr/EdgeChains/target/release/arakoo': No such file or directory +nohup: failed to run command '/home/shyam/pr/EdgeChains/target/release/arakoo': No such file or directory +2024-07-09T17:54:34.325248Z INFO Loading Component from "/home/shyam/pr/EdgeChains/JS/wasm/test/wasmtestcases/index.wasm" +2024-07-09T17:54:35.429767Z INFO Starting server ... +2024-07-09T17:54:35.429968Z INFO Listening on http://127.0.0.1:8080 +2024-07-09T17:54:38.377628Z INFO Handling request: GET /hello +Successfully responded to request +2024-07-09T17:55:41.371997Z INFO Loading Component from "/home/shyam/pr/EdgeChains/JS/wasm/test/wasmtestcases/index.wasm" +2024-07-09T17:55:42.905582Z INFO Starting server ... +thread 'main' panicked at /home/shyam/.cargo/registry/src/index.crates.io-6f17d22bba15001f/hyper-0.14.29/src/server/server.rs:81:13: +error binding to 127.0.0.1:8080: error creating server listener: Address already in use (os error 98) +note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace +2024-07-09T17:55:45.386989Z INFO Handling request: GET /hello +Successfully responded to request +2024-07-09T17:56:40.841915Z INFO Loading Component from "/home/shyam/pr/EdgeChains/JS/wasm/test/wasmtestcases/index.wasm" +2024-07-09T17:56:42.408213Z INFO Starting server ... +thread 'main' panicked at /home/shyam/.cargo/registry/src/index.crates.io-6f17d22bba15001f/hyper-0.14.29/src/server/server.rs:81:13: +error binding to 127.0.0.1:8080: error creating server listener: Address already in use (os error 98) +note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace +2024-07-09T17:56:44.861415Z INFO Handling request: GET /hello +Successfully responded to request +2024-07-09T18:04:21.691950Z INFO Loading Component from "/home/shyam/pr/EdgeChains/JS/wasm/test/wasmtestcases/index.wasm" +2024-07-09T18:04:23.663535Z INFO Starting server ... +thread 'main' panicked at /home/shyam/.cargo/registry/src/index.crates.io-6f17d22bba15001f/hyper-0.14.29/src/server/server.rs:81:13: +error binding to 127.0.0.1:8080: error creating server listener: Address already in use (os error 98) +note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace +2024-07-09T18:04:25.709603Z INFO Handling request: GET /hello +Successfully responded to request diff --git a/JS/wasm/tests/wasmtestcases/build.js b/JS/wasm/tests/wasmtestcases/build.js new file mode 100644 index 00000000..66d297ff --- /dev/null +++ b/JS/wasm/tests/wasmtestcases/build.js @@ -0,0 +1,19 @@ +import { build } from "esbuild"; + +let runtime = process.argv[2]; + +build({ + entryPoints: ["src/index.js"], + bundle: true, + minify: false, + outfile: "bin/index.js", + format: "esm", + target: "esnext", + platform: "node", + define: { + "process.env.arakoo": JSON.stringify(runtime === "arakoo"), + }, +}).catch((error) => { + console.error(error); + process.exit(1); +}); diff --git a/JS/wasm/tests/wasmtestcases/package.json b/JS/wasm/tests/wasmtestcases/package.json new file mode 100644 index 00000000..ee7dc92a --- /dev/null +++ b/JS/wasm/tests/wasmtestcases/package.json @@ -0,0 +1,24 @@ +{ + "name": "pdfparse", + "version": "1.0.0", + "description": "", + "main": "index.js", + "type": "module", + "scripts": { + "test": "vitest" + }, + "keywords": [], + "author": "", + "license": "ISC", + "dependencies": { + "@hono/node-server": "^1.12.0", + "axios": "^1.7.2", + "child_process": "^1.0.2", + "esbuild": "^0.23.0", + "hono": "^3.9", + "nohup": "^0.1.0" + }, + "devDependencies": { + "vitest": "^2.0.1" + } +} diff --git a/JS/wasm/tests/wasmtestcases/src/index.js b/JS/wasm/tests/wasmtestcases/src/index.js new file mode 100644 index 00000000..fa93688a --- /dev/null +++ b/JS/wasm/tests/wasmtestcases/src/index.js @@ -0,0 +1,8 @@ +import { Hono } from "hono"; +const app = new Hono(); + +app.get("/hello", (c) => { + return c.text("Hello World"); +}); + +app.fire(); \ No newline at end of file diff --git a/JS/wasm/tests/wasmtestcases/test/all.test.js b/JS/wasm/tests/wasmtestcases/test/all.test.js new file mode 100644 index 00000000..31dfd242 --- /dev/null +++ b/JS/wasm/tests/wasmtestcases/test/all.test.js @@ -0,0 +1,74 @@ +import { expect, test } from 'vitest'; +import { execSync, exec} from "child_process" +import fs from 'node:fs/promises'; +import path from 'node:path'; +import axios from 'axios'; + +test("build.js should create bin/index.js", async () => { + try { + execSync(`node build.js`); + const filePath = path.join(__dirname, '../bin/index.js'); + + await fs.access(filePath); + expect(true).toBe(true); + + } catch (error) { + expect(error).toBeUndefined(); + } +}); + +test("should build arakoo-js-engine", async () => { + try { + const shimPath = path.resolve(__dirname, '../../../crates/arakoo-core/src/apis/http/shims'); + execSync(`cd ${shimPath} && npm install && npm run build`, { stdio: 'inherit' }); + execSync("cargo build -p arakoo-js-engine --target=wasm32-wasi -r") + const arakooPath = path.join(__dirname, '../../../../../target/release/arakoo-compiler'); + await fs.access(arakooPath); + expect(true).toBe(true); + } catch (error) { + expect(error).toBeUndefined(); + } +}, 1000000) + +test("should build arakoo", async () => { + try { + execSync("CARGO_PROFILE_RELEASE_LTO=off cargo build -p cli -r") + execSync("cargo build -p serve -r") + const arakooPath = path.join(__dirname, '../../../../../target/release/arakoo'); + await fs.access(arakooPath); + expect(true).toBe(true); + } catch (error) { + expect(error).toBeUndefined(); + } +}, 1000000) + +test("should be create a index.wasm file", async () => { + try { + const arakooPath = path.resolve(__dirname, '../../../../../target/release/arakoo-compiler'); + const indexFile = path.resolve(__dirname, '../bin/index.js'); + const filePath = path.join(__dirname, "../index.wasm"); + execSync(`${arakooPath} ${indexFile}`); + await fs.access(filePath); + expect(true).toBe(true); + } catch (error) { + expect(error).toBeUndefined(); + } +}) + + + +test("should start server", async() => { + const arakooPath = path.resolve(__dirname, '../../../../../target/release/arakoo'); + const indexFile = path.resolve(__dirname, '../index.wasm'); + + console.log(arakooPath, indexFile); + + exec(`nohup ${arakooPath} ${indexFile} >> app.log 2>&1 &`); + + await new Promise((resolve) => setTimeout(resolve, 4000)); +}); + +test("should get the response", async () => { + const response = await axios.get("http://127.0.0.1:8080/hello"); + expect(response.data).toBe("Hello World"); +}) \ No newline at end of file