as-test 0.2.1 → 0.3.1
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 +75 -68
- package/as-test.config.json +7 -10
- package/assembly/__tests__/array.spec.ts +19 -0
- package/assembly/__tests__/math.spec.ts +16 -0
- package/assembly/__tests__/sleep.spec.ts +28 -0
- package/assembly/index.ts +181 -165
- package/assembly/src/expectation.ts +119 -112
- package/assembly/src/log.ts +19 -0
- package/assembly/src/suite.ts +99 -0
- package/assembly/src/tests.ts +10 -0
- package/assembly/tsconfig.json +1 -1
- package/assembly/util/helpers.ts +0 -33
- package/assembly/util/term.ts +55 -0
- package/assets/img/screenshot.png +0 -0
- package/bin/about.js +135 -0
- package/bin/build.js +72 -131
- package/bin/index.js +70 -112
- package/bin/init.js +211 -39
- package/bin/reporter.js +1 -0
- package/bin/run.js +226 -68
- package/bin/types.js +25 -31
- package/bin/util.js +44 -20
- package/cli/build.ts +70 -109
- package/cli/index.ts +148 -159
- package/cli/init.ts +235 -34
- package/cli/reporter.ts +1 -0
- package/cli/run.ts +266 -57
- package/cli/types.ts +6 -11
- package/cli/util.ts +35 -0
- package/package.json +5 -2
- package/run/package.json +27 -0
- package/tests/array.run.js +7 -0
- package/tests/math.run.js +7 -0
- package/tests/sleep.run.js +7 -0
- package/transform/lib/coverage.js +325 -319
- package/transform/lib/index.js +51 -31
- package/transform/lib/index.js.map +1 -1
- package/transform/lib/mock.js +60 -52
- package/transform/lib/mock.js.map +1 -1
- package/transform/package.json +1 -1
- package/transform/src/index.ts +22 -3
- package/transform/src/mock.ts +1 -1
- package/asconfig.json +0 -31
- package/assembly/__tests__/example.spec.ts +0 -79
- package/assembly/reporters/tap.ts +0 -30
- package/assembly/src/group.ts +0 -44
- package/assembly/src/node.ts +0 -13
- package/jest.test.js +0 -44
- package/test.config.json +0 -0
- package/tests/test.tap +0 -14
- package/unision +0 -38
- package/unision.pub +0 -1
- package/utils.ts +0 -1
package/bin/util.js
CHANGED
|
@@ -1,23 +1,47 @@
|
|
|
1
|
+
import { existsSync, readFileSync } from "fs";
|
|
2
|
+
import { Config } from "./types.js";
|
|
3
|
+
import chalk from "chalk";
|
|
4
|
+
import { delimiter, join } from "path";
|
|
1
5
|
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}`;
|
|
6
|
+
if (ms < 0) {
|
|
7
|
+
throw new Error("Time should be a non-negative number.");
|
|
20
8
|
}
|
|
21
|
-
|
|
22
|
-
|
|
9
|
+
// Convert milliseconds to microseconds
|
|
10
|
+
const us = ms * 1000;
|
|
11
|
+
const units = [
|
|
12
|
+
{ name: "μs", divisor: 1 },
|
|
13
|
+
{ name: "ms", divisor: 1000 },
|
|
14
|
+
{ name: "s", divisor: 1000 * 1000 },
|
|
15
|
+
{ name: "m", divisor: 60 * 1000 * 1000 },
|
|
16
|
+
{ name: "h", divisor: 60 * 60 * 1000 * 1000 },
|
|
17
|
+
{ name: "d", divisor: 24 * 60 * 60 * 1000 * 1000 },
|
|
18
|
+
];
|
|
19
|
+
for (let i = units.length - 1; i >= 0; i--) {
|
|
20
|
+
const unit = units[i];
|
|
21
|
+
if (us >= unit.divisor) {
|
|
22
|
+
const value = Math.round((us / unit.divisor) * 1000) / 1000;
|
|
23
|
+
return `${value}${unit.name}`;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return `${us}us`;
|
|
27
|
+
}
|
|
28
|
+
export function loadConfig(CONFIG_PATH, warn = false) {
|
|
29
|
+
if (!existsSync(CONFIG_PATH)) {
|
|
30
|
+
if (warn)
|
|
31
|
+
console.log(`${chalk.bgMagentaBright(" WARN ")}${chalk.dim(":")} Could not locate config file in the current directory! Continuing with default config.`);
|
|
32
|
+
return new Config();
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
return Object.assign(new Config(), JSON.parse(readFileSync(CONFIG_PATH).toString()));
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
export function getExec(exec) {
|
|
39
|
+
const PATH = process.env.PATH.split(delimiter);
|
|
40
|
+
for (const pathDir of PATH) {
|
|
41
|
+
const fullPath = join(pathDir, exec + (process.platform === "win32" ? ".exe" : ""));
|
|
42
|
+
if (existsSync(fullPath)) {
|
|
43
|
+
return fullPath;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return null;
|
|
23
47
|
}
|
package/cli/build.ts
CHANGED
|
@@ -2,51 +2,50 @@ import { existsSync, readFileSync } from "fs";
|
|
|
2
2
|
import { Config } from "./types.js";
|
|
3
3
|
import { glob } from "glob";
|
|
4
4
|
import chalk from "chalk";
|
|
5
|
-
import {
|
|
6
|
-
import { formatTime } from "./util.js";
|
|
5
|
+
import { execSync } from "child_process";
|
|
7
6
|
import * as path from "path";
|
|
7
|
+
import { loadConfig } from "./util.js";
|
|
8
|
+
|
|
9
|
+
const CONFIG_PATH = path.join(process.cwd(), "./as-test.config.json");
|
|
10
|
+
const PKG_PATH = path.join(process.cwd(), "./package.json");
|
|
11
|
+
export async function build() {
|
|
12
|
+
let config = loadConfig(CONFIG_PATH, true);
|
|
8
13
|
|
|
9
|
-
export async function build(args: string[]) {
|
|
10
|
-
const CONFIG_PATH = path.join(process.cwd(), "./as-test.config.json");
|
|
11
|
-
let config: Config;
|
|
12
|
-
if (!existsSync(CONFIG_PATH)) {
|
|
13
|
-
console.log(
|
|
14
|
-
chalk.bgMagentaBright(" WARN ") +
|
|
15
|
-
chalk.dim(":") +
|
|
16
|
-
" Could not locate config file in the current directory! Continuing with default config." +
|
|
17
|
-
"\n",
|
|
18
|
-
);
|
|
19
|
-
config = new Config();
|
|
20
|
-
} else {
|
|
21
|
-
config = Object.assign(
|
|
22
|
-
new Config(),
|
|
23
|
-
JSON.parse(readFileSync(CONFIG_PATH).toString()),
|
|
24
|
-
) as Config;
|
|
25
|
-
console.log(chalk.dim("Loading config from: " + CONFIG_PATH) + "\n");
|
|
26
|
-
}
|
|
27
14
|
const ASCONFIG_PATH = path.join(process.cwd(), config.config);
|
|
28
|
-
if (!existsSync(ASCONFIG_PATH)) {
|
|
15
|
+
if (config.config && config.config !== "none" && !existsSync(ASCONFIG_PATH)) {
|
|
29
16
|
console.log(
|
|
30
|
-
chalk.bgMagentaBright(" WARN ")
|
|
31
|
-
chalk.dim(":") +
|
|
32
|
-
' Could not locate asconfig.json file! If you do not want to provide a config, set "config": "none". Continuing with default config.' +
|
|
33
|
-
"\n",
|
|
17
|
+
`${chalk.bgMagentaBright(" WARN ")}${chalk.dim(":")} Could not locate asconfig.json file! If you do not want to provide a config, set "config": "none"`,
|
|
34
18
|
);
|
|
35
19
|
}
|
|
36
|
-
|
|
20
|
+
|
|
21
|
+
ensureDeps(config);
|
|
22
|
+
|
|
23
|
+
let pkgRunner = getPkgRunner();
|
|
24
|
+
const inputFiles = await glob(config.input);
|
|
25
|
+
|
|
26
|
+
let buildArgs = getBuildArgs(config);
|
|
27
|
+
|
|
28
|
+
for (const file of inputFiles) {
|
|
29
|
+
let cmd = `${pkgRunner} asc ${file}${buildArgs}`;
|
|
30
|
+
const outFile = `${config.outDir}/${file.slice(file.lastIndexOf("/") + 1).replace(".ts", ".wasm")}`;
|
|
31
|
+
if (config.outDir) {
|
|
32
|
+
cmd += " -o " + outFile;
|
|
33
|
+
}
|
|
34
|
+
buildFile(cmd);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function ensureDeps(config: Config): void {
|
|
39
|
+
const pkg = JSON.parse(readFileSync(PKG_PATH).toString()) as {
|
|
37
40
|
dependencies: string[] | null;
|
|
38
41
|
devDependencies: string[] | null;
|
|
39
42
|
peerDependencies: string[] | null;
|
|
40
43
|
};
|
|
41
|
-
let buildCommands: string[] = [];
|
|
42
44
|
|
|
43
|
-
if (config.buildOptions.wasi) {
|
|
45
|
+
if (config.buildOptions.target == "wasi") {
|
|
44
46
|
if (!existsSync("./node_modules/@assemblyscript/wasi-shim/asconfig.json")) {
|
|
45
47
|
console.log(
|
|
46
|
-
chalk.bgRed(" ERROR ")
|
|
47
|
-
chalk.dim(":") +
|
|
48
|
-
" " +
|
|
49
|
-
"could not find @assemblyscript/wasi-shim! Add it to your dependencies to run with WASI!",
|
|
48
|
+
`${chalk.bgRed(" ERROR ")}${chalk.dim(":")} could not find @assemblyscript/wasi-shim! Add it to your dependencies to run with WASI!`,
|
|
50
49
|
);
|
|
51
50
|
process.exit(1);
|
|
52
51
|
}
|
|
@@ -62,95 +61,57 @@ export async function build(args: string[]) {
|
|
|
62
61
|
existsSync("./node_modules/@assemblyscript/wasi-shim/asconfig.json")
|
|
63
62
|
) {
|
|
64
63
|
console.log(
|
|
65
|
-
chalk.bold.bgMagentaBright(" WARN ")
|
|
66
|
-
chalk.dim(": @assemblyscript/wasi-shim") +
|
|
67
|
-
" is not included in project dependencies!",
|
|
64
|
+
`${chalk.bold.bgMagentaBright(" WARN ")}${chalk.dim(":")} @assemblyscript/wasi-shim is not included in project dependencies!"`,
|
|
68
65
|
);
|
|
69
66
|
}
|
|
70
67
|
}
|
|
68
|
+
}
|
|
71
69
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
) {
|
|
77
|
-
packageManagerCommand = "pnpx";
|
|
78
|
-
} else if (
|
|
79
|
-
process.env.npm_config_user_agent &&
|
|
80
|
-
process.env.npm_config_user_agent.includes("yarn")
|
|
81
|
-
) {
|
|
82
|
-
packageManagerCommand = "yarn run";
|
|
83
|
-
} else if (
|
|
84
|
-
process.env.npm_config_user_agent &&
|
|
85
|
-
process.env.npm_config_user_agent.includes("bun")
|
|
86
|
-
) {
|
|
87
|
-
packageManagerCommand = "bunx";
|
|
88
|
-
}
|
|
89
|
-
console.log("");
|
|
90
|
-
|
|
91
|
-
const inputFiles = await glob(config.input);
|
|
92
|
-
for (const file of inputFiles) {
|
|
93
|
-
console.log(chalk.dim("Including " + file));
|
|
94
|
-
let command = `${packageManagerCommand} asc ${file}${args.length ? " " + args.join(" ") : ""}`;
|
|
95
|
-
if (config.config !== "none") {
|
|
96
|
-
command += " --config " + config.config;
|
|
97
|
-
}
|
|
98
|
-
if (config.buildOptions.wasi) {
|
|
99
|
-
command +=
|
|
100
|
-
" --config ./node_modules/@assemblyscript/wasi-shim/asconfig.json";
|
|
70
|
+
function getPkgRunner(): string {
|
|
71
|
+
switch (process.env.npm_config_user_agent) {
|
|
72
|
+
case "pnpm": {
|
|
73
|
+
return "pnpx";
|
|
101
74
|
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
"/" +
|
|
105
|
-
file.slice(file.lastIndexOf("/") + 1).replace(".ts", ".wasm");
|
|
106
|
-
if (config.outDir) {
|
|
107
|
-
command += " -o " + outFile;
|
|
75
|
+
case "yarn": {
|
|
76
|
+
return "yarn";
|
|
108
77
|
}
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
command += " --use COVERAGE_USE=1 --transform as-test/transform";
|
|
112
|
-
if (config.coverage.show) command += " --use COVERAGE_SHOW=1";
|
|
78
|
+
case "bun": {
|
|
79
|
+
return "bunx";
|
|
113
80
|
}
|
|
114
|
-
if (config.buildOptions.args) {
|
|
115
|
-
command += " " + config.buildOptions.args.join(" ");
|
|
116
|
-
}
|
|
117
|
-
if (
|
|
118
|
-
["node", "deno", "bun"].includes(
|
|
119
|
-
config.runOptions.runtime.run.split(" ")[0],
|
|
120
|
-
)
|
|
121
|
-
) {
|
|
122
|
-
command += " --exportStart";
|
|
123
|
-
}
|
|
124
|
-
buildCommands.push(command);
|
|
125
81
|
}
|
|
82
|
+
return "npx";
|
|
83
|
+
}
|
|
126
84
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
exec(command, (err, stdout, stderr) => {
|
|
131
|
-
if (config.buildOptions.verbose) {
|
|
132
|
-
process.stdout.write(stdout);
|
|
133
|
-
}
|
|
134
|
-
if (err) {
|
|
135
|
-
process.stderr.write(stderr + "\n");
|
|
136
|
-
process.exit(1);
|
|
137
|
-
}
|
|
138
|
-
resolve();
|
|
139
|
-
});
|
|
140
|
-
});
|
|
141
|
-
};
|
|
85
|
+
function buildFile(command: string): void {
|
|
86
|
+
execSync(command, { stdio: "inherit" });
|
|
87
|
+
}
|
|
142
88
|
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
const start = performance.now();
|
|
146
|
-
let builders: Promise<void>[] = [];
|
|
147
|
-
for (const command of buildCommands) {
|
|
148
|
-
builders.push(build(command));
|
|
149
|
-
}
|
|
89
|
+
function getBuildArgs(config: Config): string {
|
|
90
|
+
let buildArgs = "";
|
|
150
91
|
|
|
151
|
-
|
|
92
|
+
buildArgs += " --transform as-test/transform --transform json-as/transform";
|
|
93
|
+
|
|
94
|
+
if (config.config && config.config !== "none") {
|
|
95
|
+
buildArgs += " --config " + config.config;
|
|
96
|
+
}
|
|
97
|
+
// Should also strip any bindings-enabling from asconfig
|
|
98
|
+
if (config.buildOptions.target == "bindings") {
|
|
99
|
+
buildArgs += " --bindings raw --exportRuntime --exportStart _start";
|
|
100
|
+
} else if (config.buildOptions.target == "wasi") {
|
|
101
|
+
buildArgs +=
|
|
102
|
+
" --config ./node_modules/@assemblyscript/wasi-shim/asconfig.json";
|
|
103
|
+
} else {
|
|
152
104
|
console.log(
|
|
153
|
-
chalk.
|
|
105
|
+
`${chalk.bgRed(" ERROR ")}${chalk.dim(":")} could determine target in config! Set target to 'bindings' or 'wasi'`,
|
|
154
106
|
);
|
|
107
|
+
process.exit(0);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
if (
|
|
111
|
+
config.buildOptions.args.length &&
|
|
112
|
+
config.buildOptions.args.find((v) => v.length > 0)
|
|
113
|
+
) {
|
|
114
|
+
buildArgs += " " + config.buildOptions.args.join(" ");
|
|
155
115
|
}
|
|
116
|
+
return buildArgs;
|
|
156
117
|
}
|
package/cli/index.ts
CHANGED
|
@@ -11,7 +11,7 @@ const args: string[] = [];
|
|
|
11
11
|
|
|
12
12
|
const COMMANDS: string[] = ["run", "build", "test", "init"];
|
|
13
13
|
|
|
14
|
-
const version = "0.
|
|
14
|
+
const version = "0.3.1";
|
|
15
15
|
|
|
16
16
|
for (const arg of _args) {
|
|
17
17
|
if (arg.startsWith("-")) flags.push(arg);
|
|
@@ -19,172 +19,19 @@ for (const arg of _args) {
|
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
if (!args.length) {
|
|
22
|
-
if (flags.includes("--
|
|
23
|
-
console.log(
|
|
24
|
-
# timing test
|
|
25
|
-
ok 1 should be strictly equal
|
|
26
|
-
not ok 2 should be strictly equal
|
|
27
|
-
---
|
|
28
|
-
operator: equal
|
|
29
|
-
expected: 100
|
|
30
|
-
actual: 107
|
|
31
|
-
...
|
|
32
|
-
|
|
33
|
-
1..2
|
|
34
|
-
# tests 2
|
|
35
|
-
# pass 1
|
|
36
|
-
# fail 1`);
|
|
37
|
-
} else if (flags.includes("--version") || flags.includes("-v")) {
|
|
38
|
-
console.log("as-test" + " " + version.toString());
|
|
22
|
+
if (flags.includes("--version") || flags.includes("-v")) {
|
|
23
|
+
console.log("as-test v" + version.toString());
|
|
39
24
|
} else {
|
|
40
|
-
|
|
41
|
-
chalk.bold.blueBright("as-test") +
|
|
42
|
-
" is a testing framework for AssemblyScript. " +
|
|
43
|
-
chalk.dim("(v" + version + ")") +
|
|
44
|
-
"\n",
|
|
45
|
-
);
|
|
46
|
-
|
|
47
|
-
console.log(
|
|
48
|
-
chalk.bold("Usage: as-test") +
|
|
49
|
-
" " +
|
|
50
|
-
chalk.dim("<command>") +
|
|
51
|
-
" " +
|
|
52
|
-
chalk.bold.blueBright("[...flags]") +
|
|
53
|
-
" " +
|
|
54
|
-
chalk.bold("[...args]") +
|
|
55
|
-
" " +
|
|
56
|
-
chalk.dim("(alias: ast)") +
|
|
57
|
-
"\n",
|
|
58
|
-
);
|
|
59
|
-
|
|
60
|
-
console.log(chalk.bold("Commands:"));
|
|
61
|
-
console.log(
|
|
62
|
-
" " +
|
|
63
|
-
chalk.bold.blueBright("run") +
|
|
64
|
-
" " +
|
|
65
|
-
chalk.dim("<my-test.spec.ts>") +
|
|
66
|
-
" " +
|
|
67
|
-
"Run unit tests with selected runtime",
|
|
68
|
-
);
|
|
69
|
-
console.log(
|
|
70
|
-
" " +
|
|
71
|
-
chalk.bold.blueBright("build") +
|
|
72
|
-
" " +
|
|
73
|
-
chalk.dim("<my-test.spec.ts>") +
|
|
74
|
-
" " +
|
|
75
|
-
"Build unit tests and compile",
|
|
76
|
-
);
|
|
77
|
-
console.log(
|
|
78
|
-
" " +
|
|
79
|
-
chalk.bold.blueBright("test") +
|
|
80
|
-
" " +
|
|
81
|
-
chalk.dim("<my-test.spec.ts>") +
|
|
82
|
-
" " +
|
|
83
|
-
"Build and run unit tests with selected runtime" +
|
|
84
|
-
"\n",
|
|
85
|
-
);
|
|
86
|
-
|
|
87
|
-
console.log(
|
|
88
|
-
" " +
|
|
89
|
-
chalk.bold.magentaBright("init") +
|
|
90
|
-
" " +
|
|
91
|
-
chalk.strikethrough.dim("") +
|
|
92
|
-
" " +
|
|
93
|
-
"Initialize an empty testing template",
|
|
94
|
-
);
|
|
95
|
-
console.log(
|
|
96
|
-
" " +
|
|
97
|
-
chalk.strikethrough.bold.magentaBright("config") +
|
|
98
|
-
" " +
|
|
99
|
-
chalk.strikethrough.dim("as-test.config.json") +
|
|
100
|
-
" " +
|
|
101
|
-
"Specify the configuration file",
|
|
102
|
-
);
|
|
103
|
-
console.log(
|
|
104
|
-
" " +
|
|
105
|
-
chalk.strikethrough.bold.magentaBright("reporter") +
|
|
106
|
-
" " +
|
|
107
|
-
chalk.strikethrough.dim("<tap>") +
|
|
108
|
-
" " +
|
|
109
|
-
"Specify the test reporter to use",
|
|
110
|
-
);
|
|
111
|
-
console.log(
|
|
112
|
-
" " +
|
|
113
|
-
chalk.strikethrough.bold.magentaBright("use") +
|
|
114
|
-
" " +
|
|
115
|
-
chalk.strikethrough.dim("wasmtime") +
|
|
116
|
-
" " +
|
|
117
|
-
"Specify the runtime to use" +
|
|
118
|
-
"\n",
|
|
119
|
-
);
|
|
120
|
-
|
|
121
|
-
console.log(chalk.bold("Flags:"));
|
|
122
|
-
|
|
123
|
-
console.log(
|
|
124
|
-
" " +
|
|
125
|
-
chalk.strikethrough.dim("run") +
|
|
126
|
-
" " +
|
|
127
|
-
chalk.strikethrough.bold.blue("--coverage") +
|
|
128
|
-
" " +
|
|
129
|
-
"Use code coverage",
|
|
130
|
-
);
|
|
131
|
-
console.log(
|
|
132
|
-
" " +
|
|
133
|
-
chalk.strikethrough.dim("run") +
|
|
134
|
-
" " +
|
|
135
|
-
chalk.strikethrough.bold.blue("--snapshot") +
|
|
136
|
-
" " +
|
|
137
|
-
"Take a snapshot of the tests",
|
|
138
|
-
);
|
|
139
|
-
console.log(
|
|
140
|
-
" " +
|
|
141
|
-
chalk.strikethrough.dim("use") +
|
|
142
|
-
" " +
|
|
143
|
-
chalk.strikethrough.bold.blue("--list") +
|
|
144
|
-
" " +
|
|
145
|
-
"List supported runtimes",
|
|
146
|
-
);
|
|
147
|
-
console.log(
|
|
148
|
-
" " +
|
|
149
|
-
chalk.strikethrough.dim("reporter") +
|
|
150
|
-
" " +
|
|
151
|
-
chalk.strikethrough.bold.blue("--list") +
|
|
152
|
-
" " +
|
|
153
|
-
"List supported reporters",
|
|
154
|
-
);
|
|
155
|
-
console.log(
|
|
156
|
-
" " +
|
|
157
|
-
chalk.strikethrough.dim("<command>") +
|
|
158
|
-
" " +
|
|
159
|
-
chalk.strikethrough.bold.blue("--help") +
|
|
160
|
-
" " +
|
|
161
|
-
"Print info about command" +
|
|
162
|
-
"\n",
|
|
163
|
-
);
|
|
164
|
-
|
|
165
|
-
console.log(
|
|
166
|
-
chalk.dim(
|
|
167
|
-
"If your using this, consider dropping a star, it would help a lot!",
|
|
168
|
-
) + "\n",
|
|
169
|
-
);
|
|
170
|
-
|
|
171
|
-
console.log(
|
|
172
|
-
"View the repo: " +
|
|
173
|
-
chalk.magenta("https://github.com/JairusSW/as-test"),
|
|
174
|
-
);
|
|
175
|
-
console.log(
|
|
176
|
-
"View the docs: " +
|
|
177
|
-
chalk.strikethrough.blue("https://docs.jairus.dev/as-test"),
|
|
178
|
-
);
|
|
25
|
+
info();
|
|
179
26
|
}
|
|
180
27
|
} else if (COMMANDS.includes(args[0]!)) {
|
|
181
28
|
const command = args.shift();
|
|
182
29
|
if (command === "build") {
|
|
183
|
-
build(
|
|
30
|
+
build();
|
|
184
31
|
} else if (command === "run") {
|
|
185
32
|
run();
|
|
186
33
|
} else if (command === "test") {
|
|
187
|
-
build(
|
|
34
|
+
build().then(() => {
|
|
188
35
|
run();
|
|
189
36
|
});
|
|
190
37
|
} else if (command === "init") {
|
|
@@ -199,3 +46,145 @@ not ok 2 should be strictly equal
|
|
|
199
46
|
args[0],
|
|
200
47
|
);
|
|
201
48
|
}
|
|
49
|
+
|
|
50
|
+
function info(): void {
|
|
51
|
+
console.log(
|
|
52
|
+
chalk.bold.blueBright("as-test") +
|
|
53
|
+
" is a testing framework for AssemblyScript. " +
|
|
54
|
+
chalk.dim("(v" + version + ")") +
|
|
55
|
+
"\n",
|
|
56
|
+
);
|
|
57
|
+
|
|
58
|
+
console.log(
|
|
59
|
+
chalk.bold("Usage: as-test") +
|
|
60
|
+
" " +
|
|
61
|
+
chalk.dim("<command>") +
|
|
62
|
+
" " +
|
|
63
|
+
chalk.bold.blueBright("[...flags]") +
|
|
64
|
+
" " +
|
|
65
|
+
chalk.bold("[...args]") +
|
|
66
|
+
" " +
|
|
67
|
+
chalk.dim("(alias: ast)") +
|
|
68
|
+
"\n",
|
|
69
|
+
);
|
|
70
|
+
|
|
71
|
+
console.log(chalk.bold("Commands:"));
|
|
72
|
+
console.log(
|
|
73
|
+
" " +
|
|
74
|
+
chalk.bold.blueBright("run") +
|
|
75
|
+
" " +
|
|
76
|
+
chalk.dim("<my-test.spec.ts>") +
|
|
77
|
+
" " +
|
|
78
|
+
"Run unit tests with selected runtime",
|
|
79
|
+
);
|
|
80
|
+
console.log(
|
|
81
|
+
" " +
|
|
82
|
+
chalk.bold.blueBright("build") +
|
|
83
|
+
" " +
|
|
84
|
+
chalk.dim("<my-test.spec.ts>") +
|
|
85
|
+
" " +
|
|
86
|
+
"Build unit tests and compile",
|
|
87
|
+
);
|
|
88
|
+
console.log(
|
|
89
|
+
" " +
|
|
90
|
+
chalk.bold.blueBright("test") +
|
|
91
|
+
" " +
|
|
92
|
+
chalk.dim("<my-test.spec.ts>") +
|
|
93
|
+
" " +
|
|
94
|
+
"Build and run unit tests with selected runtime" +
|
|
95
|
+
"\n",
|
|
96
|
+
);
|
|
97
|
+
|
|
98
|
+
console.log(
|
|
99
|
+
" " +
|
|
100
|
+
chalk.bold.magentaBright("init") +
|
|
101
|
+
" " +
|
|
102
|
+
chalk.strikethrough.dim("") +
|
|
103
|
+
" " +
|
|
104
|
+
"Initialize an empty testing template",
|
|
105
|
+
);
|
|
106
|
+
console.log(
|
|
107
|
+
" " +
|
|
108
|
+
chalk.strikethrough.bold.magentaBright("config") +
|
|
109
|
+
" " +
|
|
110
|
+
chalk.strikethrough.dim("as-test.config.json") +
|
|
111
|
+
" " +
|
|
112
|
+
"Specify the configuration file",
|
|
113
|
+
);
|
|
114
|
+
console.log(
|
|
115
|
+
" " +
|
|
116
|
+
chalk.strikethrough.bold.magentaBright("reporter") +
|
|
117
|
+
" " +
|
|
118
|
+
chalk.strikethrough.dim("<tap>") +
|
|
119
|
+
" " +
|
|
120
|
+
"Specify the test reporter to use",
|
|
121
|
+
);
|
|
122
|
+
console.log(
|
|
123
|
+
" " +
|
|
124
|
+
chalk.strikethrough.bold.magentaBright("use") +
|
|
125
|
+
" " +
|
|
126
|
+
chalk.strikethrough.dim("wasmtime") +
|
|
127
|
+
" " +
|
|
128
|
+
"Specify the runtime to use" +
|
|
129
|
+
"\n",
|
|
130
|
+
);
|
|
131
|
+
|
|
132
|
+
console.log(chalk.bold("Flags:"));
|
|
133
|
+
|
|
134
|
+
console.log(
|
|
135
|
+
" " +
|
|
136
|
+
chalk.strikethrough.dim("run") +
|
|
137
|
+
" " +
|
|
138
|
+
chalk.strikethrough.bold.blue("--coverage") +
|
|
139
|
+
" " +
|
|
140
|
+
"Use code coverage",
|
|
141
|
+
);
|
|
142
|
+
console.log(
|
|
143
|
+
" " +
|
|
144
|
+
chalk.strikethrough.dim("run") +
|
|
145
|
+
" " +
|
|
146
|
+
chalk.strikethrough.bold.blue("--snapshot") +
|
|
147
|
+
" " +
|
|
148
|
+
"Take a snapshot of the tests",
|
|
149
|
+
);
|
|
150
|
+
console.log(
|
|
151
|
+
" " +
|
|
152
|
+
chalk.strikethrough.dim("use") +
|
|
153
|
+
" " +
|
|
154
|
+
chalk.strikethrough.bold.blue("--list") +
|
|
155
|
+
" " +
|
|
156
|
+
"List supported runtimes",
|
|
157
|
+
);
|
|
158
|
+
console.log(
|
|
159
|
+
" " +
|
|
160
|
+
chalk.strikethrough.dim("reporter") +
|
|
161
|
+
" " +
|
|
162
|
+
chalk.strikethrough.bold.blue("--list") +
|
|
163
|
+
" " +
|
|
164
|
+
"List supported reporters",
|
|
165
|
+
);
|
|
166
|
+
console.log(
|
|
167
|
+
" " +
|
|
168
|
+
chalk.strikethrough.dim("<command>") +
|
|
169
|
+
" " +
|
|
170
|
+
chalk.strikethrough.bold.blue("--help") +
|
|
171
|
+
" " +
|
|
172
|
+
"Print info about command" +
|
|
173
|
+
"\n",
|
|
174
|
+
);
|
|
175
|
+
|
|
176
|
+
console.log(
|
|
177
|
+
chalk.dim(
|
|
178
|
+
"If your using this, consider dropping a star, it would help a lot!",
|
|
179
|
+
) + "\n",
|
|
180
|
+
);
|
|
181
|
+
|
|
182
|
+
console.log(
|
|
183
|
+
"View the repo: " +
|
|
184
|
+
chalk.magenta("https://github.com/JairusSW/as-test"),
|
|
185
|
+
);
|
|
186
|
+
console.log(
|
|
187
|
+
"View the docs: " +
|
|
188
|
+
chalk.strikethrough.blue("https://docs.jairus.dev/as-test"),
|
|
189
|
+
);
|
|
190
|
+
}
|