as-test 0.1.7 → 0.1.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +2 -1
- package/README.md +7 -5
- package/asconfig.json +1 -1
- package/assembly/__tests__/example.spec.ts +20 -0
- package/assembly/index.ts +6 -1
- package/assembly/test.ts +1 -0
- package/bin/build.js +100 -112
- package/bin/index.js +132 -161
- package/bin/init.js +31 -35
- package/bin/run.js +43 -54
- package/bin/types.js +29 -29
- package/bin/util.js +20 -20
- package/cli/build.ts +14 -19
- package/cli/index.ts +1 -1
- package/package.json +1 -2
- package/transform/lib/coverage.js +417 -0
- package/transform/lib/coverage.js.map +1 -0
- package/transform/lib/index.js +33 -496
- package/transform/lib/index.js.map +1 -0
- package/transform/lib/mock.js +59 -0
- package/transform/lib/mock.js.map +1 -0
- package/transform/lib/transform.js +502 -0
- package/transform/package.json +1 -1
- package/transform/src/coverage.ts +581 -0
- package/transform/src/index.ts +20 -594
- package/transform/src/mock.ts +85 -0
- package/transform/tsconfig.json +6 -59
package/bin/init.js
CHANGED
|
@@ -4,41 +4,37 @@ import * as path from "path";
|
|
|
4
4
|
import { createInterface } from "readline";
|
|
5
5
|
import { Config } from "./types.js";
|
|
6
6
|
export function init(args) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
"
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
} else {
|
|
28
|
-
console.log("Exiting...");
|
|
29
|
-
process.exit(0);
|
|
30
|
-
}
|
|
31
|
-
});
|
|
7
|
+
console.log(chalk.bold("This command will make sure that the following files exist") +
|
|
8
|
+
"\n");
|
|
9
|
+
console.log(" " +
|
|
10
|
+
chalk.bold.blueBright("./as-test.config.json") +
|
|
11
|
+
chalk.dim(" - The core config file for as-test") +
|
|
12
|
+
"\n");
|
|
13
|
+
console.log("This command will attempt to update files to match the correct configuration.\n");
|
|
14
|
+
console.log("Do you want to proceed? [Y/n] ");
|
|
15
|
+
createInterface({
|
|
16
|
+
input: process.stdin,
|
|
17
|
+
output: process.stdout,
|
|
18
|
+
}).question("", (answer) => {
|
|
19
|
+
if (answer.toLowerCase() === "y") {
|
|
20
|
+
initialize();
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
console.log("Exiting...");
|
|
24
|
+
process.exit(0);
|
|
25
|
+
}
|
|
26
|
+
});
|
|
32
27
|
}
|
|
33
28
|
function initialize() {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
29
|
+
const CONFIG_PATH = path.join(process.cwd(), "./as-test.config.json");
|
|
30
|
+
if (existsSync(CONFIG_PATH)) {
|
|
31
|
+
console.log("Found ./as-test.config.json. Updating...");
|
|
32
|
+
process.exit(0);
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
console.log("Wrote ./as-test.config.json");
|
|
36
|
+
writeFileSync(CONFIG_PATH, JSON.stringify(new Config(), null, 2));
|
|
37
|
+
console.log(JSON.stringify(new Config(), null, 2));
|
|
38
|
+
process.exit(0);
|
|
39
|
+
}
|
|
44
40
|
}
|
package/bin/run.js
CHANGED
|
@@ -4,61 +4,50 @@ import chalk from "chalk";
|
|
|
4
4
|
import { exec } from "child_process";
|
|
5
5
|
import { glob } from "glob";
|
|
6
6
|
const installScripts = new Map([
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
["wasmtime", "curl https://wasmtime.dev/install.sh -sSf | bash"],
|
|
8
|
+
["wasmer", "curl https://get.wasmer.io -sSfL | sh"],
|
|
9
9
|
]);
|
|
10
10
|
export async function run() {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
file == config.runOptions.runtime.name ||
|
|
27
|
-
file == config.runOptions.runtime.name + ".exe"
|
|
28
|
-
) {
|
|
29
|
-
execPath = bin + "/" + file;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
if (!execPath) {
|
|
34
|
-
console.log(
|
|
35
|
-
chalk.bgRed(" ERROR ") +
|
|
36
|
-
chalk.dim(":") +
|
|
37
|
-
" could not locate " +
|
|
38
|
-
config.runOptions.runtime.name +
|
|
39
|
-
" in your PATH variable. Either set it, or install it" +
|
|
40
|
-
(config.runOptions.runtime.name
|
|
41
|
-
? "using " +
|
|
42
|
-
chalk.dim(installScripts.get(config.runOptions.runtime.name))
|
|
43
|
-
: "."),
|
|
44
|
-
);
|
|
45
|
-
}
|
|
46
|
-
for (const file of inputFiles) {
|
|
47
|
-
const outFile =
|
|
48
|
-
config.outDir +
|
|
49
|
-
"/" +
|
|
50
|
-
file.slice(file.lastIndexOf("/") + 1).replace(".ts", ".wasm");
|
|
51
|
-
exec(
|
|
52
|
-
config.runOptions.runtime.run
|
|
53
|
-
.replace(config.runOptions.runtime.name, execPath)
|
|
54
|
-
.replace("<file>", outFile),
|
|
55
|
-
(err, stdout, stderr) => {
|
|
56
|
-
process.stdout.write(stdout);
|
|
57
|
-
process.stderr.write(stderr);
|
|
58
|
-
if (err) {
|
|
59
|
-
process.exit(err.code);
|
|
11
|
+
const config = Object.assign(new Config(), JSON.parse(readFileSync("./as-test.config.json").toString()));
|
|
12
|
+
const inputFiles = await glob(config.input);
|
|
13
|
+
console.log(chalk.dim("Running tests using " + config.runOptions.runtime.name + ""));
|
|
14
|
+
let execPath = "";
|
|
15
|
+
const PATH = process.env["PATH"]?.split(":");
|
|
16
|
+
for (const bin of PATH) {
|
|
17
|
+
if (bin.startsWith("/mnt/"))
|
|
18
|
+
continue; // WSL
|
|
19
|
+
if (!existsSync(bin))
|
|
20
|
+
continue;
|
|
21
|
+
for (const file of readdirSync(bin)) {
|
|
22
|
+
if (file == config.runOptions.runtime.name ||
|
|
23
|
+
file == config.runOptions.runtime.name + ".exe") {
|
|
24
|
+
execPath = bin + "/" + file;
|
|
25
|
+
}
|
|
60
26
|
}
|
|
61
|
-
|
|
62
|
-
)
|
|
63
|
-
|
|
27
|
+
}
|
|
28
|
+
if (!execPath) {
|
|
29
|
+
console.log(chalk.bgRed(" ERROR ") +
|
|
30
|
+
chalk.dim(":") +
|
|
31
|
+
" could not locate " +
|
|
32
|
+
config.runOptions.runtime.name +
|
|
33
|
+
" in your PATH variable. Either set it, or install it" +
|
|
34
|
+
(config.runOptions.runtime.name
|
|
35
|
+
? "using " +
|
|
36
|
+
chalk.dim(installScripts.get(config.runOptions.runtime.name))
|
|
37
|
+
: "."));
|
|
38
|
+
}
|
|
39
|
+
for (const file of inputFiles) {
|
|
40
|
+
const outFile = config.outDir +
|
|
41
|
+
"/" +
|
|
42
|
+
file.slice(file.lastIndexOf("/") + 1).replace(".ts", ".wasm");
|
|
43
|
+
exec(config.runOptions.runtime.run
|
|
44
|
+
.replace(config.runOptions.runtime.name, execPath)
|
|
45
|
+
.replace("<file>", outFile), (err, stdout, stderr) => {
|
|
46
|
+
process.stdout.write(stdout);
|
|
47
|
+
process.stderr.write(stderr);
|
|
48
|
+
if (err) {
|
|
49
|
+
process.exit(err.code);
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
}
|
|
64
53
|
}
|
package/bin/types.js
CHANGED
|
@@ -1,41 +1,41 @@
|
|
|
1
1
|
export class Config {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
2
|
+
constructor() {
|
|
3
|
+
this.input = ["./assembly/__tests__/*.spec.ts"];
|
|
4
|
+
this.outDir = "./build";
|
|
5
|
+
this.config = "./asconfig.json";
|
|
6
|
+
this.suites = [];
|
|
7
|
+
this.coverage = new Coverage();
|
|
8
|
+
this.buildOptions = new BuildOptions();
|
|
9
|
+
this.runOptions = new RunOptions();
|
|
10
|
+
}
|
|
11
11
|
}
|
|
12
12
|
export class Suite {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
constructor() {
|
|
14
|
+
this.name = "";
|
|
15
|
+
}
|
|
16
16
|
}
|
|
17
17
|
export class Coverage {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
18
|
+
constructor() {
|
|
19
|
+
this.enabled = false;
|
|
20
|
+
this.show = false;
|
|
21
|
+
}
|
|
22
22
|
}
|
|
23
23
|
export class BuildOptions {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
24
|
+
constructor() {
|
|
25
|
+
this.args = [];
|
|
26
|
+
this.wasi = true;
|
|
27
|
+
this.parallel = true;
|
|
28
|
+
this.verbose = true;
|
|
29
|
+
}
|
|
30
30
|
}
|
|
31
31
|
export class RunOptions {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
32
|
+
constructor() {
|
|
33
|
+
this.runtime = new Runtime();
|
|
34
|
+
}
|
|
35
35
|
}
|
|
36
36
|
export class Runtime {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
37
|
+
constructor() {
|
|
38
|
+
this.name = "wasmtime";
|
|
39
|
+
this.run = "wasmtime <file>";
|
|
40
|
+
}
|
|
41
41
|
}
|
package/bin/util.js
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
export function formatTime(ms) {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
}
|
|
5
|
-
// Convert milliseconds to microseconds
|
|
6
|
-
const us = ms * 1000;
|
|
7
|
-
const units = [
|
|
8
|
-
{ name: "μs", divisor: 1 },
|
|
9
|
-
{ name: "ms", divisor: 1000 },
|
|
10
|
-
{ name: "s", divisor: 1000 * 1000 },
|
|
11
|
-
{ name: "m", divisor: 60 * 1000 * 1000 },
|
|
12
|
-
{ name: "h", divisor: 60 * 60 * 1000 * 1000 },
|
|
13
|
-
{ name: "d", divisor: 24 * 60 * 60 * 1000 * 1000 },
|
|
14
|
-
];
|
|
15
|
-
for (let i = units.length - 1; i >= 0; i--) {
|
|
16
|
-
const unit = units[i];
|
|
17
|
-
if (us >= unit.divisor) {
|
|
18
|
-
const value = Math.round((us / unit.divisor) * 1000) / 1000;
|
|
19
|
-
return `${value}${unit.name}`;
|
|
2
|
+
if (ms < 0) {
|
|
3
|
+
throw new Error("Time should be a non-negative number.");
|
|
20
4
|
}
|
|
21
|
-
|
|
22
|
-
|
|
5
|
+
// Convert milliseconds to microseconds
|
|
6
|
+
const us = ms * 1000;
|
|
7
|
+
const units = [
|
|
8
|
+
{ name: "μs", divisor: 1 },
|
|
9
|
+
{ name: "ms", divisor: 1000 },
|
|
10
|
+
{ name: "s", divisor: 1000 * 1000 },
|
|
11
|
+
{ name: "m", divisor: 60 * 1000 * 1000 },
|
|
12
|
+
{ name: "h", divisor: 60 * 60 * 1000 * 1000 },
|
|
13
|
+
{ name: "d", divisor: 24 * 60 * 60 * 1000 * 1000 },
|
|
14
|
+
];
|
|
15
|
+
for (let i = units.length - 1; i >= 0; i--) {
|
|
16
|
+
const unit = units[i];
|
|
17
|
+
if (us >= unit.divisor) {
|
|
18
|
+
const value = Math.round((us / unit.divisor) * 1000) / 1000;
|
|
19
|
+
return `${value}${unit.name}`;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return `${us}us`;
|
|
23
23
|
}
|
package/cli/build.ts
CHANGED
|
@@ -51,26 +51,21 @@ export async function build(args: string[]) {
|
|
|
51
51
|
process.exit(1);
|
|
52
52
|
}
|
|
53
53
|
if (
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
))
|
|
54
|
+
pkg.dependencies &&
|
|
55
|
+
!Object.keys(pkg.dependencies).includes("@assemblyscript/wasi-shim") &&
|
|
56
|
+
pkg.devDependencies &&
|
|
57
|
+
!Object.keys(pkg.devDependencies).includes("@assemblyscript/wasi-shim") &&
|
|
58
|
+
pkg.peerDependencies &&
|
|
59
|
+
!Object.keys(pkg.peerDependencies).includes(
|
|
60
|
+
"@assemblyscript/wasi-shim",
|
|
61
|
+
) &&
|
|
62
|
+
existsSync("./node_modules/@assemblyscript/wasi-shim/asconfig.json")
|
|
64
63
|
) {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
chalk.dim(": @assemblyscript/wasi-shim") +
|
|
71
|
-
" is not included in project dependencies!",
|
|
72
|
-
);
|
|
73
|
-
}
|
|
64
|
+
console.log(
|
|
65
|
+
chalk.bold.bgMagentaBright(" WARN ") +
|
|
66
|
+
chalk.dim(": @assemblyscript/wasi-shim") +
|
|
67
|
+
" is not included in project dependencies!",
|
|
68
|
+
);
|
|
74
69
|
}
|
|
75
70
|
}
|
|
76
71
|
|
package/cli/index.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "as-test",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.8",
|
|
4
4
|
"description": "Testing framework for AssemblyScript. Compatible with WASI or Bindings ",
|
|
5
5
|
"types": "assembly/index.ts",
|
|
6
6
|
"author": "Jairus Tanaka",
|
|
@@ -8,7 +8,6 @@
|
|
|
8
8
|
"license": "MIT",
|
|
9
9
|
"scripts": {
|
|
10
10
|
"test": "node ./bin/index.js run",
|
|
11
|
-
"test:tap": "node ./bin/index.js --tap",
|
|
12
11
|
"pretest": "node ./bin/index.js build",
|
|
13
12
|
"build:transform": "tsc -p ./transform",
|
|
14
13
|
"build:cli": "tsc -p cli",
|