Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding-testcases #397

Merged
merged 1 commit into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions JS/wasm/tests/wasmtestcases/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
bin
33 changes: 33 additions & 0 deletions JS/wasm/tests/wasmtestcases/app.log
Original file line number Diff line number Diff line change
@@ -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
19 changes: 19 additions & 0 deletions JS/wasm/tests/wasmtestcases/build.js
Original file line number Diff line number Diff line change
@@ -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);
});
24 changes: 24 additions & 0 deletions JS/wasm/tests/wasmtestcases/package.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
8 changes: 8 additions & 0 deletions JS/wasm/tests/wasmtestcases/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { Hono } from "hono";
const app = new Hono();

app.get("/hello", (c) => {
return c.text("Hello World");
});

app.fire();
74 changes: 74 additions & 0 deletions JS/wasm/tests/wasmtestcases/test/all.test.js
Original file line number Diff line number Diff line change
@@ -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");
})
Loading