as-test 0.1.10 → 0.2.0

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 CHANGED
@@ -19,5 +19,5 @@ v0.1.7 - Fix: remove warning about wasi-shim not being included when it is inclu
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
21
  v0.1.10 - Feat: support node, deno, and bun
22
-
22
+ v0.2.0 - Fix mock -> mockFn artifacts
23
23
  [UNRELEASED] - Feat: snapshotting
package/README.md CHANGED
@@ -3,17 +3,19 @@
3
3
  | _ || __| ___|_ _|| __|| __||_ _|
4
4
  | ||__ ||___| | | | __||__ | | |
5
5
  |__|__||_____| |_| |_____||_____| |_|
6
- v0.1.10
6
+ v0.2.0
7
7
  </pre>
8
8
  </h5>
9
9
 
10
10
  ## Installation
11
11
 
12
- ```bash
13
- npm install as-test
14
- ```
12
+ To get started, install the package from NPM or GitHub
13
+
14
+ `npm i as-test --save-dev`
15
+
16
+ You'll also need to install `visitor-as`
15
17
 
16
- Note: The transform _is_ OPTIONAL, though it is required to enable code coverage.
18
+ `npm i visitor-as --save-dev`
17
19
 
18
20
  ## Templates
19
21
 
package/assembly/index.ts CHANGED
@@ -240,7 +240,7 @@ export function run(options: RunOptions = new RunOptions()): void {
240
240
  ),
241
241
  );
242
242
  console.log(
243
- rainbow.dimMk("\n------------------- v0.1.10 -------------------\n"),
243
+ rainbow.dimMk("\n------------------- v0.2.0 -------------------\n"),
244
244
  );
245
245
  // @ts-ignore
246
246
  if (isDefined(COVERAGE_USE)) {
package/bin/index.js CHANGED
@@ -7,7 +7,7 @@ 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";
10
+ const version = "0.2.0";
11
11
  for (const arg of _args) {
12
12
  if (arg.startsWith("-")) flags.push(arg);
13
13
  else args.push(arg);
package/cli/index.ts CHANGED
@@ -11,7 +11,7 @@ const args: string[] = [];
11
11
 
12
12
  const COMMANDS: string[] = ["run", "build", "test", "init"];
13
13
 
14
- const version = "0.1.10";
14
+ const version = "0.2.0";
15
15
 
16
16
  for (const arg of _args) {
17
17
  if (arg.startsWith("-")) flags.push(arg);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "as-test",
3
- "version": "0.1.10",
3
+ "version": "0.2.0",
4
4
  "description": "Testing framework for AssemblyScript. Compatible with WASI or Bindings ",
5
5
  "types": "assembly/index.ts",
6
6
  "author": "Jairus Tanaka",
@@ -1,47 +1,44 @@
1
- import {
2
- BlockStatement,
3
- ExpressionStatement,
4
- Node,
5
- } from "assemblyscript/dist/assemblyscript.js";
1
+ import { BlockStatement, ExpressionStatement, Node, } from "assemblyscript/dist/assemblyscript.js";
6
2
  import { BaseVisitor, SimpleParser } from "visitor-as/dist/index.js";
7
3
  import { RangeTransform } from "visitor-as/dist/transformRange.js";
8
4
  import { isStdlib } from "visitor-as/dist/utils.js";
9
5
  var CoverType;
10
6
  (function (CoverType) {
11
- CoverType[(CoverType["Function"] = 0)] = "Function";
12
- CoverType[(CoverType["Expression"] = 1)] = "Expression";
13
- CoverType[(CoverType["Block"] = 2)] = "Block";
7
+ CoverType[CoverType["Function"] = 0] = "Function";
8
+ CoverType[CoverType["Expression"] = 1] = "Expression";
9
+ CoverType[CoverType["Block"] = 2] = "Block";
14
10
  })(CoverType || (CoverType = {}));
15
11
  class CoverPoint {
16
- file = "";
17
- hash = "";
18
- line = 0;
19
- column = 0;
20
- type;
21
- executed = false;
12
+ file = "";
13
+ hash = "";
14
+ line = 0;
15
+ column = 0;
16
+ type;
17
+ executed = false;
22
18
  }
23
19
  export class CoverageTransform extends BaseVisitor {
24
- mustImport = false;
25
- points = new Map();
26
- globalStatements = [];
27
- visitBinaryExpression(node) {
28
- super.visitBinaryExpression(node);
29
- if (node.visited) return;
30
- node.visited = true;
31
- const path = node.range.source.normalizedPath;
32
- switch (node.operator) {
33
- case 98:
34
- case 97: {
35
- const right = node.right;
36
- const rightLc = getLineCol(node);
37
- const point = new CoverPoint();
38
- point.line = rightLc?.line;
39
- point.column = rightLc?.column;
40
- point.file = path;
41
- point.type = CoverType.Expression;
42
- point.hash = hash(point);
43
- const replacer = new RangeTransform(node);
44
- const registerStmt = SimpleParser.parseTopLevelStatement(`__REGISTER({
20
+ mustImport = false;
21
+ points = new Map();
22
+ globalStatements = [];
23
+ visitBinaryExpression(node) {
24
+ super.visitBinaryExpression(node);
25
+ if (node.visited)
26
+ return;
27
+ node.visited = true;
28
+ const path = node.range.source.normalizedPath;
29
+ switch (node.operator) {
30
+ case 98:
31
+ case 97: {
32
+ const right = node.right;
33
+ const rightLc = getLineCol(node);
34
+ const point = new CoverPoint();
35
+ point.line = rightLc?.line;
36
+ point.column = rightLc?.column;
37
+ point.file = path;
38
+ point.type = CoverType.Expression;
39
+ point.hash = hash(point);
40
+ const replacer = new RangeTransform(node);
41
+ const registerStmt = SimpleParser.parseTopLevelStatement(`__REGISTER({
45
42
  file: "${point.file}",
46
43
  hash: "${point.hash}",
47
44
  line: ${point.line},
@@ -49,35 +46,35 @@ export class CoverageTransform extends BaseVisitor {
49
46
  type: "Expression",
50
47
  executed: false
51
48
  });`);
52
- replacer.visit(registerStmt);
53
- let coverExpression = SimpleParser.parseExpression(
54
- `(__COVER("${point.hash}"), $$REPLACE_ME)`,
55
- );
56
- replacer.visit(coverExpression);
57
- coverExpression.expression.expressions[1] = right;
58
- node.right = coverExpression;
59
- this.globalStatements.push(registerStmt);
60
- break;
61
- }
49
+ replacer.visit(registerStmt);
50
+ let coverExpression = SimpleParser.parseExpression(`(__COVER("${point.hash}"), $$REPLACE_ME)`);
51
+ replacer.visit(coverExpression);
52
+ coverExpression.expression.expressions[1] = right;
53
+ node.right = coverExpression;
54
+ this.globalStatements.push(registerStmt);
55
+ break;
56
+ }
57
+ }
62
58
  }
63
- }
64
- visitMethodDeclaration(node) {
65
- super.visitMethodDeclaration(node);
66
- if (node.visited) return;
67
- node.visited = true;
68
- if (node.body) {
69
- if (node.body.visited) return;
70
- node.body.visited = true;
71
- const path = node.range.source.normalizedPath;
72
- const funcLc = getLineCol(node);
73
- const point = new CoverPoint();
74
- point.line = funcLc?.line;
75
- point.column = funcLc?.column;
76
- point.file = path;
77
- point.type = CoverType.Function;
78
- point.hash = hash(point);
79
- const replacer = new RangeTransform(node);
80
- const registerStmt = SimpleParser.parseTopLevelStatement(`__REGISTER({
59
+ visitMethodDeclaration(node) {
60
+ super.visitMethodDeclaration(node);
61
+ if (node.visited)
62
+ return;
63
+ node.visited = true;
64
+ if (node.body) {
65
+ if (node.body.visited)
66
+ return;
67
+ node.body.visited = true;
68
+ const path = node.range.source.normalizedPath;
69
+ const funcLc = getLineCol(node);
70
+ const point = new CoverPoint();
71
+ point.line = funcLc?.line;
72
+ point.column = funcLc?.column;
73
+ point.file = path;
74
+ point.type = CoverType.Function;
75
+ point.hash = hash(point);
76
+ const replacer = new RangeTransform(node);
77
+ const registerStmt = SimpleParser.parseTopLevelStatement(`__REGISTER({
81
78
  file: "${point.file}",
82
79
  hash: "${point.hash}",
83
80
  line: ${point.line},
@@ -85,34 +82,33 @@ export class CoverageTransform extends BaseVisitor {
85
82
  type: "Function",
86
83
  executed: false
87
84
  })`);
88
- replacer.visit(registerStmt);
89
- const coverStmt = SimpleParser.parseStatement(
90
- `__COVER("${point.hash}")`,
91
- true,
92
- );
93
- replacer.visit(coverStmt);
94
- const bodyBlock = node.body;
95
- bodyBlock.statements.unshift(coverStmt);
96
- this.globalStatements.push(registerStmt);
85
+ replacer.visit(registerStmt);
86
+ const coverStmt = SimpleParser.parseStatement(`__COVER("${point.hash}")`, true);
87
+ replacer.visit(coverStmt);
88
+ const bodyBlock = node.body;
89
+ bodyBlock.statements.unshift(coverStmt);
90
+ this.globalStatements.push(registerStmt);
91
+ }
97
92
  }
98
- }
99
- visitParameter(node) {
100
- if (node.visited) return;
101
- node.visited = true;
102
- const path = node.range.source.normalizedPath;
103
- if (node.initializer) {
104
- if (node.initializer.visited) return;
105
- node.initializer.visited = true;
106
- super.visitParameter(node);
107
- const paramLc = getLineCol(node.initializer);
108
- const point = new CoverPoint();
109
- point.line = paramLc?.line;
110
- point.column = paramLc?.column;
111
- point.file = path;
112
- point.type = CoverType.Expression;
113
- point.hash = hash(point);
114
- const replacer = new RangeTransform(node);
115
- const registerStmt = SimpleParser.parseTopLevelStatement(`__REGISTER({
93
+ visitParameter(node) {
94
+ if (node.visited)
95
+ return;
96
+ node.visited = true;
97
+ const path = node.range.source.normalizedPath;
98
+ if (node.initializer) {
99
+ if (node.initializer.visited)
100
+ return;
101
+ node.initializer.visited = true;
102
+ super.visitParameter(node);
103
+ const paramLc = getLineCol(node.initializer);
104
+ const point = new CoverPoint();
105
+ point.line = paramLc?.line;
106
+ point.column = paramLc?.column;
107
+ point.file = path;
108
+ point.type = CoverType.Expression;
109
+ point.hash = hash(point);
110
+ const replacer = new RangeTransform(node);
111
+ const registerStmt = SimpleParser.parseTopLevelStatement(`__REGISTER({
116
112
  file: "${point.file}",
117
113
  hash: "${point.hash}",
118
114
  line: ${point.line},
@@ -120,33 +116,34 @@ export class CoverageTransform extends BaseVisitor {
120
116
  type: "Expression",
121
117
  executed: false
122
118
  })`);
123
- replacer.visit(registerStmt);
124
- const coverExpression = SimpleParser.parseExpression(
125
- `(__COVER("${point.hash}"), $$REPLACE_ME)`,
126
- );
127
- replacer.visit(coverExpression);
128
- coverExpression.expression.expressions[1] = node.initializer;
129
- node.initializer = coverExpression;
130
- this.globalStatements.push(registerStmt);
119
+ replacer.visit(registerStmt);
120
+ const coverExpression = SimpleParser.parseExpression(`(__COVER("${point.hash}"), $$REPLACE_ME)`);
121
+ replacer.visit(coverExpression);
122
+ coverExpression.expression.expressions[1] =
123
+ node.initializer;
124
+ node.initializer = coverExpression;
125
+ this.globalStatements.push(registerStmt);
126
+ }
131
127
  }
132
- }
133
- visitFunctionDeclaration(node, isDefault) {
134
- super.visitFunctionDeclaration(node, isDefault);
135
- if (node.visited) return;
136
- node.visited = true;
137
- if (node.body) {
138
- if (node.body.visited) return;
139
- node.body.visited = true;
140
- const path = node.range.source.normalizedPath;
141
- const funcLc = getLineCol(node);
142
- const point = new CoverPoint();
143
- point.line = funcLc?.line;
144
- point.column = funcLc?.column;
145
- point.file = path;
146
- point.type = CoverType.Function;
147
- point.hash = hash(point);
148
- const replacer = new RangeTransform(node);
149
- const registerStmt = SimpleParser.parseTopLevelStatement(`__REGISTER({
128
+ visitFunctionDeclaration(node, isDefault) {
129
+ super.visitFunctionDeclaration(node, isDefault);
130
+ if (node.visited)
131
+ return;
132
+ node.visited = true;
133
+ if (node.body) {
134
+ if (node.body.visited)
135
+ return;
136
+ node.body.visited = true;
137
+ const path = node.range.source.normalizedPath;
138
+ const funcLc = getLineCol(node);
139
+ const point = new CoverPoint();
140
+ point.line = funcLc?.line;
141
+ point.column = funcLc?.column;
142
+ point.file = path;
143
+ point.type = CoverType.Function;
144
+ point.hash = hash(point);
145
+ const replacer = new RangeTransform(node);
146
+ const registerStmt = SimpleParser.parseTopLevelStatement(`__REGISTER({
150
147
  file: "${point.file}",
151
148
  hash: "${point.hash}",
152
149
  line: ${point.line},
@@ -154,57 +151,54 @@ export class CoverageTransform extends BaseVisitor {
154
151
  type: "Function",
155
152
  executed: false
156
153
  })`);
157
- replacer.visit(registerStmt);
158
- this.globalStatements.push(registerStmt);
159
- if (node.body.kind === 35) {
160
- const coverStmt = SimpleParser.parseStatement(`{
154
+ replacer.visit(registerStmt);
155
+ this.globalStatements.push(registerStmt);
156
+ if (node.body.kind === 35) {
157
+ const coverStmt = SimpleParser.parseStatement(`{
161
158
  __COVER("${point.hash}")
162
159
  return $$REPLACE_ME
163
160
  }`);
164
- replacer.visit(coverStmt);
165
- const bodyReturn = coverStmt.statements[1];
166
- const body = node.body;
167
- node.arrowKind = 2;
168
- bodyReturn.value = body.expression;
169
- node.body = body;
170
- } else {
171
- const coverStmt = SimpleParser.parseStatement(
172
- `__COVER("${point.hash}")`,
173
- true,
174
- );
175
- replacer.visit(coverStmt);
176
- if (node.body instanceof BlockStatement) {
177
- node.body.statements.unshift(coverStmt);
178
- } else if (node.body instanceof ExpressionStatement) {
179
- const expression = node.body.expression;
180
- node.body = Node.createBlockStatement(
181
- [Node.createReturnStatement(expression, expression.range)],
182
- expression.range,
183
- );
184
- const bodyBlock = node.body;
185
- bodyBlock.statements.unshift(coverStmt);
161
+ replacer.visit(coverStmt);
162
+ const bodyReturn = coverStmt.statements[1];
163
+ const body = node.body;
164
+ node.arrowKind = 2;
165
+ bodyReturn.value = body.expression;
166
+ node.body = body;
167
+ }
168
+ else {
169
+ const coverStmt = SimpleParser.parseStatement(`__COVER("${point.hash}")`, true);
170
+ replacer.visit(coverStmt);
171
+ if (node.body instanceof BlockStatement) {
172
+ node.body.statements.unshift(coverStmt);
173
+ }
174
+ else if (node.body instanceof ExpressionStatement) {
175
+ const expression = node.body.expression;
176
+ node.body = Node.createBlockStatement([Node.createReturnStatement(expression, expression.range)], expression.range);
177
+ const bodyBlock = node.body;
178
+ bodyBlock.statements.unshift(coverStmt);
179
+ }
180
+ }
186
181
  }
187
- }
188
182
  }
189
- }
190
- visitIfStatement(node) {
191
- if (node.visited) return;
192
- node.visited = true;
193
- let visitIfTrue = false;
194
- let visitIfFalse = false;
195
- const ifTrue = node.ifTrue;
196
- const ifFalse = node.ifFalse;
197
- const path = node.range.source.normalizedPath;
198
- if (ifTrue.kind !== 30) {
199
- const trueLc = getLineCol(ifTrue);
200
- const point = new CoverPoint();
201
- point.line = trueLc?.line;
202
- point.column = trueLc?.column;
203
- point.file = path;
204
- point.type = CoverType.Expression;
205
- point.hash = hash(point);
206
- const replacer = new RangeTransform(ifTrue);
207
- const registerStmt = SimpleParser.parseTopLevelStatement(`__REGISTER({
183
+ visitIfStatement(node) {
184
+ if (node.visited)
185
+ return;
186
+ node.visited = true;
187
+ let visitIfTrue = false;
188
+ let visitIfFalse = false;
189
+ const ifTrue = node.ifTrue;
190
+ const ifFalse = node.ifFalse;
191
+ const path = node.range.source.normalizedPath;
192
+ if (ifTrue.kind !== 30) {
193
+ const trueLc = getLineCol(ifTrue);
194
+ const point = new CoverPoint();
195
+ point.line = trueLc?.line;
196
+ point.column = trueLc?.column;
197
+ point.file = path;
198
+ point.type = CoverType.Expression;
199
+ point.hash = hash(point);
200
+ const replacer = new RangeTransform(ifTrue);
201
+ const registerStmt = SimpleParser.parseTopLevelStatement(`__REGISTER({
208
202
  file: "${point.file}",
209
203
  hash: "${point.hash}",
210
204
  line: ${point.line},
@@ -212,28 +206,25 @@ export class CoverageTransform extends BaseVisitor {
212
206
  type: "Expression",
213
207
  executed: false
214
208
  })`);
215
- replacer.visit(registerStmt);
216
- const coverStmt = SimpleParser.parseStatement(
217
- `{__COVER("${point.hash}")};`,
218
- true,
219
- );
220
- replacer.visit(coverStmt);
221
- coverStmt.statements.push(ifTrue);
222
- node.ifTrue = coverStmt;
223
- this.globalStatements.push(registerStmt);
224
- visitIfTrue = true;
225
- visitIfFalse = !!ifFalse;
226
- }
227
- if (ifFalse && ifFalse.kind !== 30) {
228
- const falseLc = getLineCol(ifFalse);
229
- const point = new CoverPoint();
230
- point.line = falseLc?.line;
231
- point.column = falseLc?.column;
232
- point.file = path;
233
- point.type = CoverType.Expression;
234
- point.hash = hash(point);
235
- const replacer = new RangeTransform(ifTrue);
236
- const registerStmt = SimpleParser.parseTopLevelStatement(`__REGISTER({
209
+ replacer.visit(registerStmt);
210
+ const coverStmt = SimpleParser.parseStatement(`{__COVER("${point.hash}")};`, true);
211
+ replacer.visit(coverStmt);
212
+ coverStmt.statements.push(ifTrue);
213
+ node.ifTrue = coverStmt;
214
+ this.globalStatements.push(registerStmt);
215
+ visitIfTrue = true;
216
+ visitIfFalse = !!ifFalse;
217
+ }
218
+ if (ifFalse && ifFalse.kind !== 30) {
219
+ const falseLc = getLineCol(ifFalse);
220
+ const point = new CoverPoint();
221
+ point.line = falseLc?.line;
222
+ point.column = falseLc?.column;
223
+ point.file = path;
224
+ point.type = CoverType.Expression;
225
+ point.hash = hash(point);
226
+ const replacer = new RangeTransform(ifTrue);
227
+ const registerStmt = SimpleParser.parseTopLevelStatement(`__REGISTER({
237
228
  file: "${point.file}",
238
229
  hash: "${point.hash}",
239
230
  line: ${point.line},
@@ -241,50 +232,51 @@ export class CoverageTransform extends BaseVisitor {
241
232
  type: "Expression",
242
233
  executed: false
243
234
  })`);
244
- replacer.visit(registerStmt);
245
- const coverStmt = SimpleParser.parseStatement(
246
- `{__COVER("${point.hash}")};`,
247
- true,
248
- );
249
- replacer.visit(coverStmt);
250
- coverStmt.statements.push(ifFalse);
251
- node.ifFalse = coverStmt;
252
- this.globalStatements.push(registerStmt);
253
- visitIfTrue = true;
254
- visitIfFalse = true;
255
- }
256
- if (visitIfTrue || visitIfFalse) {
257
- if (visitIfTrue) {
258
- if (ifTrue.visited) return;
259
- ifTrue.visited = true;
260
- this._visit(ifTrue);
261
- }
262
- if (visitIfFalse) {
263
- if (ifFalse.visited) return;
264
- ifFalse.visited = true;
265
- this._visit(ifFalse);
266
- }
267
- } else {
268
- super.visitIfStatement(node);
235
+ replacer.visit(registerStmt);
236
+ const coverStmt = SimpleParser.parseStatement(`{__COVER("${point.hash}")};`, true);
237
+ replacer.visit(coverStmt);
238
+ coverStmt.statements.push(ifFalse);
239
+ node.ifFalse = coverStmt;
240
+ this.globalStatements.push(registerStmt);
241
+ visitIfTrue = true;
242
+ visitIfFalse = true;
243
+ }
244
+ if (visitIfTrue || visitIfFalse) {
245
+ if (visitIfTrue) {
246
+ if (ifTrue.visited)
247
+ return;
248
+ ifTrue.visited = true;
249
+ this._visit(ifTrue);
250
+ }
251
+ if (visitIfFalse) {
252
+ if (ifFalse.visited)
253
+ return;
254
+ ifFalse.visited = true;
255
+ this._visit(ifFalse);
256
+ }
257
+ }
258
+ else {
259
+ super.visitIfStatement(node);
260
+ }
269
261
  }
270
- }
271
- visitTernaryExpression(node) {
272
- if (node.visited) return;
273
- node.visited = true;
274
- super.visitTernaryExpression(node);
275
- const trueExpression = node.ifThen;
276
- const falseExpression = node.ifElse;
277
- const path = node.range.source.normalizedPath;
278
- {
279
- const trueLc = getLineCol(trueExpression);
280
- const point = new CoverPoint();
281
- point.line = trueLc?.line;
282
- point.column = trueLc?.column;
283
- point.file = path;
284
- point.type = CoverType.Expression;
285
- point.hash = hash(point);
286
- const replacer = new RangeTransform(trueExpression);
287
- const registerStmt = SimpleParser.parseTopLevelStatement(`__REGISTER({
262
+ visitTernaryExpression(node) {
263
+ if (node.visited)
264
+ return;
265
+ node.visited = true;
266
+ super.visitTernaryExpression(node);
267
+ const trueExpression = node.ifThen;
268
+ const falseExpression = node.ifElse;
269
+ const path = node.range.source.normalizedPath;
270
+ {
271
+ const trueLc = getLineCol(trueExpression);
272
+ const point = new CoverPoint();
273
+ point.line = trueLc?.line;
274
+ point.column = trueLc?.column;
275
+ point.file = path;
276
+ point.type = CoverType.Expression;
277
+ point.hash = hash(point);
278
+ const replacer = new RangeTransform(trueExpression);
279
+ const registerStmt = SimpleParser.parseTopLevelStatement(`__REGISTER({
288
280
  file: "${point.file}",
289
281
  hash: "${point.hash}",
290
282
  line: ${point.line},
@@ -292,25 +284,24 @@ export class CoverageTransform extends BaseVisitor {
292
284
  type: "Expression",
293
285
  executed: false
294
286
  })`);
295
- replacer.visit(registerStmt);
296
- const coverExpression = SimpleParser.parseExpression(
297
- `(__COVER("${point.hash}"), $$REPLACE_ME)`,
298
- );
299
- replacer.visit(coverExpression);
300
- coverExpression.expression.expressions[1] = trueExpression;
301
- node.ifThen = coverExpression;
302
- this.globalStatements.push(registerStmt);
303
- }
304
- {
305
- const falseLc = getLineCol(falseExpression);
306
- const point = new CoverPoint();
307
- point.line = falseLc?.line;
308
- point.column = falseLc?.column;
309
- point.file = path;
310
- point.type = CoverType.Expression;
311
- point.hash = hash(point);
312
- const replacer = new RangeTransform(falseExpression);
313
- const registerStmt = SimpleParser.parseTopLevelStatement(`__REGISTER({
287
+ replacer.visit(registerStmt);
288
+ const coverExpression = SimpleParser.parseExpression(`(__COVER("${point.hash}"), $$REPLACE_ME)`);
289
+ replacer.visit(coverExpression);
290
+ coverExpression.expression.expressions[1] =
291
+ trueExpression;
292
+ node.ifThen = coverExpression;
293
+ this.globalStatements.push(registerStmt);
294
+ }
295
+ {
296
+ const falseLc = getLineCol(falseExpression);
297
+ const point = new CoverPoint();
298
+ point.line = falseLc?.line;
299
+ point.column = falseLc?.column;
300
+ point.file = path;
301
+ point.type = CoverType.Expression;
302
+ point.hash = hash(point);
303
+ const replacer = new RangeTransform(falseExpression);
304
+ const registerStmt = SimpleParser.parseTopLevelStatement(`__REGISTER({
314
305
  file: "${point.file}",
315
306
  hash: "${point.hash}",
316
307
  line: ${point.line},
@@ -318,29 +309,29 @@ export class CoverageTransform extends BaseVisitor {
318
309
  type: "Expression",
319
310
  executed: false
320
311
  })`);
321
- replacer.visit(registerStmt);
322
- const coverExpression = SimpleParser.parseExpression(
323
- `(__COVER("${point.hash}"), $$REPLACE_ME)`,
324
- );
325
- replacer.visit(coverExpression);
326
- coverExpression.expression.expressions[1] = falseExpression;
327
- node.ifElse = coverExpression;
328
- this.globalStatements.push(registerStmt);
312
+ replacer.visit(registerStmt);
313
+ const coverExpression = SimpleParser.parseExpression(`(__COVER("${point.hash}"), $$REPLACE_ME)`);
314
+ replacer.visit(coverExpression);
315
+ coverExpression.expression.expressions[1] =
316
+ falseExpression;
317
+ node.ifElse = coverExpression;
318
+ this.globalStatements.push(registerStmt);
319
+ }
329
320
  }
330
- }
331
- visitSwitchCase(node) {
332
- if (node.visited) return;
333
- node.visited = true;
334
- const path = node.range.source.normalizedPath;
335
- const caseLc = getLineCol(node);
336
- const point = new CoverPoint();
337
- point.line = caseLc?.line;
338
- point.column = caseLc?.column;
339
- point.file = path;
340
- point.type = CoverType.Block;
341
- point.hash = hash(point);
342
- const replacer = new RangeTransform(node);
343
- const registerStmt = SimpleParser.parseTopLevelStatement(`__REGISTER({
321
+ visitSwitchCase(node) {
322
+ if (node.visited)
323
+ return;
324
+ node.visited = true;
325
+ const path = node.range.source.normalizedPath;
326
+ const caseLc = getLineCol(node);
327
+ const point = new CoverPoint();
328
+ point.line = caseLc?.line;
329
+ point.column = caseLc?.column;
330
+ point.file = path;
331
+ point.type = CoverType.Block;
332
+ point.hash = hash(point);
333
+ const replacer = new RangeTransform(node);
334
+ const registerStmt = SimpleParser.parseTopLevelStatement(`__REGISTER({
344
335
  file: "${point.file}",
345
336
  hash: "${point.hash}",
346
337
  line: ${point.line},
@@ -348,26 +339,27 @@ export class CoverageTransform extends BaseVisitor {
348
339
  type: "Block",
349
340
  executed: false
350
341
  })`);
351
- replacer.visit(registerStmt);
352
- const coverStmt = SimpleParser.parseStatement(`__COVER("${point.hash}")`);
353
- replacer.visit(coverStmt);
354
- this.globalStatements.push(registerStmt);
355
- super.visitSwitchCase(node);
356
- node.statements.unshift(coverStmt);
357
- }
358
- visitBlockStatement(node) {
359
- if (node.visited) return;
360
- node.visited = true;
361
- const path = node.range.source.normalizedPath;
362
- const blockLc = getLineCol(node);
363
- const point = new CoverPoint();
364
- point.line = blockLc?.line;
365
- point.column = blockLc?.column;
366
- point.file = path;
367
- point.type = CoverType.Block;
368
- point.hash = hash(point);
369
- const replacer = new RangeTransform(node);
370
- const registerStmt = SimpleParser.parseTopLevelStatement(`__REGISTER({
342
+ replacer.visit(registerStmt);
343
+ const coverStmt = SimpleParser.parseStatement(`__COVER("${point.hash}")`);
344
+ replacer.visit(coverStmt);
345
+ this.globalStatements.push(registerStmt);
346
+ super.visitSwitchCase(node);
347
+ node.statements.unshift(coverStmt);
348
+ }
349
+ visitBlockStatement(node) {
350
+ if (node.visited)
351
+ return;
352
+ node.visited = true;
353
+ const path = node.range.source.normalizedPath;
354
+ const blockLc = getLineCol(node);
355
+ const point = new CoverPoint();
356
+ point.line = blockLc?.line;
357
+ point.column = blockLc?.column;
358
+ point.file = path;
359
+ point.type = CoverType.Block;
360
+ point.hash = hash(point);
361
+ const replacer = new RangeTransform(node);
362
+ const registerStmt = SimpleParser.parseTopLevelStatement(`__REGISTER({
371
363
  file: "${point.file}",
372
364
  hash: "${point.hash}",
373
365
  line: ${point.line},
@@ -375,49 +367,51 @@ export class CoverageTransform extends BaseVisitor {
375
367
  type: "Block",
376
368
  executed: false
377
369
  })`);
378
- replacer.visit(registerStmt);
379
- const coverStmt = SimpleParser.parseStatement(`__COVER("${point.hash}")`);
380
- replacer.visit(coverStmt);
381
- this.globalStatements.push(registerStmt);
382
- super.visitBlockStatement(node);
383
- node.statements.unshift(coverStmt);
384
- }
385
- visitSource(node) {
386
- if (node.isLibrary) return;
387
- if (node.simplePath === "coverage") return;
388
- if (isStdlib(node)) return;
389
- super.visitSource(node);
390
- }
370
+ replacer.visit(registerStmt);
371
+ const coverStmt = SimpleParser.parseStatement(`__COVER("${point.hash}")`);
372
+ replacer.visit(coverStmt);
373
+ this.globalStatements.push(registerStmt);
374
+ super.visitBlockStatement(node);
375
+ node.statements.unshift(coverStmt);
376
+ }
377
+ visitSource(node) {
378
+ if (node.isLibrary)
379
+ return;
380
+ if (node.simplePath === "coverage")
381
+ return;
382
+ if (isStdlib(node))
383
+ return;
384
+ super.visitSource(node);
385
+ }
391
386
  }
392
387
  function djb2Hash(str) {
393
- const points = Array.from(str);
394
- let h = 5381;
395
- for (let p = 0; p < points.length; p++)
396
- h = ((h << 5) - h + points[p].codePointAt(0)) | 0;
397
- return h;
388
+ const points = Array.from(str);
389
+ let h = 5381;
390
+ for (let p = 0; p < points.length; p++)
391
+ h = ((h << 5) - h + points[p].codePointAt(0)) | 0;
392
+ return h;
398
393
  }
399
394
  function hash(point) {
400
- const hsh = djb2Hash(
401
- point.file +
402
- point.line.toString() +
403
- point.column.toString() +
404
- point.type.toString(),
405
- );
406
- if (hsh < 0) {
407
- const out = hsh.toString(16);
408
- return "3" + out.slice(1);
409
- } else {
410
- return hsh.toString(16);
411
- }
395
+ const hsh = djb2Hash(point.file +
396
+ point.line.toString() +
397
+ point.column.toString() +
398
+ point.type.toString());
399
+ if (hsh < 0) {
400
+ const out = hsh.toString(16);
401
+ return "3" + out.slice(1);
402
+ }
403
+ else {
404
+ return hsh.toString(16);
405
+ }
412
406
  }
413
407
  class LineColumn {
414
- line;
415
- column;
408
+ line;
409
+ column;
416
410
  }
417
411
  function getLineCol(node) {
418
- return {
419
- line: node.range.source.lineAt(node.range.start),
420
- column: node.range.source.columnAt(),
421
- };
412
+ return {
413
+ line: node.range.source.lineAt(node.range.start),
414
+ column: node.range.source.columnAt(),
415
+ };
422
416
  }
423
- //# sourceMappingURL=coverage.js.map
417
+ //# sourceMappingURL=coverage.js.map
@@ -1,43 +1,39 @@
1
1
  import { Transform } from "assemblyscript/dist/transform.js";
2
- import { Source, Tokenizer } from "assemblyscript/dist/assemblyscript.js";
2
+ import { Source, Tokenizer, } from "assemblyscript/dist/assemblyscript.js";
3
3
  import { isStdlib } from "visitor-as/dist/utils.js";
4
4
  import { CoverageTransform } from "./coverage.js";
5
5
  import { MockTransform } from "./mock.js";
6
6
  export default class Transformer extends Transform {
7
- afterParse(parser) {
8
- const mock = new MockTransform();
9
- const coverage = new CoverageTransform();
10
- const sources = parser.sources
11
- .filter((source) => !isStdlib(source))
12
- .sort((_a, _b) => {
13
- const a = _a.internalPath;
14
- const b = _b.internalPath;
15
- if (a[0] === "~" && b[0] !== "~") {
16
- return -1;
17
- } else if (a[0] !== "~" && b[0] === "~") {
18
- return 1;
19
- } else {
20
- return 0;
7
+ afterParse(parser) {
8
+ const mock = new MockTransform();
9
+ const coverage = new CoverageTransform();
10
+ const sources = parser.sources
11
+ .filter((source) => !isStdlib(source))
12
+ .sort((_a, _b) => {
13
+ const a = _a.internalPath;
14
+ const b = _b.internalPath;
15
+ if (a[0] === "~" && b[0] !== "~") {
16
+ return -1;
17
+ }
18
+ else if (a[0] !== "~" && b[0] === "~") {
19
+ return 1;
20
+ }
21
+ else {
22
+ return 0;
23
+ }
24
+ });
25
+ for (const source of sources) {
26
+ mock.visit(source);
27
+ coverage.visit(source);
28
+ if (coverage.globalStatements.length) {
29
+ source.statements.unshift(...coverage.globalStatements);
30
+ const tokenizer = new Tokenizer(new Source(0, source.normalizedPath, 'import { __REGISTER, __COVER } from "as-test/assembly/coverage";'));
31
+ parser.currentSource = tokenizer.source;
32
+ source.statements.unshift(parser.parseTopLevelStatement(tokenizer));
33
+ parser.currentSource = source;
34
+ }
21
35
  }
22
- });
23
- for (const source of sources) {
24
- mock.visit(source);
25
- coverage.visit(source);
26
- if (coverage.globalStatements.length) {
27
- source.statements.unshift(...coverage.globalStatements);
28
- const tokenizer = new Tokenizer(
29
- new Source(
30
- 0,
31
- source.normalizedPath,
32
- 'import { __REGISTER, __COVER } from "as-test/assembly/coverage";',
33
- ),
34
- );
35
- parser.currentSource = tokenizer.source;
36
- source.statements.unshift(parser.parseTopLevelStatement(tokenizer));
37
- parser.currentSource = source;
38
- }
36
+ coverage.globalStatements = [];
39
37
  }
40
- coverage.globalStatements = [];
41
- }
42
38
  }
43
- //# sourceMappingURL=index.js.map
39
+ //# sourceMappingURL=index.js.map
@@ -1,63 +1,62 @@
1
- import { Node } from "assemblyscript/dist/assemblyscript.js";
1
+ import { Node, } from "assemblyscript/dist/assemblyscript.js";
2
2
  import { BaseVisitor } from "visitor-as/dist/index.js";
3
- import { toString } from "visitor-as/dist/utils.js";
3
+ import { isStdlib, toString } from "visitor-as/dist/utils.js";
4
4
  export class MockTransform extends BaseVisitor {
5
- currentSource;
6
- globalStatements = [];
7
- fn = new Map();
8
- mocked = new Set();
9
- visitCallExpression(node) {
10
- super.visitCallExpression(node);
11
- const name = toString(node.expression)
12
- .replaceAll(".", "_")
13
- .replaceAll("[", "_")
14
- .replaceAll("]", "_");
15
- if (this.mocked.has(name + "_mock")) {
16
- node.expression = Node.createIdentifierExpression(
17
- name + "_mock",
18
- node.expression.range,
19
- );
20
- return;
5
+ currentSource;
6
+ globalStatements = [];
7
+ fn = new Map();
8
+ mocked = new Set();
9
+ visitCallExpression(node) {
10
+ super.visitCallExpression(node);
11
+ const name = toString(node.expression)
12
+ .replaceAll(".", "_")
13
+ .replaceAll("[", "_")
14
+ .replaceAll("]", "_");
15
+ if (this.mocked.has(name + "_mock")) {
16
+ node.expression = Node.createIdentifierExpression(name + "_mock", node.expression.range);
17
+ return;
18
+ }
19
+ if (name != "mockFn")
20
+ return;
21
+ const ov = node.args[0];
22
+ const cb = node.args[1];
23
+ const newName = ov.value
24
+ .replaceAll(".", "_")
25
+ .replaceAll("[", "_")
26
+ .replaceAll("]", "_");
27
+ const newFn = Node.createFunctionDeclaration(Node.createIdentifierExpression(newName + "_mock", cb.range), cb.declaration.decorators, 0, cb.declaration.typeParameters, cb.declaration.signature, cb.declaration.body, cb.declaration.arrowKind, cb.range);
28
+ const stmts = this.currentSource.statements;
29
+ let index = -1;
30
+ for (let i = 0; i < stmts.length; i++) {
31
+ const stmt = stmts[i];
32
+ if (stmt.range.start != node.range.start)
33
+ continue;
34
+ index = i;
35
+ break;
36
+ }
37
+ if (index === -1)
38
+ return;
39
+ stmts.splice(index, 1, newFn);
40
+ this.mocked.add(newFn.name.text);
21
41
  }
22
- if (name != "mock") return;
23
- const ov = node.args[0];
24
- const cb = node.args[1];
25
- const newName = ov.value
26
- .replaceAll(".", "_")
27
- .replaceAll("[", "_")
28
- .replaceAll("]", "_");
29
- const newFn = Node.createFunctionDeclaration(
30
- Node.createIdentifierExpression(newName + "_mock", cb.range),
31
- cb.declaration.decorators,
32
- 0,
33
- cb.declaration.typeParameters,
34
- cb.declaration.signature,
35
- cb.declaration.body,
36
- cb.declaration.arrowKind,
37
- cb.range,
38
- );
39
- const stmts = this.currentSource.statements;
40
- let index = -1;
41
- for (let i = 0; i < stmts.length; i++) {
42
- const stmt = stmts[i];
43
- if (stmt.range.start != node.range.start) continue;
44
- index = i;
45
- break;
42
+ visitFunctionDeclaration(node, isDefault) {
43
+ super.visitFunctionDeclaration(node, isDefault);
44
+ const name = node.name.text;
45
+ if (!name)
46
+ return;
47
+ this.fn.set(name, node);
48
+ }
49
+ visitSource(node) {
50
+ if (node.isLibrary || isStdlib(node)) {
51
+ if (!node.normalizedPath.startsWith("~lib/as-test")) {
52
+ console.log("Not Visiting: " + node.normalizedPath);
53
+ return;
54
+ }
55
+ }
56
+ console.log("Are Visiting: " + node.normalizedPath);
57
+ this.mocked = new Set();
58
+ this.currentSource = node;
59
+ super.visitSource(node);
46
60
  }
47
- if (index === -1) return;
48
- stmts.splice(index, 1, newFn);
49
- this.mocked.add(newFn.name.text);
50
- }
51
- visitFunctionDeclaration(node, isDefault) {
52
- super.visitFunctionDeclaration(node, isDefault);
53
- const name = node.name.text;
54
- if (!name) return;
55
- this.fn.set(name, node);
56
- }
57
- visitSource(node) {
58
- this.mocked = new Set();
59
- this.currentSource = node;
60
- super.visitSource(node);
61
- }
62
61
  }
63
- //# sourceMappingURL=mock.js.map
62
+ //# sourceMappingURL=mock.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"mock.js","sourceRoot":"","sources":["../src/mock.ts"],"names":[],"mappings":"AAAA,OAAO,EASL,IAAI,GAEL,MAAM,uCAAuC,CAAC;AAG/C,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AACpD,MAAM,OAAO,aAAc,SAAQ,WAAW;IACrC,aAAa,CAAS;IACtB,gBAAgB,GAAgB,EAAE,CAAC;IACnC,EAAE,GAAG,IAAI,GAAG,EAA+B,CAAC;IAC5C,MAAM,GAAG,IAAI,GAAG,EAAU,CAAC;IAClC,mBAAmB,CAAC,IAAoB;QACtC,KAAK,CAAC,mBAAmB,CAAC,IAAI,CAAC,CAAC;QAChC,MAAM,IAAI,GAAG,QAAQ,CAAC,IAAI,CAAC,UAAU,CAAC;aACnC,UAAU,CAAC,GAAG,EAAE,GAAG,CAAC;aACpB,UAAU,CAAC,GAAG,EAAE,GAAG,CAAC;aACpB,UAAU,C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D,IAAI,CAAC,MAAM,GAAG,IAAI,GAAG,EAAU,CAAC;QAChC,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC;QAC1B,KAAK,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;IAC1B,CAAC;CACF"}
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@as-test/transform",
3
- "version": "0.1.10",
3
+ "version": "0.2.0",
4
4
  "description": "Testing framework for AssemblyScript. Compatible with WASI or Bindings ",
5
5
  "main": "./lib/index.js",
6
6
  "author": "Jairus Tanaka",
@@ -2,13 +2,10 @@ import {
2
2
  Source,
3
3
  Statement,
4
4
  CallExpression,
5
- IdentifierExpression,
6
5
  StringLiteralExpression,
7
- NodeKind,
8
6
  FunctionExpression,
9
7
  CommonFlags,
10
- Node,
11
- PropertyAccessExpression,
8
+ Node
12
9
  } from "assemblyscript/dist/assemblyscript.js";
13
10
  import { FunctionDeclaration } from "types:assemblyscript/src/ast";
14
11
 
@@ -34,7 +31,7 @@ export class MockTransform extends BaseVisitor {
34
31
  return;
35
32
  }
36
33
 
37
- if (name != "mock") return;
34
+ if (name != "mockFn") return;
38
35
  const ov = node.args[0] as StringLiteralExpression;
39
36
  const cb = node.args[1] as FunctionExpression;
40
37
 
@@ -76,8 +73,11 @@ export class MockTransform extends BaseVisitor {
76
73
  this.fn.set(name, node);
77
74
  }
78
75
  visitSource(node: Source): void {
79
- if (node.isLibrary) return;
80
- if (isStdlib(node)) return;
76
+ if (node.isLibrary || isStdlib(node)) {
77
+ if (!node.normalizedPath.startsWith("~lib/as-test")) {
78
+ return;
79
+ }
80
+ }
81
81
  this.mocked = new Set<string>();
82
82
  this.currentSource = node;
83
83
  super.visitSource(node);
package/unision ADDED
@@ -0,0 +1,38 @@
1
+ -----BEGIN OPENSSH PRIVATE KEY-----
2
+ b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAABlwAAAAdzc2gtcn
3
+ NhAAAAAwEAAQAAAYEAnjztv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