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/run.js
CHANGED
|
@@ -7,225 +7,256 @@ import { existsSync, mkdirSync, writeFileSync } from "fs";
|
|
|
7
7
|
import { diff } from "typer-diff";
|
|
8
8
|
const CONFIG_PATH = path.join(process.cwd(), "./as-test.config.json");
|
|
9
9
|
export async function run() {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
10
|
+
const reports = [];
|
|
11
|
+
const config = loadConfig(CONFIG_PATH);
|
|
12
|
+
const inputFiles = await glob(config.input);
|
|
13
|
+
console.log(
|
|
14
|
+
chalk.dim("Running tests using " + config.runOptions.runtime.name + ""),
|
|
15
|
+
);
|
|
16
|
+
const command = config.runOptions.runtime.run.split(" ")[0];
|
|
17
|
+
let execPath = getExec(command);
|
|
18
|
+
if (!execPath) {
|
|
19
|
+
console.log(
|
|
20
|
+
`${chalk.bgRed(" ERROR ")}${chalk.dim(":")} could not locate ${command} in PATH variable!`,
|
|
21
|
+
);
|
|
22
|
+
process.exit(0);
|
|
23
|
+
}
|
|
24
|
+
if (inputFiles.length) {
|
|
25
|
+
console.log(
|
|
26
|
+
chalk.bold.blueBright(` _____ _____ _____ _____ _____ _____ `),
|
|
27
|
+
);
|
|
28
|
+
console.log(
|
|
29
|
+
chalk.bold.blueBright(`| _ || __| ___|_ _|| __|| __||_ _|`),
|
|
30
|
+
);
|
|
31
|
+
console.log(
|
|
32
|
+
chalk.bold.blueBright(`| ||__ ||___| | | | __||__ | | | `),
|
|
33
|
+
);
|
|
34
|
+
console.log(
|
|
35
|
+
chalk.bold.blueBright(`|__|__||_____| |_| |_____||_____| |_| `),
|
|
36
|
+
);
|
|
37
|
+
console.log(
|
|
38
|
+
chalk.dim("\n------------------- v0.3.2 -------------------\n"),
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
for (const plugin of Object.keys(config.plugins)) {
|
|
42
|
+
if (!config.plugins[plugin]) continue;
|
|
43
|
+
console.log(
|
|
44
|
+
chalk.bgBlueBright(" PLUGIN ") +
|
|
45
|
+
" " +
|
|
46
|
+
chalk.dim(
|
|
47
|
+
"Using " + plugin.slice(0, 1).toUpperCase() + plugin.slice(1),
|
|
48
|
+
) +
|
|
49
|
+
"\n",
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
for (let i = 0; i < inputFiles.length; i++) {
|
|
53
|
+
const file = inputFiles[i];
|
|
54
|
+
const outFile = path.join(
|
|
55
|
+
config.outDir,
|
|
56
|
+
file.slice(file.lastIndexOf("/") + 1).replace(".ts", ".wasm"),
|
|
57
|
+
);
|
|
58
|
+
let cmd = config.runOptions.runtime.run.replace(command, execPath);
|
|
59
|
+
if (config.buildOptions.target == "bindings") {
|
|
60
|
+
cmd = config.runOptions.runtime.run.replace(command, execPath);
|
|
61
|
+
if (cmd.includes("<name>")) {
|
|
62
|
+
cmd = cmd.replace(
|
|
63
|
+
"<name>",
|
|
64
|
+
file
|
|
65
|
+
.slice(file.lastIndexOf("/") + 1)
|
|
66
|
+
.replace(".ts", "")
|
|
67
|
+
.replace(".spec", ""),
|
|
68
|
+
);
|
|
69
|
+
} else {
|
|
70
|
+
cmd = cmd.replace(
|
|
71
|
+
"<file>",
|
|
72
|
+
outFile
|
|
73
|
+
.replace("build", "tests")
|
|
74
|
+
.replace(".spec", "")
|
|
75
|
+
.replace(".wasm", ".run.js"),
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
} else {
|
|
79
|
+
cmd = cmd.replace("<file>", outFile);
|
|
26
80
|
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
81
|
+
const report = JSON.parse(
|
|
82
|
+
await (() => {
|
|
83
|
+
return new Promise((res, _) => {
|
|
84
|
+
let stdout = "";
|
|
85
|
+
const io = exec(cmd);
|
|
86
|
+
io.stdout.pipe(process.stdout);
|
|
87
|
+
io.stderr.pipe(process.stderr);
|
|
88
|
+
io.stdout.on("data", (data) => {
|
|
89
|
+
stdout += readData(data);
|
|
90
|
+
});
|
|
91
|
+
io.stdout.on("close", () => {
|
|
92
|
+
res(stdout);
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
})(),
|
|
96
|
+
);
|
|
97
|
+
reports.push(report);
|
|
98
|
+
}
|
|
99
|
+
if (config.logs && config.logs != "none") {
|
|
100
|
+
if (!existsSync(path.join(process.cwd(), config.logs))) {
|
|
101
|
+
mkdirSync(path.join(process.cwd(), config.logs));
|
|
34
102
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
103
|
+
writeFileSync(
|
|
104
|
+
path.join(process.cwd(), config.logs, "test.log.json"),
|
|
105
|
+
JSON.stringify(reports, null, 2),
|
|
106
|
+
);
|
|
107
|
+
}
|
|
108
|
+
const reporter = new Reporter(reports);
|
|
109
|
+
if (reporter.failed.length) {
|
|
110
|
+
console.log(chalk.dim("----------------- [FAILED] -------------------\n"));
|
|
111
|
+
for (const failed of reporter.failed) {
|
|
112
|
+
console.log(
|
|
113
|
+
`${chalk.bgRed(" FAIL ")} ${chalk.dim(failed.description)}\n`,
|
|
114
|
+
);
|
|
115
|
+
for (const test of failed.tests) {
|
|
116
|
+
const diffResult = diff(
|
|
117
|
+
JSON.stringify(test._left),
|
|
118
|
+
JSON.stringify(test._right),
|
|
119
|
+
);
|
|
120
|
+
let expected = chalk.dim(JSON.stringify(test._left));
|
|
121
|
+
let received = "";
|
|
122
|
+
for (const res of diffResult.diff) {
|
|
123
|
+
switch (res.type) {
|
|
124
|
+
case "correct": {
|
|
125
|
+
received += chalk.dim(res.value);
|
|
126
|
+
continue;
|
|
46
127
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
.replace(".spec", "")
|
|
51
|
-
.replace(".wasm", ".run.js"));
|
|
128
|
+
case "extra": {
|
|
129
|
+
received += chalk.red.strikethrough(res.value);
|
|
130
|
+
continue;
|
|
52
131
|
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
stdout += readData(data);
|
|
65
|
-
});
|
|
66
|
-
io.stdout.on("close", () => {
|
|
67
|
-
res(stdout);
|
|
68
|
-
});
|
|
69
|
-
});
|
|
70
|
-
})());
|
|
71
|
-
reports.push(report);
|
|
72
|
-
}
|
|
73
|
-
if (config.logs && config.logs != "none") {
|
|
74
|
-
if (!existsSync(path.join(process.cwd(), config.logs))) {
|
|
75
|
-
mkdirSync(path.join(process.cwd(), config.logs));
|
|
76
|
-
}
|
|
77
|
-
writeFileSync(path.join(process.cwd(), config.logs, "test.log.json"), JSON.stringify(reports, null, 2));
|
|
78
|
-
}
|
|
79
|
-
const reporter = new Reporter(reports);
|
|
80
|
-
if (reporter.failed.length) {
|
|
81
|
-
console.log(chalk.dim("----------------- [FAILED] -------------------\n"));
|
|
82
|
-
for (const failed of reporter.failed) {
|
|
83
|
-
console.log(`${chalk.bgRed(" FAIL ")} ${chalk.dim(failed.description)}\n`);
|
|
84
|
-
for (const test of failed.tests) {
|
|
85
|
-
const diffResult = diff(JSON.stringify(test._left), JSON.stringify(test._right));
|
|
86
|
-
let expected = chalk.dim(JSON.stringify(test._left));
|
|
87
|
-
let received = "";
|
|
88
|
-
for (const res of diffResult.diff) {
|
|
89
|
-
switch (res.type) {
|
|
90
|
-
case "correct": {
|
|
91
|
-
received += chalk.dim(res.value);
|
|
92
|
-
continue;
|
|
93
|
-
}
|
|
94
|
-
case "extra": {
|
|
95
|
-
received += chalk.red.strikethrough(res.value);
|
|
96
|
-
continue;
|
|
97
|
-
}
|
|
98
|
-
case "missing": {
|
|
99
|
-
received += chalk.bgBlack(res.value);
|
|
100
|
-
continue;
|
|
101
|
-
}
|
|
102
|
-
case "wrong": {
|
|
103
|
-
received += chalk.bgRed(res.value);
|
|
104
|
-
continue;
|
|
105
|
-
}
|
|
106
|
-
case "untouched": {
|
|
107
|
-
//received += chalk.bgBlackBright(res.value);
|
|
108
|
-
continue;
|
|
109
|
-
}
|
|
110
|
-
case "spacer": {
|
|
111
|
-
//received += chalk.bgBlackBright(res.value);
|
|
112
|
-
continue;
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
if (test.verdict == "fail") {
|
|
117
|
-
console.log(`${chalk.dim("(expected) ->")} ${expected}`);
|
|
118
|
-
console.log(`${chalk.dim("(received) ->")} ${received}\n`);
|
|
119
|
-
}
|
|
132
|
+
case "missing": {
|
|
133
|
+
received += chalk.bgBlack(res.value);
|
|
134
|
+
continue;
|
|
135
|
+
}
|
|
136
|
+
case "wrong": {
|
|
137
|
+
received += chalk.bgRed(res.value);
|
|
138
|
+
continue;
|
|
139
|
+
}
|
|
140
|
+
case "untouched": {
|
|
141
|
+
//received += chalk.bgBlackBright(res.value);
|
|
142
|
+
continue;
|
|
120
143
|
}
|
|
144
|
+
case "spacer": {
|
|
145
|
+
//received += chalk.bgBlackBright(res.value);
|
|
146
|
+
continue;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
121
149
|
}
|
|
150
|
+
if (test.verdict == "fail") {
|
|
151
|
+
console.log(`${chalk.dim("(expected) ->")} ${expected}`);
|
|
152
|
+
console.log(`${chalk.dim("(received) ->")} ${received}\n`);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
122
155
|
}
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
process.stdout.write(
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
156
|
+
}
|
|
157
|
+
console.log(chalk.dim("----------------- [RESULTS] ------------------\n"));
|
|
158
|
+
process.stdout.write(chalk.bold("Files: "));
|
|
159
|
+
if (reporter.failedFiles) {
|
|
160
|
+
process.stdout.write(chalk.bold.red(reporter.failedFiles + " failed"));
|
|
161
|
+
} else {
|
|
162
|
+
process.stdout.write(chalk.bold.greenBright("0 failed"));
|
|
163
|
+
}
|
|
164
|
+
process.stdout.write(
|
|
165
|
+
", " + (reporter.failedFiles + reporter.passedFiles) + " total\n",
|
|
166
|
+
);
|
|
167
|
+
process.stdout.write(chalk.bold("Suites: "));
|
|
168
|
+
if (reporter.failedSuites) {
|
|
169
|
+
process.stdout.write(chalk.bold.red(reporter.failedSuites + " failed"));
|
|
170
|
+
} else {
|
|
171
|
+
process.stdout.write(chalk.bold.greenBright("0 failed"));
|
|
172
|
+
}
|
|
173
|
+
process.stdout.write(
|
|
174
|
+
", " + (reporter.failedSuites + reporter.passedSuites) + " total\n",
|
|
175
|
+
);
|
|
176
|
+
process.stdout.write(chalk.bold("Tests: "));
|
|
177
|
+
if (reporter.failedTests) {
|
|
178
|
+
process.stdout.write(chalk.bold.red(reporter.failedTests + " failed"));
|
|
179
|
+
} else {
|
|
180
|
+
process.stdout.write(chalk.bold.greenBright("0 failed"));
|
|
181
|
+
}
|
|
182
|
+
process.stdout.write(
|
|
183
|
+
", " + (reporter.failedTests + reporter.passedTests) + " total\n",
|
|
184
|
+
);
|
|
185
|
+
process.stdout.write(
|
|
186
|
+
chalk.bold("Time: ") + formatTime(reporter.time) + "\n",
|
|
187
|
+
);
|
|
188
|
+
if (reporter.failedFiles) process.exit(1);
|
|
189
|
+
process.exit(0);
|
|
152
190
|
}
|
|
153
191
|
class Reporter {
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
192
|
+
constructor(reports) {
|
|
193
|
+
this.passedFiles = 0;
|
|
194
|
+
this.failedFiles = 0;
|
|
195
|
+
this.passedSuites = 0;
|
|
196
|
+
this.failedSuites = 0;
|
|
197
|
+
this.passedTests = 0;
|
|
198
|
+
this.failedTests = 0;
|
|
199
|
+
this.failed = [];
|
|
200
|
+
this.time = 0.0;
|
|
201
|
+
this.readReports(reports);
|
|
202
|
+
}
|
|
203
|
+
readReports(reports) {
|
|
204
|
+
for (const file of reports) {
|
|
205
|
+
this.readFile(file);
|
|
164
206
|
}
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
207
|
+
}
|
|
208
|
+
readFile(file) {
|
|
209
|
+
let failed = false;
|
|
210
|
+
for (const suite of file) {
|
|
211
|
+
if (suite.verdict == "fail") {
|
|
212
|
+
failed = true;
|
|
213
|
+
this.failedSuites++;
|
|
214
|
+
} else {
|
|
215
|
+
this.passedSuites++;
|
|
216
|
+
}
|
|
217
|
+
this.time += suite.time.end - suite.time.start;
|
|
218
|
+
for (const subSuite of suite.suites) {
|
|
219
|
+
this.readSuite(subSuite);
|
|
220
|
+
}
|
|
221
|
+
for (const test of suite.tests) {
|
|
222
|
+
if (test.verdict == "fail") this.failed.push(suite);
|
|
223
|
+
this.readTest(test);
|
|
224
|
+
}
|
|
169
225
|
}
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
this.passedSuites++;
|
|
179
|
-
}
|
|
180
|
-
this.time += suite.time.end - suite.time.start;
|
|
181
|
-
for (const subSuite of suite.suites) {
|
|
182
|
-
this.readSuite(subSuite);
|
|
183
|
-
}
|
|
184
|
-
for (const test of suite.tests) {
|
|
185
|
-
if (test.verdict == "fail")
|
|
186
|
-
this.failed.push(suite);
|
|
187
|
-
this.readTest(test);
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
if (failed)
|
|
191
|
-
this.failedFiles++;
|
|
192
|
-
else
|
|
193
|
-
this.passedFiles++;
|
|
226
|
+
if (failed) this.failedFiles++;
|
|
227
|
+
else this.passedFiles++;
|
|
228
|
+
}
|
|
229
|
+
readSuite(suite) {
|
|
230
|
+
if (suite.verdict == "fail") {
|
|
231
|
+
this.failedSuites++;
|
|
232
|
+
} else {
|
|
233
|
+
this.passedSuites++;
|
|
194
234
|
}
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
}
|
|
199
|
-
else {
|
|
200
|
-
this.passedSuites++;
|
|
201
|
-
}
|
|
202
|
-
this.time += suite.time.end - suite.time.start;
|
|
203
|
-
for (const subSuite of suite.suites) {
|
|
204
|
-
this.readSuite(subSuite);
|
|
205
|
-
}
|
|
206
|
-
for (const test of suite.tests) {
|
|
207
|
-
if (test.verdict == "fail")
|
|
208
|
-
this.failed.push(suite);
|
|
209
|
-
this.readTest(test);
|
|
210
|
-
}
|
|
235
|
+
this.time += suite.time.end - suite.time.start;
|
|
236
|
+
for (const subSuite of suite.suites) {
|
|
237
|
+
this.readSuite(subSuite);
|
|
211
238
|
}
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
}
|
|
216
|
-
else {
|
|
217
|
-
this.passedTests++;
|
|
218
|
-
}
|
|
239
|
+
for (const test of suite.tests) {
|
|
240
|
+
if (test.verdict == "fail") this.failed.push(suite);
|
|
241
|
+
this.readTest(test);
|
|
219
242
|
}
|
|
243
|
+
}
|
|
244
|
+
readTest(test) {
|
|
245
|
+
if (test.verdict == "fail") {
|
|
246
|
+
this.failedTests++;
|
|
247
|
+
} else {
|
|
248
|
+
this.passedTests++;
|
|
249
|
+
}
|
|
250
|
+
}
|
|
220
251
|
}
|
|
221
252
|
function readData(data) {
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
253
|
+
let out = "";
|
|
254
|
+
const start = data.indexOf("READ_LINE");
|
|
255
|
+
if (start >= 0) {
|
|
256
|
+
const slice = data.slice(start + 9);
|
|
257
|
+
const end = slice.indexOf("END_LINE");
|
|
258
|
+
out += slice.slice(0, end);
|
|
259
|
+
out += readData(slice);
|
|
260
|
+
}
|
|
261
|
+
return out;
|
|
231
262
|
}
|
package/bin/types.js
CHANGED
|
@@ -1,35 +1,35 @@
|
|
|
1
1
|
export class Config {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
2
|
+
constructor() {
|
|
3
|
+
this.input = ["./assembly/__tests__/*.spec.ts"];
|
|
4
|
+
this.outDir = "./build";
|
|
5
|
+
this.logs = "./logs";
|
|
6
|
+
this.config = "none";
|
|
7
|
+
this.plugins = {
|
|
8
|
+
coverage: true,
|
|
9
|
+
};
|
|
10
|
+
this.buildOptions = new BuildOptions();
|
|
11
|
+
this.runOptions = new RunOptions();
|
|
12
|
+
}
|
|
13
13
|
}
|
|
14
14
|
export class Suite {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
constructor() {
|
|
16
|
+
this.name = "";
|
|
17
|
+
}
|
|
18
18
|
}
|
|
19
19
|
export class BuildOptions {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
20
|
+
constructor() {
|
|
21
|
+
this.args = [];
|
|
22
|
+
this.target = "wasi";
|
|
23
|
+
}
|
|
24
24
|
}
|
|
25
25
|
export class RunOptions {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
26
|
+
constructor() {
|
|
27
|
+
this.runtime = new Runtime();
|
|
28
|
+
}
|
|
29
29
|
}
|
|
30
30
|
export class Runtime {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
31
|
+
constructor() {
|
|
32
|
+
this.name = "wasmtime";
|
|
33
|
+
this.run = "wasmtime <file>";
|
|
34
|
+
}
|
|
35
35
|
}
|
package/bin/util.js
CHANGED
|
@@ -3,45 +3,52 @@ import { Config } from "./types.js";
|
|
|
3
3
|
import chalk from "chalk";
|
|
4
4
|
import { delimiter, join } from "path";
|
|
5
5
|
export function formatTime(ms) {
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
if (ms < 0) {
|
|
7
|
+
throw new Error("Time should be a non-negative number.");
|
|
8
|
+
}
|
|
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}`;
|
|
8
24
|
}
|
|
9
|
-
|
|
10
|
-
|
|
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`;
|
|
25
|
+
}
|
|
26
|
+
return `${us}us`;
|
|
27
27
|
}
|
|
28
28
|
export function loadConfig(CONFIG_PATH, warn = false) {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
29
|
+
if (!existsSync(CONFIG_PATH)) {
|
|
30
|
+
if (warn)
|
|
31
|
+
console.log(
|
|
32
|
+
`${chalk.bgMagentaBright(" WARN ")}${chalk.dim(":")} Could not locate config file in the current directory! Continuing with default config.`,
|
|
33
|
+
);
|
|
34
|
+
return new Config();
|
|
35
|
+
} else {
|
|
36
|
+
return Object.assign(
|
|
37
|
+
new Config(),
|
|
38
|
+
JSON.parse(readFileSync(CONFIG_PATH).toString()),
|
|
39
|
+
);
|
|
40
|
+
}
|
|
37
41
|
}
|
|
38
42
|
export function getExec(exec) {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
43
|
+
const PATH = process.env.PATH.split(delimiter);
|
|
44
|
+
for (const pathDir of PATH) {
|
|
45
|
+
const fullPath = join(
|
|
46
|
+
pathDir,
|
|
47
|
+
exec + (process.platform === "win32" ? ".exe" : ""),
|
|
48
|
+
);
|
|
49
|
+
if (existsSync(fullPath)) {
|
|
50
|
+
return fullPath;
|
|
45
51
|
}
|
|
46
|
-
|
|
52
|
+
}
|
|
53
|
+
return null;
|
|
47
54
|
}
|
package/cli/index.ts
CHANGED
package/cli/init.ts
CHANGED
|
@@ -9,7 +9,7 @@ export async function init(args: string[]) {
|
|
|
9
9
|
input: process.stdin,
|
|
10
10
|
output: process.stdout,
|
|
11
11
|
});
|
|
12
|
-
console.log(chalk.bold("as-test init v0.3.
|
|
12
|
+
console.log(chalk.bold("as-test init v0.3.2") + "\n");
|
|
13
13
|
console.log(chalk.dim("[1/3]") + " select a target [wasi/bindings]");
|
|
14
14
|
const target = await ask(chalk.dim(" -> "), rl);
|
|
15
15
|
if (!TARGETS.includes(target)) {
|
|
@@ -184,7 +184,6 @@ const exports = instantiate(module, {});`,
|
|
|
184
184
|
existsSync(PKG_PATH) ? readFileSync(PKG_PATH).toString() : "{}",
|
|
185
185
|
);
|
|
186
186
|
if (!pkg["scripts"]) pkg["scripts"] = {};
|
|
187
|
-
if (pkg.scripts["test"]) process.exit(0);
|
|
188
187
|
if (!pkg.scripts["pretest"]) {
|
|
189
188
|
pkg.scripts["pretest"] = "as-test build";
|
|
190
189
|
pkg.scripts["test"] = "as-test run";
|
|
@@ -193,7 +192,7 @@ const exports = instantiate(module, {});`,
|
|
|
193
192
|
}
|
|
194
193
|
if (!pkg["devDependencies"]) pkg["devDependencies"] = {};
|
|
195
194
|
if (!pkg["devDependencies"]["as-test"])
|
|
196
|
-
pkg["devDependencies"]["as-test"] = "^0.3.
|
|
195
|
+
pkg["devDependencies"]["as-test"] = "^0.3.2";
|
|
197
196
|
if (target == "bindings") {
|
|
198
197
|
pkg["type"] = "module";
|
|
199
198
|
}
|
package/cli/run.ts
CHANGED
|
@@ -42,7 +42,7 @@ export async function run() {
|
|
|
42
42
|
chalk.bold.blueBright(`|__|__||_____| |_| |_____||_____| |_| `),
|
|
43
43
|
);
|
|
44
44
|
console.log(
|
|
45
|
-
chalk.dim("\n------------------- v0.3.
|
|
45
|
+
chalk.dim("\n------------------- v0.3.2 -------------------\n"),
|
|
46
46
|
);
|
|
47
47
|
}
|
|
48
48
|
|