Skip to content

Commit

Permalink
output metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
JairusSW committed Jul 17, 2024
1 parent f36e38c commit 663aa0b
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 253 deletions.
10 changes: 6 additions & 4 deletions assembly/__tests__/sleep.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { describe, expect, run, test } from "..";
import { describe, expect, log, run, test } from "..";
import { sleep } from "as-sleep/assembly";
describe("Should sleep", () => {
test("1ms", () => {
Expand All @@ -16,10 +16,12 @@ describe("Should sleep", () => {
sleep(1000);
expect(Date.now() - start).toBeGreaterOrEqualTo(1000);
});
test("10s", () => {
test("5s", () => {
const start = Date.now();
sleep(10000);
expect(Date.now() - start).toBeGreaterOrEqualTo(10000);
log("Sleeping...")
sleep(5000);
log("Done!")
expect(Date.now() - start).toBeGreaterOrEqualTo(5000);
});
});

Expand Down
2 changes: 1 addition & 1 deletion assembly/src/log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ export class Log {
this.text = text;
}
display(): void {
term.write(" ".repeat(this.depth + 1) + `${rainbow.bgMagentaBright(" LOG ")}${rainbow.dimMk(":")} ${this.text}\n`);
term.write(" ".repeat(this.depth + 1) + `${rainbow.bgBlackBright(" LOG ")}${rainbow.dimMk(":")} ${this.text}\n`);
}
}
101 changes: 52 additions & 49 deletions bin/run.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import chalk from "chalk";
import { exec } from "child_process";
import { glob } from "glob";
import { getExec, loadConfig } from "./util.js";
import { formatTime, getExec, loadConfig } from "./util.js";
import * as path from "path";
import { writeFileSync } from "fs";
import { existsSync, mkdirSync, writeFileSync } from "fs";
const CONFIG_PATH = path.join(process.cwd(), "./as-test.config.json");
const ansi = new RegExp("[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)|(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-nq-uy=><~]))", "g");
export async function run() {
Expand Down Expand Up @@ -40,7 +40,7 @@ export async function run() {
.replace(command, execPath)
.replace("<file>", outFile.replace(".wasm", ".js"));
}
const report = await (() => {
const report = JSON.parse(await (() => {
return new Promise((res, _) => {
let stdout = "";
const io = exec(cmd);
Expand All @@ -53,54 +53,57 @@ export async function run() {
res(stdout);
});
});
})();
})());
reports.push(report);
}
writeFileSync(path.join(process.cwd(), config.logs, "test.log.json"), reports.join("\n\n"));
// if (config.logs && config.logs != "none") {
// if (!existsSync(path.join(process.cwd(), config.logs))) {
// mkdirSync(path.join(process.cwd(), config.logs));
// }
// writeFileSync(path.join(process.cwd(), config.logs, "test.log.json"), JSON.stringify(reports, null, 2));
// }
// const reporter = new Reporter(reports);
// if (reporter.failed.length) {
// console.log(chalk.dim("----------------- [FAILED] -------------------\n"));
// for (const failed of reporter.failed) {
// console.log(`${chalk.bgRed(" FAIL ")} ${chalk.dim(failed.description)}\n`);
// for (const test of failed.tests) {
// if (test.verdict == "fail") {
// console.log(`${chalk.dim("(expected) ->")} ${chalk.bold(test._left.toString())}`);
// console.log(`${chalk.dim("(received) ->")} ${chalk.bold(test._right.toString())}\n`);
// }
// }
// }
// }
// console.log("----------------- [RESULTS] ------------------\n");
// process.stdout.write(chalk.bold("Files: "));
// if (reporter.failedFiles) {
// process.stdout.write(chalk.bold.red(reporter.failedFiles + " failed"));
// } else {
// process.stdout.write(chalk.bold.greenBright("0 failed"));
// }
// process.stdout.write(", " + (reporter.failedFiles + reporter.passedFiles) + " total\n");
// process.stdout.write(chalk.bold("Suites: "));
// if (reporter.failedSuites) {
// process.stdout.write(chalk.bold.red(reporter.failedSuites + " failed"));
// } else {
// process.stdout.write(chalk.bold.greenBright("0 failed"));
// }
// process.stdout.write(", " + (reporter.failedSuites + reporter.passedSuites) + " total\n");
// process.stdout.write(chalk.bold("Tests: "));
// if (reporter.failedTests) {
// process.stdout.write(chalk.bold.red(reporter.failedTests + " failed"));
// } else {
// process.stdout.write(chalk.bold.greenBright("0 failed"));
// }
// process.stdout.write(", " + (reporter.failedTests + reporter.passedTests) + " total\n");
// process.stdout.write(chalk.bold("Time: ") + formatTime(reporter.time) + "\n");
// if (reporter.failedFiles) process.exit(1);
// process.exit(0);
if (config.logs && config.logs != "none") {
if (!existsSync(path.join(process.cwd(), config.logs))) {
mkdirSync(path.join(process.cwd(), config.logs));
}
writeFileSync(path.join(process.cwd(), config.logs, "test.log.json"), JSON.stringify(reports, null, 2));
}
const reporter = new Reporter(reports);
if (reporter.failed.length) {
console.log(chalk.dim("----------------- [FAILED] -------------------\n"));
for (const failed of reporter.failed) {
console.log(`${chalk.bgRed(" FAIL ")} ${chalk.dim(failed.description)}\n`);
for (const test of failed.tests) {
if (test.verdict == "fail") {
console.log(`${chalk.dim("(expected) ->")} ${chalk.bold(test._left.toString())}`);
console.log(`${chalk.dim("(received) ->")} ${chalk.bold(test._right.toString())}\n`);
}
}
}
}
console.log("----------------- [RESULTS] ------------------\n");
process.stdout.write(chalk.bold("Files: "));
if (reporter.failedFiles) {
process.stdout.write(chalk.bold.red(reporter.failedFiles + " failed"));
}
else {
process.stdout.write(chalk.bold.greenBright("0 failed"));
}
process.stdout.write(", " + (reporter.failedFiles + reporter.passedFiles) + " total\n");
process.stdout.write(chalk.bold("Suites: "));
if (reporter.failedSuites) {
process.stdout.write(chalk.bold.red(reporter.failedSuites + " failed"));
}
else {
process.stdout.write(chalk.bold.greenBright("0 failed"));
}
process.stdout.write(", " + (reporter.failedSuites + reporter.passedSuites) + " total\n");
process.stdout.write(chalk.bold("Tests: "));
if (reporter.failedTests) {
process.stdout.write(chalk.bold.red(reporter.failedTests + " failed"));
}
else {
process.stdout.write(chalk.bold.greenBright("0 failed"));
}
process.stdout.write(", " + (reporter.failedTests + reporter.passedTests) + " total\n");
process.stdout.write(chalk.bold("Time: ") + formatTime(reporter.time) + "\n");
if (reporter.failedFiles)
process.exit(1);
process.exit(0);
}
class Reporter {
constructor(reports) {
Expand Down
4 changes: 2 additions & 2 deletions cli/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export async function run() {
.replace("<file>", outFile.replace(".wasm", ".js"));
}

const report = await (() => {
const report = JSON.parse(await (() => {
return new Promise<string>((res, _) => {
let stdout = "";
const io = exec(cmd);
Expand All @@ -65,7 +65,7 @@ export async function run() {
res(stdout);
});
});
})();
})());
reports.push(report);
}

Expand Down
197 changes: 0 additions & 197 deletions reporters/log/index.ts

This file was deleted.

Empty file removed test.config.json
Empty file.

0 comments on commit 663aa0b

Please sign in to comment.