as-test 0.1.9 → 0.1.10
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 +12 -13
- package/asconfig.json +2 -4
- package/assembly/__tests__/example.spec.ts +2 -13
- package/assembly/index.ts +7 -2
- package/bin/build.js +125 -98
- package/bin/index.js +161 -132
- package/bin/init.js +35 -31
- package/bin/run.js +62 -42
- package/bin/types.js +29 -29
- package/bin/util.js +20 -20
- package/cli/build.ts +10 -3
- package/cli/index.ts +1 -1
- package/cli/run.ts +27 -16
- package/package.json +4 -4
- package/transform/lib/coverage.js +325 -319
- package/transform/lib/index.js +35 -31
- package/transform/lib/mock.js +57 -49
- package/transform/package.json +1 -1
- package/transform/src/mock.ts +3 -1
- package/assembly/test.ts +0 -71
package/CHANGELOG.md
CHANGED
|
@@ -18,5 +18,6 @@ v0.1.6 - Fix: args should be prefixed with a space
|
|
|
18
18
|
v0.1.7 - Fix: remove warning about wasi-shim not being included when it is included
|
|
19
19
|
v0.1.8 - Feat: function mocking
|
|
20
20
|
v0.1.9 - Fix: mocks were not being applied to declared functions, only property accesses
|
|
21
|
+
v0.1.10 - Feat: support node, deno, and bun
|
|
21
22
|
|
|
22
|
-
|
|
23
|
+
[UNRELEASED] - Feat: snapshotting
|
package/README.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
| _ || __| ___|_ _|| __|| __||_ _|
|
|
4
4
|
| ||__ ||___| | | | __||__ | | |
|
|
5
5
|
|__|__||_____| |_| |_____||_____| |_|
|
|
6
|
-
v0.1.
|
|
6
|
+
v0.1.10
|
|
7
7
|
</pre>
|
|
8
8
|
</h5>
|
|
9
9
|
|
|
@@ -15,6 +15,15 @@ npm install as-test
|
|
|
15
15
|
|
|
16
16
|
Note: The transform _is_ OPTIONAL, though it is required to enable code coverage.
|
|
17
17
|
|
|
18
|
+
## Templates
|
|
19
|
+
|
|
20
|
+
I provide two templates for reference
|
|
21
|
+
|
|
22
|
+
[WASI](https://github.com/JairusSW/as-test/tree/template/wasi)
|
|
23
|
+
[Node/Bun/Deno](https://github.com/JairusSW/as-test/tree/template/node-bun-deno)
|
|
24
|
+
|
|
25
|
+
View the docs: https://docs.jairus.dev/as-test
|
|
26
|
+
|
|
18
27
|
## Usage
|
|
19
28
|
|
|
20
29
|
You can setup the configuration files using
|
|
@@ -38,7 +47,7 @@ import {
|
|
|
38
47
|
afterAll,
|
|
39
48
|
beforeEach,
|
|
40
49
|
afterEach,
|
|
41
|
-
|
|
50
|
+
mockFn,
|
|
42
51
|
log,
|
|
43
52
|
run
|
|
44
53
|
} from "as-test";
|
|
@@ -52,7 +61,7 @@ afterAll(() => {
|
|
|
52
61
|
});
|
|
53
62
|
|
|
54
63
|
// Mock/override the function console.log
|
|
55
|
-
|
|
64
|
+
mockFn<void>("console.log", (data: string): void => {
|
|
56
65
|
console.log("[MOCKED]: " + data + "\n");
|
|
57
66
|
});
|
|
58
67
|
|
|
@@ -129,16 +138,6 @@ If you use this project in your codebase, consider dropping a [⭐ HERE](https:/
|
|
|
129
138
|
This library is in the EARLY STAGES OF DEVELOPMENT!
|
|
130
139
|
If you want a feature, drop an issue (and again, maybe a star). I'll likely add it in less than 7 days.
|
|
131
140
|
|
|
132
|
-
## Contact
|
|
133
|
-
|
|
134
|
-
Contact me at:
|
|
135
|
-
|
|
136
|
-
Email: `me@jairus.dev`
|
|
137
|
-
|
|
138
|
-
GitHub: `JairusSW`
|
|
139
|
-
|
|
140
|
-
Discord: `jairussw`
|
|
141
|
-
|
|
142
141
|
## Issues
|
|
143
142
|
|
|
144
143
|
Please submit an issue to https://github.com/JairusSW/as-test/issues if you find anything wrong with this library
|
package/asconfig.json
CHANGED
|
@@ -8,20 +8,10 @@ import {
|
|
|
8
8
|
afterEach,
|
|
9
9
|
log,
|
|
10
10
|
run,
|
|
11
|
-
|
|
11
|
+
mockFn,
|
|
12
12
|
} from "..";
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
console.log("a: " + a.toString());
|
|
16
|
-
console.log("b: " + b.toString());
|
|
17
|
-
console.log("c: " + c.toString());
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
mock("hello", (a: i32, b: i32, c: i32): void => {
|
|
21
|
-
hello(a + 10, b + 10, c + 10);
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
mock("console.log", (data: string): void => {
|
|
14
|
+
mockFn<void>("console.log", (data: string): void => {
|
|
25
15
|
console.log("[MOCKED]: " + data);
|
|
26
16
|
});
|
|
27
17
|
|
|
@@ -47,7 +37,6 @@ describe("Math operations", () => {
|
|
|
47
37
|
});
|
|
48
38
|
|
|
49
39
|
test("Mock", () => {
|
|
50
|
-
hello(1, 2, 3);
|
|
51
40
|
console.log("hello");
|
|
52
41
|
});
|
|
53
42
|
|
package/assembly/index.ts
CHANGED
|
@@ -175,7 +175,12 @@ export function afterEach(callback: () => void): void {
|
|
|
175
175
|
after_each_callback = callback;
|
|
176
176
|
}
|
|
177
177
|
|
|
178
|
-
|
|
178
|
+
/**
|
|
179
|
+
* Overrides all references to an existing function to instead point to this
|
|
180
|
+
* @param {string} fn - name of function to override
|
|
181
|
+
* @param {() => returnType} callback - the function to substitute it with
|
|
182
|
+
*/
|
|
183
|
+
export function mockFn<returnType>(
|
|
179
184
|
fn: string,
|
|
180
185
|
callback: (...args: any[]) => returnType,
|
|
181
186
|
): void {}
|
|
@@ -235,7 +240,7 @@ export function run(options: RunOptions = new RunOptions()): void {
|
|
|
235
240
|
),
|
|
236
241
|
);
|
|
237
242
|
console.log(
|
|
238
|
-
rainbow.dimMk("\n------------------- v0.1.
|
|
243
|
+
rainbow.dimMk("\n------------------- v0.1.10 -------------------\n"),
|
|
239
244
|
);
|
|
240
245
|
// @ts-ignore
|
|
241
246
|
if (isDefined(COVERAGE_USE)) {
|
package/bin/build.js
CHANGED
|
@@ -6,113 +6,140 @@ 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 (!existsSync("./node_modules/@assemblyscript/wasi-shim/asconfig.json")) {
|
|
39
|
+
console.log(
|
|
40
|
+
chalk.bgRed(" ERROR ") +
|
|
41
|
+
chalk.dim(":") +
|
|
42
|
+
" " +
|
|
43
|
+
"could not find @assemblyscript/wasi-shim! Add it to your dependencies to run with WASI!",
|
|
44
|
+
);
|
|
45
|
+
process.exit(1);
|
|
17
46
|
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
47
|
+
if (
|
|
48
|
+
pkg.dependencies &&
|
|
49
|
+
!Object.keys(pkg.dependencies).includes("@assemblyscript/wasi-shim") &&
|
|
50
|
+
pkg.devDependencies &&
|
|
51
|
+
!Object.keys(pkg.devDependencies).includes("@assemblyscript/wasi-shim") &&
|
|
52
|
+
pkg.peerDependencies &&
|
|
53
|
+
!Object.keys(pkg.peerDependencies).includes(
|
|
54
|
+
"@assemblyscript/wasi-shim",
|
|
55
|
+
) &&
|
|
56
|
+
existsSync("./node_modules/@assemblyscript/wasi-shim/asconfig.json")
|
|
57
|
+
) {
|
|
58
|
+
console.log(
|
|
59
|
+
chalk.bold.bgMagentaBright(" WARN ") +
|
|
60
|
+
chalk.dim(": @assemblyscript/wasi-shim") +
|
|
61
|
+
" is not included in project dependencies!",
|
|
62
|
+
);
|
|
21
63
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
64
|
+
}
|
|
65
|
+
let packageManagerCommand = "npx";
|
|
66
|
+
if (
|
|
67
|
+
process.env.npm_config_user_agent &&
|
|
68
|
+
process.env.npm_config_user_agent.includes("pnpm")
|
|
69
|
+
) {
|
|
70
|
+
packageManagerCommand = "pnpx";
|
|
71
|
+
} else if (
|
|
72
|
+
process.env.npm_config_user_agent &&
|
|
73
|
+
process.env.npm_config_user_agent.includes("yarn")
|
|
74
|
+
) {
|
|
75
|
+
packageManagerCommand = "yarn run";
|
|
76
|
+
} else if (
|
|
77
|
+
process.env.npm_config_user_agent &&
|
|
78
|
+
process.env.npm_config_user_agent.includes("bun")
|
|
79
|
+
) {
|
|
80
|
+
packageManagerCommand = "bunx";
|
|
81
|
+
}
|
|
82
|
+
console.log("");
|
|
83
|
+
const inputFiles = await glob(config.input);
|
|
84
|
+
for (const file of inputFiles) {
|
|
85
|
+
console.log(chalk.dim("Including " + file));
|
|
86
|
+
let command = `${packageManagerCommand} asc ${file}${args.length ? " " + args.join(" ") : ""}`;
|
|
87
|
+
if (config.config !== "none") {
|
|
88
|
+
command += " --config " + config.config;
|
|
28
89
|
}
|
|
29
|
-
const pkg = JSON.parse(readFileSync("./package.json").toString());
|
|
30
|
-
let buildCommands = [];
|
|
31
90
|
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
|
-
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
|
-
}
|
|
91
|
+
command +=
|
|
92
|
+
" --config ./node_modules/@assemblyscript/wasi-shim/asconfig.json";
|
|
50
93
|
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
94
|
+
const outFile =
|
|
95
|
+
config.outDir +
|
|
96
|
+
"/" +
|
|
97
|
+
file.slice(file.lastIndexOf("/") + 1).replace(".ts", ".wasm");
|
|
98
|
+
if (config.outDir) {
|
|
99
|
+
command += " -o " + outFile;
|
|
55
100
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
101
|
+
if (config.coverage.enabled) {
|
|
102
|
+
console.log(chalk.dim("Enabling coverage"));
|
|
103
|
+
command += " --use COVERAGE_USE=1 --transform as-test/transform";
|
|
104
|
+
if (config.coverage.show) command += " --use COVERAGE_SHOW=1";
|
|
59
105
|
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
packageManagerCommand = "bunx";
|
|
106
|
+
if (config.buildOptions.args) {
|
|
107
|
+
command += " " + config.buildOptions.args.join(" ");
|
|
63
108
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
command +=
|
|
71
|
-
" --config ./node_modules/@assemblyscript/wasi-shim/asconfig.json";
|
|
72
|
-
}
|
|
73
|
-
if (config.config !== "none") {
|
|
74
|
-
command += " --config " + config.config;
|
|
75
|
-
}
|
|
76
|
-
const outFile = config.outDir +
|
|
77
|
-
"/" +
|
|
78
|
-
file.slice(file.lastIndexOf("/") + 1).replace(".ts", ".wasm");
|
|
79
|
-
if (config.outDir) {
|
|
80
|
-
command += " -o " + outFile;
|
|
81
|
-
}
|
|
82
|
-
if (config.coverage.enabled) {
|
|
83
|
-
console.log(chalk.dim("Enabling coverage"));
|
|
84
|
-
command += " --use COVERAGE_USE=1 --transform as-test/transform";
|
|
85
|
-
if (config.coverage.show)
|
|
86
|
-
command += " --use COVERAGE_SHOW=1";
|
|
87
|
-
}
|
|
88
|
-
if (config.buildOptions.args) {
|
|
89
|
-
command += " " + config.buildOptions.args.join(" ");
|
|
90
|
-
}
|
|
91
|
-
buildCommands.push(command);
|
|
109
|
+
if (
|
|
110
|
+
["node", "deno", "bun"].includes(
|
|
111
|
+
config.runOptions.runtime.run.split(" ")[0],
|
|
112
|
+
)
|
|
113
|
+
) {
|
|
114
|
+
command += " --exportStart";
|
|
92
115
|
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
});
|
|
106
|
-
});
|
|
107
|
-
};
|
|
108
|
-
if (config.buildOptions.parallel) {
|
|
109
|
-
console.log(chalk.dim("Building sources in parallel..."));
|
|
110
|
-
const start = performance.now();
|
|
111
|
-
let builders = [];
|
|
112
|
-
for (const command of buildCommands) {
|
|
113
|
-
builders.push(build(command));
|
|
116
|
+
buildCommands.push(command);
|
|
117
|
+
}
|
|
118
|
+
const build = (command) => {
|
|
119
|
+
return new Promise((resolve, _) => {
|
|
120
|
+
console.log(chalk.dim("Building: " + command));
|
|
121
|
+
exec(command, (err, stdout, stderr) => {
|
|
122
|
+
if (config.buildOptions.verbose) {
|
|
123
|
+
process.stdout.write(stdout);
|
|
124
|
+
}
|
|
125
|
+
if (err) {
|
|
126
|
+
process.stderr.write(stderr + "\n");
|
|
127
|
+
process.exit(1);
|
|
114
128
|
}
|
|
115
|
-
|
|
116
|
-
|
|
129
|
+
resolve();
|
|
130
|
+
});
|
|
131
|
+
});
|
|
132
|
+
};
|
|
133
|
+
if (config.buildOptions.parallel) {
|
|
134
|
+
console.log(chalk.dim("Building sources in parallel..."));
|
|
135
|
+
const start = performance.now();
|
|
136
|
+
let builders = [];
|
|
137
|
+
for (const command of buildCommands) {
|
|
138
|
+
builders.push(build(command));
|
|
117
139
|
}
|
|
140
|
+
await Promise.all(builders);
|
|
141
|
+
console.log(
|
|
142
|
+
chalk.dim("Compiled in " + formatTime(performance.now() - start)) + "\n",
|
|
143
|
+
);
|
|
144
|
+
}
|
|
118
145
|
}
|
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.10";
|
|
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
|
}
|