as-test 0.5.1 → 0.5.3

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/bin/util.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { existsSync, readFileSync } from "fs";
2
- import { BuildOptions, Config, RunOptions, Runtime } from "./types.js";
2
+ import { BuildOptions, Config, CoverageOptions, ModeConfig, ReporterConfig, RunOptions, Runtime, } from "./types.js";
3
3
  import chalk from "chalk";
4
4
  import { delimiter, dirname, join } from "path";
5
5
  import { fileURLToPath } from "url";
@@ -35,9 +35,39 @@ export function loadConfig(CONFIG_PATH, warn = false) {
35
35
  else {
36
36
  const raw = JSON.parse(readFileSync(CONFIG_PATH).toString());
37
37
  const config = Object.assign(new Config(), raw);
38
+ config.env = parseEnvMap(raw.env);
38
39
  const runOptionsRaw = raw.runOptions ?? {};
39
40
  config.buildOptions = Object.assign(new BuildOptions(), raw.buildOptions ?? {});
41
+ config.buildOptions.cmd =
42
+ typeof config.buildOptions.cmd == "string" ? config.buildOptions.cmd : "";
43
+ config.buildOptions.args = Array.isArray(config.buildOptions.args)
44
+ ? config.buildOptions.args.filter((item) => typeof item == "string")
45
+ : [];
46
+ config.buildOptions.target =
47
+ typeof config.buildOptions.target == "string" && config.buildOptions.target.length
48
+ ? config.buildOptions.target
49
+ : "wasi";
40
50
  config.runOptions = Object.assign(new RunOptions(), runOptionsRaw);
51
+ const reporterRaw = runOptionsRaw.reporter;
52
+ if (typeof reporterRaw == "string") {
53
+ config.runOptions.reporter = reporterRaw;
54
+ }
55
+ else if (reporterRaw && typeof reporterRaw == "object") {
56
+ const reporterConfig = Object.assign(new ReporterConfig(), reporterRaw);
57
+ reporterConfig.name =
58
+ typeof reporterConfig.name == "string" ? reporterConfig.name : "";
59
+ reporterConfig.options = Array.isArray(reporterConfig.options)
60
+ ? reporterConfig.options.filter((value) => typeof value == "string")
61
+ : [];
62
+ reporterConfig.outDir =
63
+ typeof reporterConfig.outDir == "string" ? reporterConfig.outDir : "";
64
+ reporterConfig.outFile =
65
+ typeof reporterConfig.outFile == "string" ? reporterConfig.outFile : "";
66
+ config.runOptions.reporter = reporterConfig;
67
+ }
68
+ else {
69
+ config.runOptions.reporter = "";
70
+ }
41
71
  const runtimeRaw = runOptionsRaw.runtime;
42
72
  const runtime = new Runtime();
43
73
  const legacyRun = typeof runOptionsRaw.run == "string" && runOptionsRaw.run.length
@@ -54,9 +84,207 @@ export function loadConfig(CONFIG_PATH, warn = false) {
54
84
  : runtime.cmd;
55
85
  runtime.cmd = cmd;
56
86
  config.runOptions.runtime = runtime;
87
+ config.modes = parseModes(raw.modes);
57
88
  return config;
58
89
  }
59
90
  }
91
+ function parseModes(raw) {
92
+ if (!raw || typeof raw != "object" || Array.isArray(raw))
93
+ return {};
94
+ const out = {};
95
+ const entries = Object.entries(raw);
96
+ for (const [name, value] of entries) {
97
+ if (!value || typeof value != "object" || Array.isArray(value))
98
+ continue;
99
+ const modeRaw = value;
100
+ const mode = new ModeConfig();
101
+ if (typeof modeRaw.outDir == "string" && modeRaw.outDir.length) {
102
+ mode.outDir = modeRaw.outDir;
103
+ }
104
+ if (typeof modeRaw.logs == "string" && modeRaw.logs.length) {
105
+ mode.logs = modeRaw.logs;
106
+ }
107
+ if (typeof modeRaw.coverageDir == "string" &&
108
+ modeRaw.coverageDir.length) {
109
+ mode.coverageDir = modeRaw.coverageDir;
110
+ }
111
+ if (typeof modeRaw.snapshotDir == "string" &&
112
+ modeRaw.snapshotDir.length) {
113
+ mode.snapshotDir = modeRaw.snapshotDir;
114
+ }
115
+ if (typeof modeRaw.config == "string" && modeRaw.config.length) {
116
+ mode.config = modeRaw.config;
117
+ }
118
+ if (typeof modeRaw.coverage == "boolean") {
119
+ mode.coverage = modeRaw.coverage;
120
+ }
121
+ else if (modeRaw.coverage && typeof modeRaw.coverage == "object") {
122
+ mode.coverage = Object.assign(new CoverageOptions(), modeRaw.coverage);
123
+ }
124
+ if (modeRaw.buildOptions && typeof modeRaw.buildOptions == "object") {
125
+ const buildRaw = modeRaw.buildOptions;
126
+ const build = {};
127
+ if (typeof buildRaw.cmd == "string") {
128
+ build.cmd = buildRaw.cmd;
129
+ }
130
+ if (Array.isArray(buildRaw.args)) {
131
+ build.args = buildRaw.args.filter((item) => typeof item == "string");
132
+ }
133
+ if (typeof buildRaw.target == "string" && buildRaw.target.length) {
134
+ build.target = buildRaw.target;
135
+ }
136
+ mode.buildOptions = build;
137
+ }
138
+ if (modeRaw.runOptions && typeof modeRaw.runOptions == "object") {
139
+ const runRaw = modeRaw.runOptions;
140
+ const run = {};
141
+ if (runRaw.runtime && typeof runRaw.runtime == "object") {
142
+ const runtimeRaw = runRaw.runtime;
143
+ const runtime = new Runtime();
144
+ if (typeof runtimeRaw.cmd == "string" && runtimeRaw.cmd.length) {
145
+ runtime.cmd = runtimeRaw.cmd;
146
+ }
147
+ else if (typeof runtimeRaw.run == "string" &&
148
+ runtimeRaw.run.length) {
149
+ runtime.cmd = runtimeRaw.run;
150
+ }
151
+ else {
152
+ runtime.cmd = "";
153
+ }
154
+ run.runtime = runtime;
155
+ }
156
+ if (typeof runRaw.reporter == "string") {
157
+ run.reporter = runRaw.reporter;
158
+ }
159
+ else if (runRaw.reporter && typeof runRaw.reporter == "object") {
160
+ const reporter = Object.assign(new ReporterConfig(), runRaw.reporter);
161
+ reporter.name = typeof reporter.name == "string" ? reporter.name : "";
162
+ reporter.options = Array.isArray(reporter.options)
163
+ ? reporter.options.filter((item) => typeof item == "string")
164
+ : [];
165
+ reporter.outDir =
166
+ typeof reporter.outDir == "string" ? reporter.outDir : "";
167
+ reporter.outFile =
168
+ typeof reporter.outFile == "string" ? reporter.outFile : "";
169
+ run.reporter = reporter;
170
+ }
171
+ mode.runOptions = run;
172
+ }
173
+ if (modeRaw.env && typeof modeRaw.env == "object") {
174
+ const env = {};
175
+ for (const [key, val] of Object.entries(modeRaw.env)) {
176
+ if (typeof val == "string")
177
+ env[key] = val;
178
+ }
179
+ mode.env = env;
180
+ }
181
+ out[name] = mode;
182
+ }
183
+ return out;
184
+ }
185
+ function parseEnvMap(raw) {
186
+ if (!raw || typeof raw != "object" || Array.isArray(raw))
187
+ return {};
188
+ const env = {};
189
+ for (const [key, val] of Object.entries(raw)) {
190
+ if (typeof val == "string")
191
+ env[key] = val;
192
+ }
193
+ return env;
194
+ }
195
+ export function resolveModeNames(rawArgs) {
196
+ const names = [];
197
+ for (let i = 0; i < rawArgs.length; i++) {
198
+ const arg = rawArgs[i];
199
+ if (arg == "--mode") {
200
+ const next = rawArgs[i + 1];
201
+ if (!next || next.startsWith("-"))
202
+ continue;
203
+ i++;
204
+ appendModeTokens(names, next);
205
+ continue;
206
+ }
207
+ if (arg.startsWith("--mode=")) {
208
+ appendModeTokens(names, arg.slice("--mode=".length));
209
+ }
210
+ }
211
+ return [...new Set(names)];
212
+ }
213
+ function appendModeTokens(out, value) {
214
+ for (const token of value.split(",")) {
215
+ const mode = token.trim();
216
+ if (!mode.length)
217
+ continue;
218
+ out.push(mode);
219
+ }
220
+ }
221
+ export function applyMode(config, modeName) {
222
+ if (!modeName) {
223
+ return {
224
+ config,
225
+ env: {
226
+ ...process.env,
227
+ ...config.env,
228
+ },
229
+ };
230
+ }
231
+ const mode = config.modes[modeName];
232
+ if (!mode) {
233
+ const known = Object.keys(config.modes);
234
+ const available = known.length ? known.join(", ") : "(none)";
235
+ throw new Error(`unknown mode "${modeName}". Available modes: ${available}`);
236
+ }
237
+ const merged = Object.assign(new Config(), config);
238
+ merged.buildOptions = Object.assign(new BuildOptions(), config.buildOptions);
239
+ merged.runOptions = Object.assign(new RunOptions(), config.runOptions);
240
+ merged.runOptions.runtime = Object.assign(new Runtime(), config.runOptions.runtime);
241
+ if (mode.outDir)
242
+ merged.outDir = mode.outDir;
243
+ else
244
+ merged.outDir = appendPathSegment(config.outDir, modeName);
245
+ if (mode.logs)
246
+ merged.logs = mode.logs;
247
+ else if (config.logs != "none")
248
+ merged.logs = appendPathSegment(config.logs, modeName);
249
+ if (mode.coverageDir)
250
+ merged.coverageDir = mode.coverageDir;
251
+ else if (config.coverageDir != "none")
252
+ merged.coverageDir = appendPathSegment(config.coverageDir, modeName);
253
+ if (mode.snapshotDir)
254
+ merged.snapshotDir = mode.snapshotDir;
255
+ if (mode.config)
256
+ merged.config = mode.config;
257
+ if (mode.coverage != undefined)
258
+ merged.coverage = mode.coverage;
259
+ if (mode.buildOptions.target)
260
+ merged.buildOptions.target = mode.buildOptions.target;
261
+ if (mode.buildOptions.cmd != undefined)
262
+ merged.buildOptions.cmd = mode.buildOptions.cmd;
263
+ if (mode.buildOptions.args) {
264
+ merged.buildOptions.args = [
265
+ ...merged.buildOptions.args,
266
+ ...mode.buildOptions.args,
267
+ ];
268
+ }
269
+ if (mode.runOptions.runtime?.cmd) {
270
+ merged.runOptions.runtime.cmd = mode.runOptions.runtime.cmd;
271
+ }
272
+ if (mode.runOptions.reporter != undefined) {
273
+ merged.runOptions.reporter = mode.runOptions.reporter;
274
+ }
275
+ return {
276
+ config: merged,
277
+ env: {
278
+ ...process.env,
279
+ ...config.env,
280
+ ...mode.env,
281
+ },
282
+ modeName,
283
+ };
284
+ }
285
+ function appendPathSegment(basePath, segment) {
286
+ return join(basePath, segment);
287
+ }
60
288
  export function getCliVersion() {
61
289
  const candidates = [
62
290
  join(process.cwd(), "package.json"),
package/package.json CHANGED
@@ -1,19 +1,17 @@
1
1
  {
2
2
  "name": "as-test",
3
- "version": "0.5.1",
4
- "description": "Testing framework for AssemblyScript. Compatible with WASI or Bindings",
5
- "types": "assembly/index.ts",
3
+ "version": "0.5.3",
6
4
  "author": "Jairus Tanaka",
7
- "contributors": [],
8
- "license": "MIT",
9
- "scripts": {
10
- "test": "node ./bin/index.js test",
11
- "build:transform": "tsc -p ./transform",
12
- "build:cli": "tsc -p cli",
13
- "build:run": "tsc -p run",
14
- "prettier": "prettier -w .",
15
- "release:check": "npm run build:cli && npm run build:transform && npm run test && npm pack --dry-run --cache /tmp/as-test-npm-cache",
16
- "prepublishOnly": "npm run build:cli && npm run build:transform && npm run test"
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "git+https://github.com/JairusSW/as-test.git"
8
+ },
9
+ "dependencies": {
10
+ "as-console": "^7.0.0",
11
+ "as-rainbow": "^0.1.0",
12
+ "chalk": "^5.6.2",
13
+ "glob": "^13.0.3",
14
+ "typer-diff": "^1.1.1"
17
15
  },
18
16
  "devDependencies": {
19
17
  "@assemblyscript/wasi-shim": "^0.1.0",
@@ -23,46 +21,20 @@
23
21
  "as-test": "./",
24
22
  "assemblyscript": "^0.28.9",
25
23
  "assemblyscript-prettier": "^3.0.1",
26
- "json-as": "^1.2.5",
27
24
  "prettier": "3.6.2",
25
+ "try-as": "^0.2.5",
28
26
  "typescript": "^5.9.3",
29
27
  "typescript-eslint": "^8.55.0"
30
28
  },
31
- "dependencies": {
32
- "as-console": "^7.0.0",
33
- "as-rainbow": "^0.1.0",
34
- "as-variant": "^0.4.1",
35
- "chalk": "^5.6.2",
36
- "glob": "^13.0.3",
37
- "gradient-string": "^3.0.0",
38
- "typer-diff": "^1.1.1",
39
- "wipc-js": "^0.1.1"
40
- },
41
- "peerDependencies": {
42
- "json-as": "^1.2.5"
43
- },
44
- "optionalDependencies": {
45
- "try-as": "^0.2.5"
46
- },
47
- "repository": {
48
- "type": "git",
49
- "url": "git+https://github.com/JairusSW/as-test.git"
29
+ "bin": {
30
+ "as-test": "./bin/index.js",
31
+ "ast": "./bin/index.js"
50
32
  },
51
- "keywords": [
52
- "assemblyscript",
53
- "testing",
54
- "test",
55
- "as-pect",
56
- "aspect"
57
- ],
58
33
  "bugs": {
59
34
  "url": "https://github.com/JairusSW/as-test/issues"
60
35
  },
61
- "homepage": "https://github.com/JairusSW/as-test#readme",
62
- "type": "module",
63
- "publishConfig": {
64
- "@JairusSW:registry": "https://npm.pkg.github.com"
65
- },
36
+ "contributors": [],
37
+ "description": "Testing framework for AssemblyScript. Compatible with WASI or Bindings",
66
38
  "files": [
67
39
  "assembly/**/*.ts",
68
40
  "!assembly/__tests__/**",
@@ -70,7 +42,6 @@
70
42
  "bin/**/*.js",
71
43
  "templates/**/*.js",
72
44
  "transform/lib/**/*.js",
73
- "transform/lib/**/*.js.map",
74
45
  "transform/package.json",
75
46
  "CHANGELOG.md",
76
47
  "README.md",
@@ -78,8 +49,27 @@
78
49
  "as-test.config.schema.json",
79
50
  "index.ts"
80
51
  ],
81
- "bin": {
82
- "as-test": "./bin/index.js",
83
- "ast": "./bin/index.js"
84
- }
52
+ "homepage": "https://github.com/JairusSW/as-test#readme",
53
+ "keywords": [
54
+ "assemblyscript",
55
+ "testing",
56
+ "test",
57
+ "as-pect",
58
+ "aspect"
59
+ ],
60
+ "license": "MIT",
61
+ "publishConfig": {
62
+ "@JairusSW:registry": "https://npm.pkg.github.com"
63
+ },
64
+ "scripts": {
65
+ "test": "node ./bin/index.js test",
66
+ "build:transform": "tsc -p ./transform",
67
+ "build:cli": "tsc -p cli",
68
+ "build:run": "tsc -p run",
69
+ "prettier": "prettier -w .",
70
+ "release:check": "npm run build:cli && npm run build:transform && npm run test && npm pack --dry-run --cache /tmp/as-test-npm-cache",
71
+ "prepublishOnly": "npm run build:cli && npm run build:transform && npm run test"
72
+ },
73
+ "type": "module",
74
+ "types": "assembly/index.ts"
85
75
  }