as-test 0.4.0 → 0.4.2

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.
Files changed (49) hide show
  1. package/CHANGELOG.md +10 -1
  2. package/README.md +12 -12
  3. package/as-test.config.json +1 -1
  4. package/assembly/__tests__/array.spec.ts +3 -3
  5. package/assembly/src/expectation.ts +29 -16
  6. package/assembly/src/suite.ts +2 -0
  7. package/assembly/src/tests.ts +1 -0
  8. package/bin/build.js +65 -77
  9. package/bin/index.js +130 -160
  10. package/bin/init.js +96 -109
  11. package/bin/reporter.js +1 -1
  12. package/bin/run.js +210 -236
  13. package/bin/types.js +25 -25
  14. package/bin/util.js +35 -42
  15. package/cli/run.ts +13 -15
  16. package/cli/tsconfig.json +2 -1
  17. package/package.json +12 -9
  18. package/transform/lib/builder.js +1361 -0
  19. package/transform/lib/builder.js.map +1 -0
  20. package/transform/lib/coverage.js +6 -6
  21. package/transform/lib/coverage.js.map +1 -1
  22. package/transform/lib/index.js +1 -1
  23. package/transform/lib/index.js.map +1 -1
  24. package/transform/lib/linker.js +19 -0
  25. package/transform/lib/linker.js.map +1 -0
  26. package/transform/lib/mock.js +9 -9
  27. package/transform/lib/mock.js.map +1 -1
  28. package/transform/lib/range.js +13 -0
  29. package/transform/lib/range.js.map +1 -0
  30. package/transform/lib/types.js +26 -0
  31. package/transform/lib/types.js.map +1 -0
  32. package/transform/lib/util.js +47 -0
  33. package/transform/lib/util.js.map +1 -0
  34. package/transform/lib/visitor.js +532 -0
  35. package/transform/lib/visitor.js.map +1 -0
  36. package/transform/src/builder.ts +1474 -0
  37. package/transform/src/coverage.ts +6 -7
  38. package/transform/src/index.ts +1 -2
  39. package/transform/src/linker.ts +41 -0
  40. package/transform/src/mock.ts +9 -10
  41. package/transform/src/range.ts +12 -0
  42. package/transform/src/types.ts +35 -0
  43. package/transform/src/util.ts +81 -0
  44. package/transform/src/visitor.ts +744 -0
  45. package/.trunk/configs/.markdownlint.yaml +0 -2
  46. package/.trunk/configs/.yamllint.yaml +0 -7
  47. package/.trunk/trunk.yaml +0 -34
  48. package/bin/about.js +0 -135
  49. package/bin/package.json +0 -3
package/bin/index.js CHANGED
@@ -9,168 +9,138 @@ const args = [];
9
9
  const COMMANDS = ["run", "build", "test", "init"];
10
10
  const version = "0.3.5";
11
11
  for (const arg of _args) {
12
- if (arg.startsWith("-")) flags.push(arg);
13
- else args.push(arg);
12
+ if (arg.startsWith("-"))
13
+ flags.push(arg);
14
+ else
15
+ args.push(arg);
14
16
  }
15
17
  if (!args.length) {
16
- if (flags.includes("--version") || flags.includes("-v")) {
17
- console.log("as-test v" + version.toString());
18
- } else {
19
- info();
20
- }
21
- } else if (COMMANDS.includes(args[0])) {
22
- const command = args.shift();
23
- if (command === "build") {
24
- build();
25
- } else if (command === "run") {
26
- run();
27
- } else if (command === "test") {
28
- build().then(() => {
29
- run();
30
- });
31
- } else if (command === "init") {
32
- init(args);
33
- }
34
- } else {
35
- console.log(
36
- chalk.bgRed(" ERROR ") +
37
- chalk.dim(":") +
38
- " " +
39
- chalk.bold("Unknown command: ") +
40
- args[0],
41
- );
18
+ if (flags.includes("--version") || flags.includes("-v")) {
19
+ console.log("as-test v" + version.toString());
20
+ }
21
+ else {
22
+ info();
23
+ }
24
+ }
25
+ else if (COMMANDS.includes(args[0])) {
26
+ const command = args.shift();
27
+ if (command === "build") {
28
+ build();
29
+ }
30
+ else if (command === "run") {
31
+ run();
32
+ }
33
+ else if (command === "test") {
34
+ build().then(() => {
35
+ run();
36
+ });
37
+ }
38
+ else if (command === "init") {
39
+ init(args);
40
+ }
41
+ }
42
+ else {
43
+ console.log(chalk.bgRed(" ERROR ") +
44
+ chalk.dim(":") +
45
+ " " +
46
+ chalk.bold("Unknown command: ") +
47
+ args[0]);
42
48
  }
43
49
  function info() {
44
- console.log(
45
- chalk.bold.blueBright("as-test") +
46
- " is a testing framework for AssemblyScript. " +
47
- chalk.dim("(v" + version + ")") +
48
- "\n",
49
- );
50
- console.log(
51
- chalk.bold("Usage: as-test") +
52
- " " +
53
- chalk.dim("<command>") +
54
- " " +
55
- chalk.bold.blueBright("[...flags]") +
56
- " " +
57
- chalk.bold("[...args]") +
58
- " " +
59
- chalk.dim("(alias: ast)") +
60
- "\n",
61
- );
62
- console.log(chalk.bold("Commands:"));
63
- console.log(
64
- " " +
65
- chalk.bold.blueBright("run") +
66
- " " +
67
- chalk.dim("<my-test.spec.ts>") +
68
- " " +
69
- "Run unit tests with selected runtime",
70
- );
71
- console.log(
72
- " " +
73
- chalk.bold.blueBright("build") +
74
- " " +
75
- chalk.dim("<my-test.spec.ts>") +
76
- " " +
77
- "Build unit tests and compile",
78
- );
79
- console.log(
80
- " " +
81
- chalk.bold.blueBright("test") +
82
- " " +
83
- chalk.dim("<my-test.spec.ts>") +
84
- " " +
85
- "Build and run unit tests with selected runtime" +
86
- "\n",
87
- );
88
- console.log(
89
- " " +
90
- chalk.bold.magentaBright("init") +
91
- " " +
92
- chalk.strikethrough.dim("") +
93
- " " +
94
- "Initialize an empty testing template",
95
- );
96
- console.log(
97
- " " +
98
- chalk.strikethrough.bold.magentaBright("config") +
99
- " " +
100
- chalk.strikethrough.dim("as-test.config.json") +
101
- " " +
102
- "Specify the configuration file",
103
- );
104
- console.log(
105
- " " +
106
- chalk.strikethrough.bold.magentaBright("reporter") +
107
- " " +
108
- chalk.strikethrough.dim("<tap>") +
109
- " " +
110
- "Specify the test reporter to use",
111
- );
112
- console.log(
113
- " " +
114
- chalk.strikethrough.bold.magentaBright("use") +
115
- " " +
116
- chalk.strikethrough.dim("wasmtime") +
117
- " " +
118
- "Specify the runtime to use" +
119
- "\n",
120
- );
121
- console.log(chalk.bold("Flags:"));
122
- console.log(
123
- " " +
124
- chalk.strikethrough.dim("run") +
125
- " " +
126
- chalk.strikethrough.bold.blue("--coverage") +
127
- " " +
128
- "Use code coverage",
129
- );
130
- console.log(
131
- " " +
132
- chalk.strikethrough.dim("run") +
133
- " " +
134
- chalk.strikethrough.bold.blue("--snapshot") +
135
- " " +
136
- "Take a snapshot of the tests",
137
- );
138
- console.log(
139
- " " +
140
- chalk.strikethrough.dim("use") +
141
- " " +
142
- chalk.strikethrough.bold.blue("--list") +
143
- " " +
144
- "List supported runtimes",
145
- );
146
- console.log(
147
- " " +
148
- chalk.strikethrough.dim("reporter") +
149
- " " +
150
- chalk.strikethrough.bold.blue("--list") +
151
- " " +
152
- "List supported reporters",
153
- );
154
- console.log(
155
- " " +
156
- chalk.strikethrough.dim("<command>") +
157
- " " +
158
- chalk.strikethrough.bold.blue("--help") +
159
- " " +
160
- "Print info about command" +
161
- "\n",
162
- );
163
- console.log(
164
- chalk.dim(
165
- "If your using this, consider dropping a star, it would help a lot!",
166
- ) + "\n",
167
- );
168
- console.log(
169
- "View the repo: " +
170
- chalk.magenta("https://github.com/JairusSW/as-test"),
171
- );
172
- console.log(
173
- "View the docs: " +
174
- chalk.strikethrough.blue("https://docs.jairus.dev/as-test"),
175
- );
50
+ console.log(chalk.bold.blueBright("as-test") +
51
+ " is a testing framework for AssemblyScript. " +
52
+ chalk.dim("(v" + version + ")") +
53
+ "\n");
54
+ console.log(chalk.bold("Usage: as-test") +
55
+ " " +
56
+ chalk.dim("<command>") +
57
+ " " +
58
+ chalk.bold.blueBright("[...flags]") +
59
+ " " +
60
+ chalk.bold("[...args]") +
61
+ " " +
62
+ chalk.dim("(alias: ast)") +
63
+ "\n");
64
+ console.log(chalk.bold("Commands:"));
65
+ console.log(" " +
66
+ chalk.bold.blueBright("run") +
67
+ " " +
68
+ chalk.dim("<my-test.spec.ts>") +
69
+ " " +
70
+ "Run unit tests with selected runtime");
71
+ console.log(" " +
72
+ chalk.bold.blueBright("build") +
73
+ " " +
74
+ chalk.dim("<my-test.spec.ts>") +
75
+ " " +
76
+ "Build unit tests and compile");
77
+ console.log(" " +
78
+ chalk.bold.blueBright("test") +
79
+ " " +
80
+ chalk.dim("<my-test.spec.ts>") +
81
+ " " +
82
+ "Build and run unit tests with selected runtime" +
83
+ "\n");
84
+ console.log(" " +
85
+ chalk.bold.magentaBright("init") +
86
+ " " +
87
+ chalk.strikethrough.dim("") +
88
+ " " +
89
+ "Initialize an empty testing template");
90
+ console.log(" " +
91
+ chalk.strikethrough.bold.magentaBright("config") +
92
+ " " +
93
+ chalk.strikethrough.dim("as-test.config.json") +
94
+ " " +
95
+ "Specify the configuration file");
96
+ console.log(" " +
97
+ chalk.strikethrough.bold.magentaBright("reporter") +
98
+ " " +
99
+ chalk.strikethrough.dim("<tap>") +
100
+ " " +
101
+ "Specify the test reporter to use");
102
+ console.log(" " +
103
+ chalk.strikethrough.bold.magentaBright("use") +
104
+ " " +
105
+ chalk.strikethrough.dim("wasmtime") +
106
+ " " +
107
+ "Specify the runtime to use" +
108
+ "\n");
109
+ console.log(chalk.bold("Flags:"));
110
+ console.log(" " +
111
+ chalk.strikethrough.dim("run") +
112
+ " " +
113
+ chalk.strikethrough.bold.blue("--coverage") +
114
+ " " +
115
+ "Use code coverage");
116
+ console.log(" " +
117
+ chalk.strikethrough.dim("run") +
118
+ " " +
119
+ chalk.strikethrough.bold.blue("--snapshot") +
120
+ " " +
121
+ "Take a snapshot of the tests");
122
+ console.log(" " +
123
+ chalk.strikethrough.dim("use") +
124
+ " " +
125
+ chalk.strikethrough.bold.blue("--list") +
126
+ " " +
127
+ "List supported runtimes");
128
+ console.log(" " +
129
+ chalk.strikethrough.dim("reporter") +
130
+ " " +
131
+ chalk.strikethrough.bold.blue("--list") +
132
+ " " +
133
+ "List supported reporters");
134
+ console.log(" " +
135
+ chalk.strikethrough.dim("<command>") +
136
+ " " +
137
+ chalk.strikethrough.bold.blue("--help") +
138
+ " " +
139
+ "Print info about command" +
140
+ "\n");
141
+ console.log(chalk.dim("If your using this, consider dropping a star, it would help a lot!") + "\n");
142
+ console.log("View the repo: " +
143
+ chalk.magenta("https://github.com/JairusSW/as-test"));
144
+ console.log("View the docs: " +
145
+ chalk.strikethrough.blue("https://docs.jairus.dev/as-test"));
176
146
  }
package/bin/init.js CHANGED
@@ -5,27 +5,24 @@ import { createInterface } from "readline";
5
5
  import { loadConfig } from "./util.js";
6
6
  const TARGETS = ["wasi", "bindings"];
7
7
  export async function init(args) {
8
- const rl = createInterface({
9
- input: process.stdin,
10
- output: process.stdout,
11
- });
12
- console.log(chalk.bold("as-test init v0.3.5") + "\n");
13
- console.log(chalk.dim("[1/3]") + " select a target [wasi/bindings]");
14
- const target = await ask(chalk.dim(" -> "), rl);
15
- if (!TARGETS.includes(target)) {
16
- console.log("Invalid target " + target + ". Exiting.");
17
- process.exit(0);
18
- }
19
- process.stdout.write(`\u001B[1A`);
20
- process.stdout.write("\x1B[2K");
21
- process.stdout.write("\x1B[0G");
22
- console.log(
23
- "\n" +
24
- chalk.dim("[2/3]") +
25
- " attempting to create the following files. Continue? [y/n]\n",
26
- );
27
- console.log(
28
- chalk.dim(` ├── 📂 assembly/
8
+ const rl = createInterface({
9
+ input: process.stdin,
10
+ output: process.stdout,
11
+ });
12
+ console.log(chalk.bold("as-test init v0.3.5") + "\n");
13
+ console.log(chalk.dim("[1/3]") + " select a target [wasi/bindings]");
14
+ const target = await ask(chalk.dim(" -> "), rl);
15
+ if (!TARGETS.includes(target)) {
16
+ console.log("Invalid target " + target + ". Exiting.");
17
+ process.exit(0);
18
+ }
19
+ process.stdout.write(`\u001B[1A`);
20
+ process.stdout.write("\x1B[2K");
21
+ process.stdout.write("\x1B[0G");
22
+ console.log("\n" +
23
+ chalk.dim("[2/3]") +
24
+ " attempting to create the following files. Continue? [y/n]\n");
25
+ console.log(chalk.dim(` ├── 📂 assembly/
29
26
  │ └── 📂 __tests__/
30
27
  │ └── 🧪 example.spec.ts
31
28
  ├── 📂 build/
@@ -33,27 +30,25 @@ export async function init(args) {
33
30
  ├── 📂 tests/
34
31
  │ └── 📃 as-test.run.js
35
32
  ├── ⚙️ as-test.config.json
36
- └── ⚙️ package.json\n`),
37
- );
38
- const cont = (await ask(chalk.dim(" -> "), rl)).toLowerCase().trim();
39
- if (cont == "n" || cont == "no") {
40
- console.log("Exiting.");
41
- process.exit(0);
42
- }
43
- let config = loadConfig(path.join(process.cwd(), "./as-test.config.json"));
44
- if (target == "wasi" && config.buildOptions.target != "wasi") {
45
- config.buildOptions.target = "wasi";
46
- config.runOptions.runtime.name = "wasmtime";
47
- config.runOptions.runtime.run = "wasmtime <file>";
48
- } else if (target == "bindings" && config.buildOptions.target != "bindings") {
49
- config.buildOptions.target = "bindings";
50
- config.runOptions.runtime.name = "node";
51
- config.runOptions.runtime.run = "node ./tests/<name>.run.js";
52
- }
53
- writeFile("./as-test.config.json", JSON.stringify(config, null, 2));
54
- writeFile(
55
- "./assembly/__tests__/example.spec.ts",
56
- `import {
33
+ └── ⚙️ package.json\n`));
34
+ const cont = (await ask(chalk.dim(" -> "), rl)).toLowerCase().trim();
35
+ if (cont == "n" || cont == "no") {
36
+ console.log("Exiting.");
37
+ process.exit(0);
38
+ }
39
+ let config = loadConfig(path.join(process.cwd(), "./as-test.config.json"));
40
+ if (target == "wasi" && config.buildOptions.target != "wasi") {
41
+ config.buildOptions.target = "wasi";
42
+ config.runOptions.runtime.name = "wasmtime";
43
+ config.runOptions.runtime.run = "wasmtime <file>";
44
+ }
45
+ else if (target == "bindings" && config.buildOptions.target != "bindings") {
46
+ config.buildOptions.target = "bindings";
47
+ config.runOptions.runtime.name = "node";
48
+ config.runOptions.runtime.run = "node ./tests/<name>.run.js";
49
+ }
50
+ writeFile("./as-test.config.json", JSON.stringify(config, null, 2));
51
+ writeFile("./assembly/__tests__/example.spec.ts", `import {
57
52
  describe,
58
53
  expect,
59
54
  test,
@@ -143,85 +138,77 @@ run();
143
138
  function sleep(ms: i64): void {
144
139
  const target = Date.now() + ms;
145
140
  while (target > Date.now()) { }
146
- }`,
147
- );
148
- writeDir("./build/");
149
- writeDir("./logs/");
150
- if (target == "bindings") {
151
- writeFile(
152
- "./tests/example.run.js",
153
- `import { readFileSync } from "fs";
141
+ }`);
142
+ writeDir("./build/");
143
+ writeDir("./logs/");
144
+ if (target == "bindings") {
145
+ writeFile("./tests/example.run.js", `import { readFileSync } from "fs";
154
146
  import { instantiate } from "../build/example.spec.js";
155
147
 
156
148
  const binary = readFileSync("./build/example.spec.wasm");
157
149
  const module = new WebAssembly.Module(binary);
158
150
 
159
- const exports = instantiate(module, {});`,
160
- );
161
- }
162
- const PKG_PATH = path.join(process.cwd(), "./package.json");
163
- if (!hasDep(PKG_PATH, "assemblyscript")) {
164
- console.log(
165
- chalk.dim(
166
- "AssemblyScript is not included in dependencies.\nInstall it with " +
167
- (process.env.npm_config_user_agent == "yarn"
168
- ? process.env.npm_config_user_agent + " add assemblyscript"
169
- : process.env.npm_config_user_agent + " install assemblyscript"),
170
- ),
171
- );
172
- }
173
- const pkg = JSON.parse(
174
- existsSync(PKG_PATH) ? readFileSync(PKG_PATH).toString() : "{}",
175
- );
176
- if (!pkg["scripts"]) pkg["scripts"] = {};
177
- if (!pkg.scripts["pretest"]) {
178
- pkg.scripts["pretest"] = "as-test build";
179
- pkg.scripts["test"] = "as-test run";
180
- } else {
181
- pkg.scripts["test"] = "as-test test";
182
- }
183
- if (!pkg["devDependencies"]) pkg["devDependencies"] = {};
184
- if (!pkg["devDependencies"]["as-test"])
185
- pkg["devDependencies"]["as-test"] = "^0.3.5";
186
- if (target == "bindings") {
187
- pkg["type"] = "module";
188
- }
189
- writeFileSync(PKG_PATH, JSON.stringify(pkg, null, 2));
190
- process.exit(0);
151
+ const exports = instantiate(module, {});`);
152
+ }
153
+ const PKG_PATH = path.join(process.cwd(), "./package.json");
154
+ if (!hasDep(PKG_PATH, "assemblyscript")) {
155
+ console.log(chalk.dim("AssemblyScript is not included in dependencies.\nInstall it with " +
156
+ (process.env.npm_config_user_agent == "yarn"
157
+ ? process.env.npm_config_user_agent + " add assemblyscript"
158
+ : process.env.npm_config_user_agent + " install assemblyscript")));
159
+ }
160
+ const pkg = JSON.parse(existsSync(PKG_PATH) ? readFileSync(PKG_PATH).toString() : "{}");
161
+ if (!pkg["scripts"])
162
+ pkg["scripts"] = {};
163
+ if (!pkg.scripts["pretest"]) {
164
+ pkg.scripts["pretest"] = "as-test build";
165
+ pkg.scripts["test"] = "as-test run";
166
+ }
167
+ else {
168
+ pkg.scripts["test"] = "as-test test";
169
+ }
170
+ if (!pkg["devDependencies"])
171
+ pkg["devDependencies"] = {};
172
+ if (!pkg["devDependencies"]["as-test"])
173
+ pkg["devDependencies"]["as-test"] = "^0.3.5";
174
+ if (target == "bindings") {
175
+ pkg["type"] = "module";
176
+ }
177
+ writeFileSync(PKG_PATH, JSON.stringify(pkg, null, 2));
178
+ process.exit(0);
191
179
  }
192
180
  function ask(question, face) {
193
- return new Promise((res, _) => {
194
- face.question(question, (answer) => {
195
- res(answer);
181
+ return new Promise((res, _) => {
182
+ face.question(question, (answer) => {
183
+ res(answer);
184
+ });
196
185
  });
197
- });
198
186
  }
199
187
  function writeFile(pth, data) {
200
- const fmtPath = path.join(process.cwd(), pth);
201
- if (existsSync(fmtPath)) return;
202
- if (!existsSync(path.dirname(fmtPath)))
203
- mkdirSync(path.dirname(fmtPath), { recursive: true });
204
- writeFileSync(fmtPath, data);
188
+ const fmtPath = path.join(process.cwd(), pth);
189
+ if (existsSync(fmtPath))
190
+ return;
191
+ if (!existsSync(path.dirname(fmtPath)))
192
+ mkdirSync(path.dirname(fmtPath), { recursive: true });
193
+ writeFileSync(fmtPath, data);
205
194
  }
206
195
  function writeDir(pth) {
207
- const fmtPath = path.join(process.cwd(), pth);
208
- if (existsSync(fmtPath)) return;
209
- mkdirSync(fmtPath);
196
+ const fmtPath = path.join(process.cwd(), pth);
197
+ if (existsSync(fmtPath))
198
+ return;
199
+ mkdirSync(fmtPath);
210
200
  }
211
201
  function hasDep(PKG_PATH, dep) {
212
- const pkg = JSON.parse(
213
- existsSync(PKG_PATH) ? readFileSync(PKG_PATH).toString() : "{}",
214
- );
215
- if (existsSync(path.join(process.cwd(), "./node_modules/", dep))) return true;
216
- if (
217
- pkg.dependencies &&
218
- !Object.keys(pkg.dependencies).includes(dep) &&
219
- pkg.devDependencies &&
220
- !Object.keys(pkg.devDependencies).includes(dep) &&
221
- pkg.peerDependencies &&
222
- !Object.keys(pkg.peerDependencies).includes(dep)
223
- ) {
224
- return false;
225
- }
226
- return true;
202
+ const pkg = JSON.parse(existsSync(PKG_PATH) ? readFileSync(PKG_PATH).toString() : "{}");
203
+ if (existsSync(path.join(process.cwd(), "./node_modules/", dep)))
204
+ return true;
205
+ if (pkg.dependencies &&
206
+ !Object.keys(pkg.dependencies).includes(dep) &&
207
+ pkg.devDependencies &&
208
+ !Object.keys(pkg.devDependencies).includes(dep) &&
209
+ pkg.peerDependencies &&
210
+ !Object.keys(pkg.peerDependencies).includes(dep)) {
211
+ return false;
212
+ }
213
+ return true;
227
214
  }
package/bin/reporter.js CHANGED
@@ -1 +1 @@
1
- export function report() {}
1
+ export function report() { }