Skip to content

Commit a1f37dc

Browse files
committed
chore: add e2e test
1 parent 3675aa6 commit a1f37dc

File tree

6 files changed

+60
-2
lines changed

6 files changed

+60
-2
lines changed

bin/cli.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,10 @@ start_unit_test(
6565
.then((success) => {
6666
if (!success) {
6767
console.error(chalk.redBright("Test Failed") + "\n");
68-
exit(-1);
68+
exit(255);
6969
}
7070
})
7171
.catch((e) => {
7272
console.error(chalk.redBright(" Test crash, error message: ") + chalk.yellowBright(`${e.stack}`) + "\n");
73-
exit(-1);
73+
exit(255);
7474
});
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import os from "node:os";
2+
import path from "node:path";
3+
4+
const tmpFolder = path.join(os.tmpdir(), "as-test-e2e");
5+
6+
export default {
7+
include: ["tests/e2e/printLogInFailedInfo"],
8+
imports(runtime) {
9+
return {
10+
env: {
11+
log: (msg) => {
12+
runtime.framework.log(runtime.exports.__getString(msg));
13+
},
14+
},
15+
};
16+
},
17+
temp: tmpFolder,
18+
output: tmpFolder,
19+
mode: [],
20+
};

tests/e2e/printLogInFailedInfo/env.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export declare function log(msg: string): void;
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { test, expect } from "../../../assembly";
2+
import { log } from "./env";
3+
4+
test("failed test", () => {
5+
log("This is a log message for the failed test.");
6+
expect(1 + 1).equal(3);
7+
});
8+
9+
test("succeed test", () => {
10+
log("This is a log message for the succeed test.");
11+
expect(1 + 1).equal(2);
12+
});
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"extends": "assemblyscript/std/assembly.json",
3+
"include": ["./**/*.ts"]
4+
}

tests/e2e/run.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import assert from "node:assert";
2+
import { exec } from "node:child_process";
3+
4+
console.log("Running e2e test: printLogInFailedInfo");
5+
exec("node ./bin/as-test.js --config tests/e2e/printLogInFailedInfo/as-test.config.js", (error, stdout, stderr) => {
6+
assert(error.code === 255);
7+
const expectStdOut = `
8+
code analysis: OK
9+
compile testcases: OK
10+
instrument: OK
11+
execute testcases: OK
12+
13+
test case: 1/2 (success/total)
14+
15+
Error Message:
16+
failed test:
17+
tests/e2e/printLogInFailedInfo/source.test.ts:6:2 value: 2 expect: = 3
18+
This is a log message for the failed test.
19+
`;
20+
assert(stdout, expectStdOut.trim());
21+
});

0 commit comments

Comments
 (0)