as-test 0.3.0 → 0.3.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.
- package/.github/workflows/as-test.yml +0 -3
- package/CHANGELOG.md +2 -0
- package/README.md +3 -8
- package/assembly/__tests__/mock.spec.ts +22 -0
- package/assembly/__tests__/mock.ts +7 -0
- package/assembly/index.ts +13 -19
- package/assets/img/screenshot.png +0 -0
- package/bin/build.js +77 -65
- package/bin/index.js +161 -131
- package/bin/init.js +110 -98
- package/bin/reporter.js +1 -1
- package/bin/run.js +236 -205
- package/bin/types.js +25 -25
- package/bin/util.js +42 -35
- package/cli/index.ts +1 -1
- package/cli/init.ts +2 -3
- package/cli/run.ts +1 -1
- package/package.json +1 -2
- package/run/package.json +1 -1
- package/tests/mock.run.js +14 -0
- package/transform/lib/index.js.map +1 -1
- package/transform/lib/mock.js +76 -7
- package/transform/lib/mock.js.map +1 -1
- package/transform/package.json +1 -1
- package/transform/src/mock.ts +92 -8
- package/assets/img/download.png +0 -0
- package/jest.test.js +0 -44
package/bin/init.js
CHANGED
|
@@ -5,24 +5,27 @@ 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
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
8
|
+
const rl = createInterface({
|
|
9
|
+
input: process.stdin,
|
|
10
|
+
output: process.stdout,
|
|
11
|
+
});
|
|
12
|
+
console.log(chalk.bold("as-test init v0.3.2") + "\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/
|
|
26
29
|
│ └── 📂 __tests__/
|
|
27
30
|
│ └── 🧪 example.spec.ts
|
|
28
31
|
├── 📂 build/
|
|
@@ -30,25 +33,27 @@ export async function init(args) {
|
|
|
30
33
|
├── 📂 tests/
|
|
31
34
|
│ └── 📃 as-test.run.js
|
|
32
35
|
├── ⚙️ as-test.config.json
|
|
33
|
-
└── ⚙️ package.json\n`)
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
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 {
|
|
52
57
|
describe,
|
|
53
58
|
expect,
|
|
54
59
|
test,
|
|
@@ -138,79 +143,86 @@ run();
|
|
|
138
143
|
function sleep(ms: i64): void {
|
|
139
144
|
const target = Date.now() + ms;
|
|
140
145
|
while (target > Date.now()) { }
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
+
}`,
|
|
147
|
+
);
|
|
148
|
+
writeDir("./build/");
|
|
149
|
+
writeDir("./logs/");
|
|
150
|
+
if (target == "bindings") {
|
|
151
|
+
writeFile(
|
|
152
|
+
"./tests/example.run.js",
|
|
153
|
+
`import { readFileSync } from "fs";
|
|
146
154
|
import { instantiate } from "../build/example.spec.js";
|
|
147
155
|
|
|
148
156
|
const binary = readFileSync("./build/example.spec.wasm");
|
|
149
157
|
const module = new WebAssembly.Module(binary);
|
|
150
158
|
|
|
151
|
-
const exports = instantiate(module, {})
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
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["test"]) process.exit(0);
|
|
178
|
+
if (!pkg.scripts["pretest"]) {
|
|
179
|
+
pkg.scripts["pretest"] = "as-test build";
|
|
180
|
+
pkg.scripts["test"] = "as-test run";
|
|
181
|
+
} else {
|
|
182
|
+
pkg.scripts["test"] = "as-test test";
|
|
183
|
+
}
|
|
184
|
+
if (!pkg["devDependencies"]) pkg["devDependencies"] = {};
|
|
185
|
+
if (!pkg["devDependencies"]["as-test"])
|
|
186
|
+
pkg["devDependencies"]["as-test"] = "^0.3.2";
|
|
187
|
+
if (target == "bindings") {
|
|
188
|
+
pkg["type"] = "module";
|
|
189
|
+
}
|
|
190
|
+
writeFileSync(PKG_PATH, JSON.stringify(pkg, null, 2));
|
|
191
|
+
process.exit(0);
|
|
181
192
|
}
|
|
182
193
|
function ask(question, face) {
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
});
|
|
194
|
+
return new Promise((res, _) => {
|
|
195
|
+
face.question(question, (answer) => {
|
|
196
|
+
res(answer);
|
|
187
197
|
});
|
|
198
|
+
});
|
|
188
199
|
}
|
|
189
200
|
function writeFile(pth, data) {
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
writeFileSync(fmtPath, data);
|
|
201
|
+
const fmtPath = path.join(process.cwd(), pth);
|
|
202
|
+
if (existsSync(fmtPath)) return;
|
|
203
|
+
if (!existsSync(path.dirname(fmtPath)))
|
|
204
|
+
mkdirSync(path.dirname(fmtPath), { recursive: true });
|
|
205
|
+
writeFileSync(fmtPath, data);
|
|
196
206
|
}
|
|
197
207
|
function writeDir(pth) {
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
mkdirSync(fmtPath);
|
|
208
|
+
const fmtPath = path.join(process.cwd(), pth);
|
|
209
|
+
if (existsSync(fmtPath)) return;
|
|
210
|
+
mkdirSync(fmtPath);
|
|
202
211
|
}
|
|
203
212
|
function hasDep(PKG_PATH, dep) {
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
213
|
+
const pkg = JSON.parse(
|
|
214
|
+
existsSync(PKG_PATH) ? readFileSync(PKG_PATH).toString() : "{}",
|
|
215
|
+
);
|
|
216
|
+
if (existsSync(path.join(process.cwd(), "./node_modules/", dep))) return true;
|
|
217
|
+
if (
|
|
218
|
+
pkg.dependencies &&
|
|
219
|
+
!Object.keys(pkg.dependencies).includes(dep) &&
|
|
220
|
+
pkg.devDependencies &&
|
|
221
|
+
!Object.keys(pkg.devDependencies).includes(dep) &&
|
|
222
|
+
pkg.peerDependencies &&
|
|
223
|
+
!Object.keys(pkg.peerDependencies).includes(dep)
|
|
224
|
+
) {
|
|
225
|
+
return false;
|
|
226
|
+
}
|
|
227
|
+
return true;
|
|
216
228
|
}
|
package/bin/reporter.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export function report() {
|
|
1
|
+
export function report() {}
|