Skip to content

Commit

Permalink
exit with code
Browse files Browse the repository at this point in the history
  • Loading branch information
JairusSW committed Jul 16, 2024
1 parent 3a38426 commit 8ff4ed1
Show file tree
Hide file tree
Showing 38 changed files with 1,788 additions and 1,705 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/as-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:

- name: Build reporter
run: bun run build:log

- name: Build tests
run: bun run pretest

Expand Down
2 changes: 1 addition & 1 deletion as-test.config.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"input": ["./assembly/__tests__/*.spec.ts"],
"outDir": "./build",
"config": "./asconfig.json",
"config": "none",
"plugins": {
"coverage": true
},
Expand Down
4 changes: 3 additions & 1 deletion assembly/__tests__/array.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ describe("Array manipulation", () => {
expect(myArray).toContain(2);
});

it("should be empty", () => {});
it("should be empty", () => {
expect("ag").toBe("asd")
});
});

run({
Expand Down
42 changes: 21 additions & 21 deletions assembly/__tests__/sleep.spec.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
import { describe, expect, run, test } from "..";
import { sleep } from "as-sleep/assembly";
describe("Should sleep", () => {
test("1ms", () => {
const start = Date.now();
sleep(1);
expect(Date.now() - start).toBeGreaterOrEqualTo(1);
});
test("10ms", () => {
const start = Date.now();
sleep(10);
expect(Date.now() - start).toBeGreaterOrEqualTo(10);
});
test("100ms", () => {
const start = Date.now();
sleep(100);
expect(Date.now() - start).toBeGreaterOrEqualTo(1010);
});
test("1s", () => {
const start = Date.now();
sleep(1000);
expect(Date.now() - start).toBeGreaterOrEqualTo(1000);
});
test("1ms", () => {
const start = Date.now();
sleep(1);
expect(Date.now() - start).toBeGreaterOrEqualTo(1);
});
test("10ms", () => {
const start = Date.now();
sleep(10);
expect(Date.now() - start).toBeGreaterOrEqualTo(10);
});
test("100ms", () => {
const start = Date.now();
sleep(100);
expect(Date.now() - start).toBeGreaterOrEqualTo(100);
});
test("1s", () => {
const start = Date.now();
sleep(1000);
expect(Date.now() - start).toBeGreaterOrEqualTo(1000);
});
});

run();
run();
10 changes: 4 additions & 6 deletions assembly/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ let entrySuites: Suite[] = [];

// Globals
@global let suites: Suite[] = [];

@global let depth: i32 = -1;

@global let current_suite: Suite | null = null;

let before_all_callback: (() => void) | null = null;
Expand Down Expand Up @@ -226,17 +228,13 @@ export function mockFn<returnType>(
* Unmock all references to an existing function to instead point to the original function
* @param {string} fn - name of function to override
*/
export function unmockFn(
fn: string
): void {}
export function unmockFn(fn: string): void {}

/**
* Re-mock all references to an existing function to instead point to the declared function
* @param {string} fn - name of function to override
*/
export function remockFn(
fn: string
): void {}
export function remockFn(fn: string): void {}

/**
* Class defining options that can be passed to the `run` function.
Expand Down
4 changes: 2 additions & 2 deletions assembly/src/suite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export class Suite {
public depth: i32 = 0;
public suites: Suite[] = [];
public tests: Tests[] = [];
public kind!: SuiteKind;
public kind: SuiteKind;

public verdict: Verdict = Verdict.None;

Expand Down Expand Up @@ -64,4 +64,4 @@ export class Suite {
if (this.suites.length) this.verdict = Verdict.Ok;
}
}
}
}
228 changes: 132 additions & 96 deletions bin/about.js
Original file line number Diff line number Diff line change
@@ -1,99 +1,135 @@
import chalk from "chalk";
export function about() {
console.log(chalk.bold.blueBright("as-test") +
" is a testing framework for AssemblyScript. " +
chalk.dim("(v" + version + ")") +
"\n");
console.log(chalk.bold("Usage: as-test") +
" " +
chalk.dim("<command>") +
" " +
chalk.bold.blueBright("[...flags]") +
" " +
chalk.bold("[...args]") +
" " +
chalk.dim("(alias: ast)") +
"\n");
console.log(chalk.bold("Commands:"));
console.log(" " +
chalk.bold.blueBright("run") +
" " +
chalk.dim("<my-test.spec.ts>") +
" " +
"Run unit tests with selected runtime");
console.log(" " +
chalk.bold.blueBright("build") +
" " +
chalk.dim("<my-test.spec.ts>") +
" " +
"Build unit tests and compile");
console.log(" " +
chalk.bold.blueBright("test") +
" " +
chalk.dim("<my-test.spec.ts>") +
" " +
"Build and run unit tests with selected runtime" +
"\n");
console.log(" " +
chalk.bold.magentaBright("init") +
" " +
chalk.strikethrough.dim("") +
" " +
"Initialize an empty testing template");
console.log(" " +
chalk.strikethrough.bold.magentaBright("config") +
" " +
chalk.strikethrough.dim("as-test.config.json") +
" " +
"Specify the configuration file");
console.log(" " +
chalk.strikethrough.bold.magentaBright("reporter") +
" " +
chalk.strikethrough.dim("<tap>") +
" " +
"Specify the test reporter to use");
console.log(" " +
chalk.strikethrough.bold.magentaBright("use") +
" " +
chalk.strikethrough.dim("wasmtime") +
" " +
"Specify the runtime to use" +
"\n");
console.log(chalk.bold("Flags:"));
console.log(" " +
chalk.strikethrough.dim("run") +
" " +
chalk.strikethrough.bold.blue("--coverage") +
" " +
"Use code coverage");
console.log(" " +
chalk.strikethrough.dim("run") +
" " +
chalk.strikethrough.bold.blue("--snapshot") +
" " +
"Take a snapshot of the tests");
console.log(" " +
chalk.strikethrough.dim("use") +
" " +
chalk.strikethrough.bold.blue("--list") +
" " +
"List supported runtimes");
console.log(" " +
chalk.strikethrough.dim("reporter") +
" " +
chalk.strikethrough.bold.blue("--list") +
" " +
"List supported reporters");
console.log(" " +
chalk.strikethrough.dim("<command>") +
" " +
chalk.strikethrough.bold.blue("--help") +
" " +
"Print info about command" +
"\n");
console.log(chalk.dim("If your using this, consider dropping a star, it would help a lot!") + "\n");
console.log("View the repo: " +
chalk.magenta("https://github.com/JairusSW/as-test"));
console.log("View the docs: " +
chalk.strikethrough.blue("https://docs.jairus.dev/as-test"));
console.log(
chalk.bold.blueBright("as-test") +
" is a testing framework for AssemblyScript. " +
chalk.dim("(v" + version + ")") +
"\n",
);
console.log(
chalk.bold("Usage: as-test") +
" " +
chalk.dim("<command>") +
" " +
chalk.bold.blueBright("[...flags]") +
" " +
chalk.bold("[...args]") +
" " +
chalk.dim("(alias: ast)") +
"\n",
);
console.log(chalk.bold("Commands:"));
console.log(
" " +
chalk.bold.blueBright("run") +
" " +
chalk.dim("<my-test.spec.ts>") +
" " +
"Run unit tests with selected runtime",
);
console.log(
" " +
chalk.bold.blueBright("build") +
" " +
chalk.dim("<my-test.spec.ts>") +
" " +
"Build unit tests and compile",
);
console.log(
" " +
chalk.bold.blueBright("test") +
" " +
chalk.dim("<my-test.spec.ts>") +
" " +
"Build and run unit tests with selected runtime" +
"\n",
);
console.log(
" " +
chalk.bold.magentaBright("init") +
" " +
chalk.strikethrough.dim("") +
" " +
"Initialize an empty testing template",
);
console.log(
" " +
chalk.strikethrough.bold.magentaBright("config") +
" " +
chalk.strikethrough.dim("as-test.config.json") +
" " +
"Specify the configuration file",
);
console.log(
" " +
chalk.strikethrough.bold.magentaBright("reporter") +
" " +
chalk.strikethrough.dim("<tap>") +
" " +
"Specify the test reporter to use",
);
console.log(
" " +
chalk.strikethrough.bold.magentaBright("use") +
" " +
chalk.strikethrough.dim("wasmtime") +
" " +
"Specify the runtime to use" +
"\n",
);
console.log(chalk.bold("Flags:"));
console.log(
" " +
chalk.strikethrough.dim("run") +
" " +
chalk.strikethrough.bold.blue("--coverage") +
" " +
"Use code coverage",
);
console.log(
" " +
chalk.strikethrough.dim("run") +
" " +
chalk.strikethrough.bold.blue("--snapshot") +
" " +
"Take a snapshot of the tests",
);
console.log(
" " +
chalk.strikethrough.dim("use") +
" " +
chalk.strikethrough.bold.blue("--list") +
" " +
"List supported runtimes",
);
console.log(
" " +
chalk.strikethrough.dim("reporter") +
" " +
chalk.strikethrough.bold.blue("--list") +
" " +
"List supported reporters",
);
console.log(
" " +
chalk.strikethrough.dim("<command>") +
" " +
chalk.strikethrough.bold.blue("--help") +
" " +
"Print info about command" +
"\n",
);
console.log(
chalk.dim(
"If your using this, consider dropping a star, it would help a lot!",
) + "\n",
);
console.log(
"View the repo: " +
chalk.magenta("https://github.com/JairusSW/as-test"),
);
console.log(
"View the docs: " +
chalk.strikethrough.blue("https://docs.jairus.dev/as-test"),
);
}
Loading

0 comments on commit 8ff4ed1

Please sign in to comment.