as-test 0.1.5 → 0.1.7
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/.github/workflows/as-test.yml +1 -1
- package/CHANGELOG.md +2 -0
- package/README.md +1 -1
- package/assembly/index.ts +1 -1
- package/bin/build.js +112 -101
- package/bin/index.js +161 -132
- package/bin/init.js +35 -31
- package/bin/run.js +54 -43
- package/bin/types.js +29 -29
- package/bin/util.js +20 -20
- package/cli/build.ts +1 -1
- package/cli/index.ts +1 -1
- package/package.json +1 -1
- package/transform/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -14,3 +14,5 @@ v0.1.2 - Fix bugs with globals and dependencies
|
|
|
14
14
|
v0.1.3 - Revamp `log<T>(data: T)` with new as-console version
|
|
15
15
|
v0.1.4 - Fix a few bugs with the cli
|
|
16
16
|
v0.1.5 - Add skeleton cli and custom config
|
|
17
|
+
v0.1.6 - Fix: args should be prefixed with a space
|
|
18
|
+
v0.1.7 - Fix: remove warning about wasi-shim not being included when it is included
|
package/README.md
CHANGED
package/assembly/index.ts
CHANGED
|
@@ -230,7 +230,7 @@ export function run(options: RunOptions = new RunOptions()): void {
|
|
|
230
230
|
),
|
|
231
231
|
);
|
|
232
232
|
console.log(
|
|
233
|
-
rainbow.dimMk("\n------------------- v0.1.
|
|
233
|
+
rainbow.dimMk("\n------------------- v0.1.7 -------------------\n"),
|
|
234
234
|
);
|
|
235
235
|
// @ts-ignore
|
|
236
236
|
if (isDefined(COVERAGE_USE)) {
|
package/bin/build.js
CHANGED
|
@@ -6,114 +6,125 @@ import { exec } from "child_process";
|
|
|
6
6
|
import { formatTime } from "./util.js";
|
|
7
7
|
import * as path from "path";
|
|
8
8
|
export async function build(args) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
9
|
+
const CONFIG_PATH = path.join(process.cwd(), "./as-test.config.json");
|
|
10
|
+
let config;
|
|
11
|
+
if (!existsSync(CONFIG_PATH)) {
|
|
12
|
+
console.log(
|
|
13
|
+
chalk.bgMagentaBright(" WARN ") +
|
|
14
|
+
chalk.dim(":") +
|
|
15
|
+
" Could not locate config file in the current directory! Continuing with default config." +
|
|
16
|
+
"\n",
|
|
17
|
+
);
|
|
18
|
+
config = new Config();
|
|
19
|
+
} else {
|
|
20
|
+
config = Object.assign(
|
|
21
|
+
new Config(),
|
|
22
|
+
JSON.parse(readFileSync(CONFIG_PATH).toString()),
|
|
23
|
+
);
|
|
24
|
+
console.log(chalk.dim("Loading config from: " + CONFIG_PATH) + "\n");
|
|
25
|
+
}
|
|
26
|
+
const ASCONFIG_PATH = path.join(process.cwd(), config.config);
|
|
27
|
+
if (!existsSync(ASCONFIG_PATH)) {
|
|
28
|
+
console.log(
|
|
29
|
+
chalk.bgMagentaBright(" WARN ") +
|
|
30
|
+
chalk.dim(":") +
|
|
31
|
+
' Could not locate asconfig.json file! If you do not want to provide a config, set "config": "none". Continuing with default config.' +
|
|
32
|
+
"\n",
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
const pkg = JSON.parse(readFileSync("./package.json").toString());
|
|
36
|
+
let buildCommands = [];
|
|
37
|
+
if (config.buildOptions.wasi) {
|
|
38
|
+
if (
|
|
39
|
+
(pkg.dependencies &&
|
|
40
|
+
!Object.keys(pkg.dependencies).includes("@assemblyscript/wasi-shim")) ||
|
|
41
|
+
(pkg.devDependencies &&
|
|
42
|
+
!Object.keys(pkg.devDependencies).includes(
|
|
43
|
+
"@assemblyscript/wasi-shim",
|
|
44
|
+
)) ||
|
|
45
|
+
(pkg.peerDependencies &&
|
|
46
|
+
!Object.keys(pkg.peerDependencies).includes(
|
|
47
|
+
"@assemblyscript/wasi-shim",
|
|
48
|
+
))
|
|
49
|
+
) {
|
|
50
|
+
console.log(
|
|
51
|
+
chalk.bold.bgMagentaBright(" WARN ") +
|
|
52
|
+
chalk.dim(": @assemblyscript/wasi-shim") +
|
|
53
|
+
" is not included in project dependencies!",
|
|
54
|
+
);
|
|
17
55
|
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
56
|
+
}
|
|
57
|
+
let packageManagerCommand = "npx";
|
|
58
|
+
if (
|
|
59
|
+
process.env.npm_config_user_agent &&
|
|
60
|
+
process.env.npm_config_user_agent.includes("pnpm")
|
|
61
|
+
) {
|
|
62
|
+
packageManagerCommand = "pnpx";
|
|
63
|
+
} else if (
|
|
64
|
+
process.env.npm_config_user_agent &&
|
|
65
|
+
process.env.npm_config_user_agent.includes("yarn")
|
|
66
|
+
) {
|
|
67
|
+
packageManagerCommand = "yarn run";
|
|
68
|
+
} else if (
|
|
69
|
+
process.env.npm_config_user_agent &&
|
|
70
|
+
process.env.npm_config_user_agent.includes("bun")
|
|
71
|
+
) {
|
|
72
|
+
packageManagerCommand = "bunx";
|
|
73
|
+
}
|
|
74
|
+
console.log("");
|
|
75
|
+
const inputFiles = await glob(config.input);
|
|
76
|
+
for (const file of inputFiles) {
|
|
77
|
+
console.log(chalk.dim("Including " + file));
|
|
78
|
+
let command = `${packageManagerCommand} asc ${file}${args.length ? " " + args.join(" ") : ""}`;
|
|
31
79
|
if (config.buildOptions.wasi) {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
chalk.dim(":") +
|
|
35
|
-
" " +
|
|
36
|
-
"could not find @assemblyscript/wasi-shim! Add it to your dependencies to run with WASI!");
|
|
37
|
-
process.exit(1);
|
|
38
|
-
}
|
|
39
|
-
if ((pkg.dependencies &&
|
|
40
|
-
!Object.keys(pkg.dependencies).includes("@assemblyscript/wasi-shim")) ||
|
|
41
|
-
(pkg.devDependencies &&
|
|
42
|
-
!Object.keys(pkg.devDependencies).includes("@assemblyscript/wasi-shim")) ||
|
|
43
|
-
(pkg.peerDependencies &&
|
|
44
|
-
!Object.keys(pkg.peerDependencies).includes("@assemblyscript/wasi-shim"))) {
|
|
45
|
-
if (existsSync("./node_modules/@assemblyscript/wasi-shim/asconfig.json")) {
|
|
46
|
-
console.log(chalk.bold.bgMagentaBright(" WARN ") +
|
|
47
|
-
chalk.dim(": @assemblyscript/wasi-shim") +
|
|
48
|
-
" is not included in project dependencies!");
|
|
49
|
-
}
|
|
50
|
-
}
|
|
80
|
+
command +=
|
|
81
|
+
" --config ./node_modules/@assemblyscript/wasi-shim/asconfig.json";
|
|
51
82
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
process.env.npm_config_user_agent.includes("pnpm")) {
|
|
55
|
-
packageManagerCommand = "pnpx";
|
|
83
|
+
if (config.config !== "none") {
|
|
84
|
+
command += " --config " + config.config;
|
|
56
85
|
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
86
|
+
const outFile =
|
|
87
|
+
config.outDir +
|
|
88
|
+
"/" +
|
|
89
|
+
file.slice(file.lastIndexOf("/") + 1).replace(".ts", ".wasm");
|
|
90
|
+
if (config.outDir) {
|
|
91
|
+
command += " -o " + outFile;
|
|
60
92
|
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
93
|
+
if (config.coverage.enabled) {
|
|
94
|
+
console.log(chalk.dim("Enabling coverage"));
|
|
95
|
+
command += " --use COVERAGE_USE=1 --transform as-test/transform";
|
|
96
|
+
if (config.coverage.show) command += " --use COVERAGE_SHOW=1";
|
|
64
97
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
for (const file of inputFiles) {
|
|
68
|
-
console.log(chalk.dim("Including " + file));
|
|
69
|
-
let command = `${packageManagerCommand} asc ${file}${args.length ? " " + args.join(" ") : ""}`;
|
|
70
|
-
if (config.buildOptions.wasi) {
|
|
71
|
-
command +=
|
|
72
|
-
" --config ./node_modules/@assemblyscript/wasi-shim/asconfig.json";
|
|
73
|
-
}
|
|
74
|
-
if (config.config !== "none") {
|
|
75
|
-
command += " --config " + config.config;
|
|
76
|
-
}
|
|
77
|
-
const outFile = config.outDir +
|
|
78
|
-
"/" +
|
|
79
|
-
file.slice(file.lastIndexOf("/") + 1).replace(".ts", ".wasm");
|
|
80
|
-
if (config.outDir) {
|
|
81
|
-
command += " -o " + outFile;
|
|
82
|
-
}
|
|
83
|
-
if (config.coverage.enabled) {
|
|
84
|
-
console.log(chalk.dim("Enabling coverage"));
|
|
85
|
-
command += " --use COVERAGE_USE=1 --transform as-test/transform";
|
|
86
|
-
if (config.coverage.show)
|
|
87
|
-
command += " --use COVERAGE_SHOW=1";
|
|
88
|
-
}
|
|
89
|
-
if (config.buildOptions.args) {
|
|
90
|
-
command += config.buildOptions.args.join(" ");
|
|
91
|
-
}
|
|
92
|
-
buildCommands.push(command);
|
|
98
|
+
if (config.buildOptions.args) {
|
|
99
|
+
command += " " + config.buildOptions.args.join(" ");
|
|
93
100
|
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
});
|
|
107
|
-
});
|
|
108
|
-
};
|
|
109
|
-
if (config.buildOptions.parallel) {
|
|
110
|
-
console.log(chalk.dim("Building sources in parallel..."));
|
|
111
|
-
const start = performance.now();
|
|
112
|
-
let builders = [];
|
|
113
|
-
for (const command of buildCommands) {
|
|
114
|
-
builders.push(build(command));
|
|
101
|
+
buildCommands.push(command);
|
|
102
|
+
}
|
|
103
|
+
const build = (command) => {
|
|
104
|
+
return new Promise((resolve, _) => {
|
|
105
|
+
console.log(chalk.dim("Building: " + command));
|
|
106
|
+
exec(command, (err, stdout, stderr) => {
|
|
107
|
+
if (config.buildOptions.verbose) {
|
|
108
|
+
process.stdout.write(stdout);
|
|
109
|
+
}
|
|
110
|
+
if (err) {
|
|
111
|
+
process.stderr.write(stderr + "\n");
|
|
112
|
+
process.exit(1);
|
|
115
113
|
}
|
|
116
|
-
|
|
117
|
-
|
|
114
|
+
resolve();
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
};
|
|
118
|
+
if (config.buildOptions.parallel) {
|
|
119
|
+
console.log(chalk.dim("Building sources in parallel..."));
|
|
120
|
+
const start = performance.now();
|
|
121
|
+
let builders = [];
|
|
122
|
+
for (const command of buildCommands) {
|
|
123
|
+
builders.push(build(command));
|
|
118
124
|
}
|
|
125
|
+
await Promise.all(builders);
|
|
126
|
+
console.log(
|
|
127
|
+
chalk.dim("Compiled in " + formatTime(performance.now() - start)) + "\n",
|
|
128
|
+
);
|
|
129
|
+
}
|
|
119
130
|
}
|
package/bin/index.js
CHANGED
|
@@ -7,16 +7,14 @@ const _args = process.argv.slice(2);
|
|
|
7
7
|
const flags = [];
|
|
8
8
|
const args = [];
|
|
9
9
|
const COMMANDS = ["run", "build", "test", "init"];
|
|
10
|
-
const version = "0.1.
|
|
10
|
+
const version = "0.1.7";
|
|
11
11
|
for (const arg of _args) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
else
|
|
15
|
-
args.push(arg);
|
|
12
|
+
if (arg.startsWith("-")) flags.push(arg);
|
|
13
|
+
else args.push(arg);
|
|
16
14
|
}
|
|
17
15
|
if (!args.length) {
|
|
18
|
-
|
|
19
|
-
|
|
16
|
+
if (flags.includes("--tap")) {
|
|
17
|
+
console.log(`TAP version 13
|
|
20
18
|
# timing test
|
|
21
19
|
ok 1 should be strictly equal
|
|
22
20
|
not ok 2 should be strictly equal
|
|
@@ -30,130 +28,161 @@ not ok 2 should be strictly equal
|
|
|
30
28
|
# tests 2
|
|
31
29
|
# pass 1
|
|
32
30
|
# fail 1`);
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
chalk.dim("(alias: ast)") +
|
|
51
|
-
"\n");
|
|
52
|
-
console.log(chalk.bold("Commands:"));
|
|
53
|
-
console.log(" " +
|
|
54
|
-
chalk.bold.blueBright("run") +
|
|
55
|
-
" " +
|
|
56
|
-
chalk.dim("<my-test.spec.ts>") +
|
|
57
|
-
" " +
|
|
58
|
-
"Run unit tests with selected runtime");
|
|
59
|
-
console.log(" " +
|
|
60
|
-
chalk.bold.blueBright("build") +
|
|
61
|
-
" " +
|
|
62
|
-
chalk.dim("<my-test.spec.ts>") +
|
|
63
|
-
" " +
|
|
64
|
-
"Build unit tests and compile");
|
|
65
|
-
console.log(" " +
|
|
66
|
-
chalk.bold.blueBright("test") +
|
|
67
|
-
" " +
|
|
68
|
-
chalk.dim("<my-test.spec.ts>") +
|
|
69
|
-
" " +
|
|
70
|
-
"Build and run unit tests with selected runtime" +
|
|
71
|
-
"\n");
|
|
72
|
-
console.log(" " +
|
|
73
|
-
chalk.bold.magentaBright("init") +
|
|
74
|
-
" " +
|
|
75
|
-
chalk.strikethrough.dim("") +
|
|
76
|
-
" " +
|
|
77
|
-
"Initialize an empty testing template");
|
|
78
|
-
console.log(" " +
|
|
79
|
-
chalk.strikethrough.bold.magentaBright("config") +
|
|
80
|
-
" " +
|
|
81
|
-
chalk.strikethrough.dim("as-test.config.json") +
|
|
82
|
-
" " +
|
|
83
|
-
"Specify the configuration file");
|
|
84
|
-
console.log(" " +
|
|
85
|
-
chalk.strikethrough.bold.magentaBright("reporter") +
|
|
86
|
-
" " +
|
|
87
|
-
chalk.strikethrough.dim("<tap>") +
|
|
88
|
-
" " +
|
|
89
|
-
"Specify the test reporter to use");
|
|
90
|
-
console.log(" " +
|
|
91
|
-
chalk.strikethrough.bold.magentaBright("use") +
|
|
92
|
-
" " +
|
|
93
|
-
chalk.strikethrough.dim("wasmtime") +
|
|
94
|
-
" " +
|
|
95
|
-
"Specify the runtime to use" +
|
|
96
|
-
"\n");
|
|
97
|
-
console.log(chalk.bold("Flags:"));
|
|
98
|
-
console.log(" " +
|
|
99
|
-
chalk.strikethrough.dim("run") +
|
|
100
|
-
" " +
|
|
101
|
-
chalk.strikethrough.bold.blue("--coverage") +
|
|
102
|
-
" " +
|
|
103
|
-
"Use code coverage");
|
|
104
|
-
console.log(" " +
|
|
105
|
-
chalk.strikethrough.dim("run") +
|
|
106
|
-
" " +
|
|
107
|
-
chalk.strikethrough.bold.blue("--snapshot") +
|
|
108
|
-
" " +
|
|
109
|
-
"Take a snapshot of the tests");
|
|
110
|
-
console.log(" " +
|
|
111
|
-
chalk.strikethrough.dim("use") +
|
|
112
|
-
" " +
|
|
113
|
-
chalk.strikethrough.bold.blue("--list") +
|
|
114
|
-
" " +
|
|
115
|
-
"List supported runtimes");
|
|
116
|
-
console.log(" " +
|
|
117
|
-
chalk.strikethrough.dim("reporter") +
|
|
118
|
-
" " +
|
|
119
|
-
chalk.strikethrough.bold.blue("--list") +
|
|
120
|
-
" " +
|
|
121
|
-
"List supported reporters");
|
|
122
|
-
console.log(" " +
|
|
123
|
-
chalk.strikethrough.dim("<command>") +
|
|
124
|
-
" " +
|
|
125
|
-
chalk.strikethrough.bold.blue("--help") +
|
|
126
|
-
" " +
|
|
127
|
-
"Print info about command" +
|
|
128
|
-
"\n");
|
|
129
|
-
console.log(chalk.dim("If your using this, consider dropping a star, it would help a lot!") + "\n");
|
|
130
|
-
console.log("View the repo: " +
|
|
131
|
-
chalk.magenta("https://github.com/JairusSW/as-test"));
|
|
132
|
-
console.log("View the docs: " +
|
|
133
|
-
chalk.strikethrough.blue("https://docs.jairus.dev/as-test"));
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
else if (COMMANDS.includes(args[0])) {
|
|
137
|
-
const command = args.shift();
|
|
138
|
-
if (command === "build") {
|
|
139
|
-
build(args);
|
|
140
|
-
}
|
|
141
|
-
else if (command === "run") {
|
|
142
|
-
run();
|
|
143
|
-
}
|
|
144
|
-
else if (command === "test") {
|
|
145
|
-
build(args).then(() => {
|
|
146
|
-
run();
|
|
147
|
-
});
|
|
148
|
-
}
|
|
149
|
-
else if (command === "init") {
|
|
150
|
-
init(args);
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
else {
|
|
154
|
-
console.log(chalk.bgRed(" ERROR ") +
|
|
155
|
-
chalk.dim(":") +
|
|
31
|
+
} else if (flags.includes("--version") || flags.includes("-v")) {
|
|
32
|
+
console.log("as-test" + " " + version.toString());
|
|
33
|
+
} else {
|
|
34
|
+
console.log(
|
|
35
|
+
chalk.bold.blueBright("as-test") +
|
|
36
|
+
" is a testing framework for AssemblyScript. " +
|
|
37
|
+
chalk.dim("(v" + version + ")") +
|
|
38
|
+
"\n",
|
|
39
|
+
);
|
|
40
|
+
console.log(
|
|
41
|
+
chalk.bold("Usage: as-test") +
|
|
42
|
+
" " +
|
|
43
|
+
chalk.dim("<command>") +
|
|
44
|
+
" " +
|
|
45
|
+
chalk.bold.blueBright("[...flags]") +
|
|
46
|
+
" " +
|
|
47
|
+
chalk.bold("[...args]") +
|
|
156
48
|
" " +
|
|
157
|
-
chalk.
|
|
158
|
-
|
|
49
|
+
chalk.dim("(alias: ast)") +
|
|
50
|
+
"\n",
|
|
51
|
+
);
|
|
52
|
+
console.log(chalk.bold("Commands:"));
|
|
53
|
+
console.log(
|
|
54
|
+
" " +
|
|
55
|
+
chalk.bold.blueBright("run") +
|
|
56
|
+
" " +
|
|
57
|
+
chalk.dim("<my-test.spec.ts>") +
|
|
58
|
+
" " +
|
|
59
|
+
"Run unit tests with selected runtime",
|
|
60
|
+
);
|
|
61
|
+
console.log(
|
|
62
|
+
" " +
|
|
63
|
+
chalk.bold.blueBright("build") +
|
|
64
|
+
" " +
|
|
65
|
+
chalk.dim("<my-test.spec.ts>") +
|
|
66
|
+
" " +
|
|
67
|
+
"Build unit tests and compile",
|
|
68
|
+
);
|
|
69
|
+
console.log(
|
|
70
|
+
" " +
|
|
71
|
+
chalk.bold.blueBright("test") +
|
|
72
|
+
" " +
|
|
73
|
+
chalk.dim("<my-test.spec.ts>") +
|
|
74
|
+
" " +
|
|
75
|
+
"Build and run unit tests with selected runtime" +
|
|
76
|
+
"\n",
|
|
77
|
+
);
|
|
78
|
+
console.log(
|
|
79
|
+
" " +
|
|
80
|
+
chalk.bold.magentaBright("init") +
|
|
81
|
+
" " +
|
|
82
|
+
chalk.strikethrough.dim("") +
|
|
83
|
+
" " +
|
|
84
|
+
"Initialize an empty testing template",
|
|
85
|
+
);
|
|
86
|
+
console.log(
|
|
87
|
+
" " +
|
|
88
|
+
chalk.strikethrough.bold.magentaBright("config") +
|
|
89
|
+
" " +
|
|
90
|
+
chalk.strikethrough.dim("as-test.config.json") +
|
|
91
|
+
" " +
|
|
92
|
+
"Specify the configuration file",
|
|
93
|
+
);
|
|
94
|
+
console.log(
|
|
95
|
+
" " +
|
|
96
|
+
chalk.strikethrough.bold.magentaBright("reporter") +
|
|
97
|
+
" " +
|
|
98
|
+
chalk.strikethrough.dim("<tap>") +
|
|
99
|
+
" " +
|
|
100
|
+
"Specify the test reporter to use",
|
|
101
|
+
);
|
|
102
|
+
console.log(
|
|
103
|
+
" " +
|
|
104
|
+
chalk.strikethrough.bold.magentaBright("use") +
|
|
105
|
+
" " +
|
|
106
|
+
chalk.strikethrough.dim("wasmtime") +
|
|
107
|
+
" " +
|
|
108
|
+
"Specify the runtime to use" +
|
|
109
|
+
"\n",
|
|
110
|
+
);
|
|
111
|
+
console.log(chalk.bold("Flags:"));
|
|
112
|
+
console.log(
|
|
113
|
+
" " +
|
|
114
|
+
chalk.strikethrough.dim("run") +
|
|
115
|
+
" " +
|
|
116
|
+
chalk.strikethrough.bold.blue("--coverage") +
|
|
117
|
+
" " +
|
|
118
|
+
"Use code coverage",
|
|
119
|
+
);
|
|
120
|
+
console.log(
|
|
121
|
+
" " +
|
|
122
|
+
chalk.strikethrough.dim("run") +
|
|
123
|
+
" " +
|
|
124
|
+
chalk.strikethrough.bold.blue("--snapshot") +
|
|
125
|
+
" " +
|
|
126
|
+
"Take a snapshot of the tests",
|
|
127
|
+
);
|
|
128
|
+
console.log(
|
|
129
|
+
" " +
|
|
130
|
+
chalk.strikethrough.dim("use") +
|
|
131
|
+
" " +
|
|
132
|
+
chalk.strikethrough.bold.blue("--list") +
|
|
133
|
+
" " +
|
|
134
|
+
"List supported runtimes",
|
|
135
|
+
);
|
|
136
|
+
console.log(
|
|
137
|
+
" " +
|
|
138
|
+
chalk.strikethrough.dim("reporter") +
|
|
139
|
+
" " +
|
|
140
|
+
chalk.strikethrough.bold.blue("--list") +
|
|
141
|
+
" " +
|
|
142
|
+
"List supported reporters",
|
|
143
|
+
);
|
|
144
|
+
console.log(
|
|
145
|
+
" " +
|
|
146
|
+
chalk.strikethrough.dim("<command>") +
|
|
147
|
+
" " +
|
|
148
|
+
chalk.strikethrough.bold.blue("--help") +
|
|
149
|
+
" " +
|
|
150
|
+
"Print info about command" +
|
|
151
|
+
"\n",
|
|
152
|
+
);
|
|
153
|
+
console.log(
|
|
154
|
+
chalk.dim(
|
|
155
|
+
"If your using this, consider dropping a star, it would help a lot!",
|
|
156
|
+
) + "\n",
|
|
157
|
+
);
|
|
158
|
+
console.log(
|
|
159
|
+
"View the repo: " +
|
|
160
|
+
chalk.magenta("https://github.com/JairusSW/as-test"),
|
|
161
|
+
);
|
|
162
|
+
console.log(
|
|
163
|
+
"View the docs: " +
|
|
164
|
+
chalk.strikethrough.blue("https://docs.jairus.dev/as-test"),
|
|
165
|
+
);
|
|
166
|
+
}
|
|
167
|
+
} else if (COMMANDS.includes(args[0])) {
|
|
168
|
+
const command = args.shift();
|
|
169
|
+
if (command === "build") {
|
|
170
|
+
build(args);
|
|
171
|
+
} else if (command === "run") {
|
|
172
|
+
run();
|
|
173
|
+
} else if (command === "test") {
|
|
174
|
+
build(args).then(() => {
|
|
175
|
+
run();
|
|
176
|
+
});
|
|
177
|
+
} else if (command === "init") {
|
|
178
|
+
init(args);
|
|
179
|
+
}
|
|
180
|
+
} else {
|
|
181
|
+
console.log(
|
|
182
|
+
chalk.bgRed(" ERROR ") +
|
|
183
|
+
chalk.dim(":") +
|
|
184
|
+
" " +
|
|
185
|
+
chalk.bold("Unknown command: ") +
|
|
186
|
+
args[0],
|
|
187
|
+
);
|
|
159
188
|
}
|
package/bin/init.js
CHANGED
|
@@ -4,37 +4,41 @@ 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
|
-
|
|
7
|
+
console.log(
|
|
8
|
+
chalk.bold("This command will make sure that the following files exist") +
|
|
9
|
+
"\n",
|
|
10
|
+
);
|
|
11
|
+
console.log(
|
|
12
|
+
" " +
|
|
13
|
+
chalk.bold.blueBright("./as-test.config.json") +
|
|
14
|
+
chalk.dim(" - The core config file for as-test") +
|
|
15
|
+
"\n",
|
|
16
|
+
);
|
|
17
|
+
console.log(
|
|
18
|
+
"This command will attempt to update files to match the correct configuration.\n",
|
|
19
|
+
);
|
|
20
|
+
console.log("Do you want to proceed? [Y/n] ");
|
|
21
|
+
createInterface({
|
|
22
|
+
input: process.stdin,
|
|
23
|
+
output: process.stdout,
|
|
24
|
+
}).question("", (answer) => {
|
|
25
|
+
if (answer.toLowerCase() === "y") {
|
|
26
|
+
initialize();
|
|
27
|
+
} else {
|
|
28
|
+
console.log("Exiting...");
|
|
29
|
+
process.exit(0);
|
|
30
|
+
}
|
|
31
|
+
});
|
|
27
32
|
}
|
|
28
33
|
function initialize() {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
}
|
|
34
|
+
const CONFIG_PATH = path.join(process.cwd(), "./as-test.config.json");
|
|
35
|
+
if (existsSync(CONFIG_PATH)) {
|
|
36
|
+
console.log("Found ./as-test.config.json. Updating...");
|
|
37
|
+
process.exit(0);
|
|
38
|
+
} else {
|
|
39
|
+
console.log("Wrote ./as-test.config.json");
|
|
40
|
+
writeFileSync(CONFIG_PATH, JSON.stringify(new Config(), null, 2));
|
|
41
|
+
console.log(JSON.stringify(new Config(), null, 2));
|
|
42
|
+
process.exit(0);
|
|
43
|
+
}
|
|
40
44
|
}
|
package/bin/run.js
CHANGED
|
@@ -4,50 +4,61 @@ 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
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
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
|
-
});
|
|
11
|
+
const config = Object.assign(
|
|
12
|
+
new Config(),
|
|
13
|
+
JSON.parse(readFileSync("./as-test.config.json").toString()),
|
|
14
|
+
);
|
|
15
|
+
const inputFiles = await glob(config.input);
|
|
16
|
+
console.log(
|
|
17
|
+
chalk.dim("Running tests using " + config.runOptions.runtime.name + ""),
|
|
18
|
+
);
|
|
19
|
+
let execPath = "";
|
|
20
|
+
const PATH = process.env["PATH"]?.split(":");
|
|
21
|
+
for (const bin of PATH) {
|
|
22
|
+
if (bin.startsWith("/mnt/")) continue; // WSL
|
|
23
|
+
if (!existsSync(bin)) continue;
|
|
24
|
+
for (const file of readdirSync(bin)) {
|
|
25
|
+
if (
|
|
26
|
+
file == config.runOptions.runtime.name ||
|
|
27
|
+
file == config.runOptions.runtime.name + ".exe"
|
|
28
|
+
) {
|
|
29
|
+
execPath = bin + "/" + file;
|
|
30
|
+
}
|
|
52
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);
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
);
|
|
63
|
+
}
|
|
53
64
|
}
|
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
|
-
|
|
2
|
+
if (ms < 0) {
|
|
3
|
+
throw new Error("Time should be a non-negative number.");
|
|
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}`;
|
|
4
20
|
}
|
|
5
|
-
|
|
6
|
-
|
|
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`;
|
|
21
|
+
}
|
|
22
|
+
return `${us}us`;
|
|
23
23
|
}
|
package/cli/build.ts
CHANGED
|
@@ -117,7 +117,7 @@ export async function build(args: string[]) {
|
|
|
117
117
|
if (config.coverage.show) command += " --use COVERAGE_SHOW=1";
|
|
118
118
|
}
|
|
119
119
|
if (config.buildOptions.args) {
|
|
120
|
-
command += config.buildOptions.args.join(" ");
|
|
120
|
+
command += " " + config.buildOptions.args.join(" ");
|
|
121
121
|
}
|
|
122
122
|
buildCommands.push(command);
|
|
123
123
|
}
|
package/cli/index.ts
CHANGED
package/package.json
CHANGED