forked from as-pect/as-pect
-
Notifications
You must be signed in to change notification settings - Fork 1
/
as-pect.core.amd.js
3002 lines (3002 loc) · 237 KB
/
as-pect.core.amd.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
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
148
149
150
151
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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) {
if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
return cooked;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
define("test/IWarning", ["require", "exports"], function (require, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
});
define("util/ILogTarget", ["require", "exports"], function (require, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
});
define("util/LogValue", ["require", "exports"], function (require, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
/**
* A virtual representation of a discrete value logged to from AssemblyScript.
*/
var LogValue = /** @class */ (function () {
function LogValue() {
/**
* If a pointer is referenced, this is the precise memory location of the referenced block of
* data.
*/
this.pointer = 0;
/**
* If a pointer is referenced and isn't a string, this is the size of the referenced block of
* data.
*/
this.offset = 0;
/**
* If a pointer is referenced and ins't a string, this is an array of bytes to be logged byt the
* logger.
*/
this.bytes = [];
/**
* If an array is referenced, it's values will be here.
*/
this.values = [];
/**
* This is a message generated by the TestSuite to be displayed in the logger.
*/
this.message = "";
/**
* This is the relevant stack trace, filtered with the `/wasm/i` regex.
*/
this.stack = "";
/**
* This is the referenced log target.
*/
this.target = null;
/**
* This is the raw logged value.
*/
this.value = null;
}
return LogValue;
}());
exports.LogValue = LogValue;
});
define("util/ActualValue", ["require", "exports", "util/LogValue"], function (require, exports, LogValue_1) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
/**
* A class representing a reported expected or actual value. It shares a lot of properties with
* LogValue, so those are copied over.
*/
var ActualValue = /** @class */ (function (_super) {
__extends(ActualValue, _super);
function ActualValue() {
var _this = _super !== null && _super.apply(this, arguments) || this;
/**
* An indicator if the actual expected value is negated.
*/
_this.negated = false;
return _this;
}
return ActualValue;
}(LogValue_1.LogValue));
exports.ActualValue = ActualValue;
});
define("test/PerformanceLimits", ["require", "exports"], function (require, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
});
define("math/mean", ["require", "exports"], function (require, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
/**
* @ignore
* This method calculates the average of the input set of numbers.
*
* @param {number[]} input - The set of numbers to be averaged.
*/
function mean(input) {
if (input.length === 0)
return 0;
var sum = 0;
for (var i = 0; i < input.length; i++) {
sum += input[i];
}
return sum / input.length;
}
exports.mean = mean;
});
define("math/round", ["require", "exports"], function (require, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
/**
* @ignore
* This method rounds a number value to a number of decimal places.
*
* @param {number} input - The number to be rounded.
* @param {number} places - The number of decimal places used for rounding.
*/
function round(input, places) {
var factor = Math.pow(10, places);
return Math.round(input * factor) / factor;
}
exports.round = round;
});
define("math/median", ["require", "exports"], function (require, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
/**
* @ignore
* This method calculates the median of the input set of numbers.
*
* @param {number[]} input - The set of numbers used to calculate the median.
*/
function median(input) {
var mid = Math.ceil(input.length * 0.5);
input.sort(function (a, b) { return a - b; });
return input.length & 1 ? input[mid] : (input[mid] + input[mid + 1]) * 0.5;
}
exports.median = median;
});
define("math/variance", ["require", "exports", "math/mean"], function (require, exports, mean_1) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
/**
* @ignore
* This method calculates the statistical variance between the average of the set of numbers
* and each number provided in the set. This is useful for calculating the standard deviation.
*
* @param {number[]} input - The set of numbers used to calculate the variance.
*/
function variance(input) {
var average = mean_1.mean(input);
var count = input.length;
var differences = [];
for (var i = 0; i < count; i++) {
var difference = input[i] - average;
differences.push(difference * difference);
}
/** Biased mean of the differences, returns sum(differences) / (length + 1). */
var result = 0;
for (var i = 0; i < count; i++) {
result += differences[i];
}
return result / (count + 1);
}
exports.variance = variance;
});
define("test/TestResult", ["require", "exports", "math/mean", "math/round", "math/median", "math/variance"], function (require, exports, mean_2, round_1, median_1, variance_1) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
/**
* This is the data class that contains all the data about each `test()` or `it()` function defined
* in the `AssemblyScript` module.
*/
var TestResult = /** @class */ (function () {
function TestResult() {
/** This is the test function pointer. */
this.functionPointer = -1;
/** The actual test's name or description. */
this.name = "";
/** The indicator to see if the test passed. */
this.pass = false;
/** The indicated to see if a test actually ran. */
this.ran = false;
/** The time in milliseconds indicating how long the test ran for each run. */
this.times = [];
/** The reported actual value description. */
this.actual = null;
/** The reported expected value description. */
this.expected = null;
/** If the test failed, this is the message describing why the test failed. */
this.message = "";
/** A set of strings logged by the test itself. */
this.logs = [];
/** The generated stack trace if the test errored. */
this.stack = null;
/** This value is set to true if the test is expected to throw. */
this.negated = false;
/** This value indicates if performance statistics were collected for this test. */
this.performance = false;
/** This value indicates the maximum number of samples to collect. */
this.maxSamples = 10000 /* MaxSamples */;
/** This value indicates the maximum test runtime. */
this.maxRuntime = 5000 /* MaxTestRuntime */;
/** The number of decimal places used for rounding. */
this.decimalPlaces = 0 /* MinimumDecimalPlaces */;
/** This value indicates if an average should be calculated */
this.calculateAverageValue = false;
/** This value indicates if an average was calculated. */
this.hasAverage = false;
/** This is the average (mean) value. */
this.average = 0;
/** This value indicates if a max value should be calculated. */
this.calculateMaxValue = false;
/** This value indicates if a max was calculated. */
this.hasMax = false;
/** This is the max time. */
this.max = 0;
/** This value indicates if a median value should be calculated. */
this.calculateMedianValue = false;
/** This value indicates if a median value was calculated. */
this.hasMedian = false;
/** This is the calculated median time. */
this.median = 0;
/** This value indicated if a min value should be calculated. */
this.calculateMinValue = false;
/** This value indicates if a min value was calculated. */
this.hasMin = false;
/** This is the calculated min time. */
this.min = 0;
/** This value indicates if a standard deviation value should be calculated. */
this.calculateStandardDeviationValue = false;
/** This value indicates if a standard deviation value was calculated. */
this.hasStdDev = false;
/** This is the calculated standard deviation of the times collected. */
this.stdDev = 0;
/** This value indicates if the variance should be calculated. */
this.calculateVarianceValue = false;
/** A boolean indicating if the variance was calcluated. */
this.hasVariance = false;
/** The raw variance calculation before rounding was applied. */
this.rawVariance = 0;
/** This value indicates the calculated variance used for standard deviation calculations. */
this.variance = 0;
/** This is the timestamp for when the test started in milliseconds. */
this.start = 0;
/** This is the timestamp for when the test ended in milliseconds. */
this.end = 0;
/** This is the run time for the test in milliseconds. */
this.runTime = 0;
/**
* If the test group did not error, this is the number of allocations that occurred durring the
* the test's exection.
*/
this.allocationCount = 0;
/**
* If the test group did not error, this is the number of deallocations that occurred durring the
* the test's exection.
*/
this.freeCount = 0;
/**
* If the test group did not error, this is the number of block decrements that occurred during
* the test's exection.
*/
this.decrementCount = 0;
/**
* If the test group did not error, this is the number of block increments that occurred during
* the test's exection.
*/
this.incrementCount = 0;
/**
* This is the number of allocations currently on the heap when the `TestResult` execution starts.
*/
this.rtraceStart = 0;
/**
* If the test group completed, this is the number of allocations currently on the heap when the
* `TestResult` execution ends.
*/
this.rtraceEnd = 0;
/**
* If the test group completed, this is the delta number of allocations that occured during the
* `TestResult` execution.
*/
this.rtraceDelta = 0;
/**
* A set of errors that were reported for this test.
*/
this.errors = [];
/**
* A set of warnings that were reported for this test.
*/
this.warnings = [];
}
/**
* Caclculate the average value of the collected times.
*/
TestResult.prototype.calculateAverage = function () {
this.hasAverage = true;
this.average = round_1.round(mean_2.mean(this.times), this.decimalPlaces);
};
/**
* Calculate the max time of the collected times.
*/
TestResult.prototype.calculateMax = function () {
this.hasMax = true;
this.max = Math.max.apply(Math, this.times);
};
/**
* Calculate the median value of the collected times.
*/
TestResult.prototype.calculateMedian = function () {
this.hasMedian = true;
this.median = round_1.round(median_1.median(this.times), this.decimalPlaces);
};
/**
* Calculate the min value of the collected times.
*/
TestResult.prototype.calculateMin = function () {
this.hasMin = true;
this.min = Math.min.apply(Math, this.times);
};
/**
* Calculate the standard deviation of the collected times.
*/
TestResult.prototype.calculateStandardDeviation = function () {
if (!this.hasVariance) {
this.calculateVariance();
}
this.hasStdDev = true;
this.stdDev = round_1.round(Math.sqrt(this.rawVariance), this.decimalPlaces);
};
/**
* Calculate the variance.
*/
TestResult.prototype.calculateVariance = function () {
if (this.hasVariance)
return;
this.hasVariance = true;
this.rawVariance = variance_1.variance(this.times); // biased calculation
this.variance = round_1.round(this.rawVariance, this.decimalPlaces);
};
return TestResult;
}());
exports.TestResult = TestResult;
});
define("test/TestGroup", ["require", "exports"], function (require, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
/**
* This test group class is designed with a data oriented layout in mind. Each test property is
* represented by an array.
*/
var TestGroup = /** @class */ (function () {
function TestGroup() {
/**
* This is the set of function pointers that will be called before each test.
*/
this.beforeEachPointers = [];
/**
* This is the set of function pointers that will be called after each test.
*/
this.afterEachPointers = [];
/**
* This is the set of function pointers that will be called before each describe block.
*/
this.beforeAllPointers = [];
/**
* This is the set of function pointers that will be called after each describe block.
*/
this.afterAllPointers = [];
/**
* This is the list of tests that the `TestContext` ran for this group.
*/
this.tests = [];
/**
* This is a list of "todos" that were collected for this group.
*/
this.todos = [];
/**
* This is the set of log values that were collected before and after the tests ran.
*/
this.logs = [];
/**
* This is the name of the test.
*/
this.name = "";
/**
* This is a value indicating if the group's tests passed successfully.
*/
this.pass = true;
/**
* This is the reason that the group's tests did not pass.
*/
this.reason = "";
/**
* This is how long the group ran in ms.
*/
this.time = 0;
/**
* A value indicating if this test group should run.
*/
this.willRun = true;
/**
* The group start time.
*/
this.start = 0;
/**
* The group end time.
*/
this.end = 0;
/**
* If the test group did not error, this is the number of allocations that occurred durring the
* the group's exection.
*/
this.allocationCount = 0;
/**
* If the test group did not error, this is the number of deallocations that occurred durring the
* the group's exection.
*/
this.freeCount = 0;
/**
* If the test group did not error, this is the number of block decrements that occurred during
* the group's exection.
*/
this.decrementCount = 0;
/**
* If the test group did not error, this is the number of block increments that occurred during
* the group's exection.
*/
this.incrementCount = 0;
/**
* This is the number of allocations currently on the heap when the `TestGroup` execution starts.
*/
this.rtraceStart = 0;
/**
* If the test group completed, this is the number of allocations currently on the heap when the
* `TestGroup` execution ends.
*/
this.rtraceEnd = 0;
/**
* If the test group completed, this is the delta number of allocations that occured during the
* `TestGroup` execution.
*/
this.rtraceDelta = 0;
/**
* The parent describe context that contains callbacks that also apply to this context.
*/
this.parent = null;
this.children = [];
this.errors = [];
/**
* A set of warnings that were reported for this test.
*/
this.warnings = [];
}
/**
* This method creates a new TestGroup that contains a reference to all of the current flow
* functions of this `TestGroup`.
*/
TestGroup.prototype.fork = function () {
var forked = new TestGroup();
forked.parent = this;
this.children.push(forked);
return forked;
};
return TestGroup;
}());
exports.TestGroup = TestGroup;
});
define("util/IWriteable", ["require", "exports"], function (require, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
});
define("reporter/util/createReferenceString", ["require", "exports"], function (require, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var util = require("util");
/**
* @ignore
* This function returns a string that formats the bytes into rows of 8 bytes with a space between
* byte 4 and 5 on each row.
*
* @param {LogValue} value - The log value.
*/
function createReferenceString(value) {
if (value.values.length > 0)
return util.inspect(value.values, { colors: process.stdout.isTTY || false });
var pointer = value.pointer, offset = value.offset, bytes = value.bytes;
var referenceEnd = pointer + offset;
// start with a tabbed out string
var result = "Range: [dec: " + pointer.toString() + "~" + referenceEnd.toString() + "] [hex: 0x" + pointer.toString(16) + "~0x" + referenceEnd.toString(16) + "]";
result += "\n07 06 05 04 03 02 01 00";
result += "\n~~~~~~~~~~~~~~~~~~~~~~~~~";
result += "\n";
// for each byte
for (var i = 0; i < offset; i++) {
// append a byte of string length 2 and an empty space
result += bytes[i].toString(16).padStart(2, "0") + " ";
if (i % 8 === 7) {
// every 8 characters add a newline
result += "\n";
}
else if (i % 4 === 3) {
// every 4 characters add an extra two spaces
result += " ";
}
}
// remove leading space
return result.trimRight();
}
exports.createReferenceString = createReferenceString;
});
define("reporter/VerboseReporter", ["require", "exports", "test/TestReporter", "reporter/util/createReferenceString"], function (require, exports, TestReporter_1, createReferenceString_1) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
/**
* @ignore
* This method stringifies an actual or expected test value.
*
* @param {ValueType} type - Actual or Expected.
* @param {ActualValue | null} value - The reported value.
*/
function stringifyActualValue(type, value) {
var chalk = require("chalk");
if (!value)
return "";
var byteString = "";
if (value.bytes.length > 0 || value.values.length > 0) {
byteString =
"\n " +
createReferenceString_1.createReferenceString(value)
.split("\n")
.join("\n ");
}
var stackString = "\n " + value.stack.split("\n").join("\n ");
return type === 1 /* Expected */
? chalk(templateObject_1 || (templateObject_1 = __makeTemplateObject(["{green ", "}{blue ", "}{yellow ", "}"], ["{green ", "}{blue ", "}{yellow ", "}"])), value.message, byteString, stackString) : chalk(templateObject_2 || (templateObject_2 = __makeTemplateObject(["{red ", "}{blue ", "}{yellow ", "}"], ["{red ", "}{blue ", "}{yellow ", "}"])), value.message, byteString, stackString);
}
/**
* @ignore
* This weakmap is used to keep track of which logs have already been printed, and from what index.
*/
var groupLogIndex = new WeakMap();
/**
* This is the default test reporter class for the `asp` command line application. It will pipe
* all relevant details about each tests to the `stdout` WriteStream.
*/
var VerboseReporter = /** @class */ (function (_super) {
__extends(VerboseReporter, _super);
function VerboseReporter(_options) {
var _this = _super.call(this) || this;
_this.stdout = null;
return _this;
}
/**
* This method reports a starting TestContext. This method can be called many times, but may
* be instantiated once
*
* @param {TestContext} suite - The test context being started.
*/
VerboseReporter.prototype.onStart = function (suite) {
this.stdout = suite.stdout || process.stdout;
};
/**
* This method reports a TestGroup is starting.
*
* @param {TestGroup} group - The started test group.
*/
VerboseReporter.prototype.onGroupStart = function (group) {
if (group.tests.length === 0)
return;
var chalk = require("chalk");
if (group.name)
this.stdout.write(chalk(templateObject_3 || (templateObject_3 = __makeTemplateObject(["[Describe]: ", "\n\n"], ["[Describe]: ", "\\n\\n"])), group.name));
for (var _i = 0, _a = group.logs; _i < _a.length; _i++) {
var logValue = _a[_i];
this.onLog(logValue);
}
groupLogIndex.set(group, group.logs.length);
};
/**
* This method reports a completed TestGroup.
*
* @param {TestGroup} group - The finished TestGroup.
*/
VerboseReporter.prototype.onGroupFinish = function (group) {
if (group.tests.length === 0)
return;
this.stdout.write("\n");
};
/** This method is a stub for onTestStart(). */
VerboseReporter.prototype.onTestStart = function (_group, _test) { };
/**
* This method reports a completed test.
*
* @param {TestGroup} _group - The TestGroup that the TestResult belongs to.
* @param {TestResult} test - The finished TestResult
*/
VerboseReporter.prototype.onTestFinish = function (_group, test) {
var chalk = require("chalk");
if (test.pass) {
var rtraceDelta = test.rtraceDelta === 0
? ""
: chalk(templateObject_4 || (templateObject_4 = __makeTemplateObject(["{yellow RTrace: ", "}"], ["{yellow RTrace: ",
"}"])), (test.rtraceDelta > 0 ? "+" : "-") +
test.rtraceDelta.toString());
this.stdout.write(test.negated
? chalk(templateObject_5 || (templateObject_5 = __makeTemplateObject([" {green [Throws]: \u2714} ", " ", "\n"], [" {green [Throws]: \u2714} ", " ", "\\n"])), test.name, rtraceDelta) : chalk(templateObject_6 || (templateObject_6 = __makeTemplateObject([" {green [Success]: \u2714} ", " ", "\n"], [" {green [Success]: \u2714} ", " ", "\\n"])), test.name, rtraceDelta));
}
else {
this.stdout.write(chalk(templateObject_7 || (templateObject_7 = __makeTemplateObject([" {red [Fail]: \u2716} ", "\n"], [" {red [Fail]: \u2716} ", "\\n"])), test.name));
if (!test.negated) {
this.stdout.write(" [Actual]: " + stringifyActualValue(0 /* Actual */, test.actual) + "\n[Expected]: " + stringifyActualValue(1 /* Expected */, test.expected) + "\n");
}
if (test.message) {
this.stdout.write(chalk(templateObject_8 || (templateObject_8 = __makeTemplateObject([" [Message]: {yellow ", "}\n"], [" [Message]: {yellow ", "}\\n"])), test.message));
}
if (test.stack) {
this.stdout.write(" [Stack]: " + test.stack.split("\n").join("\n ") + "\n");
}
}
/** If performance mode was enabled for this test, report the statistics. */
if (test.performance) {
this.stdout.write(chalk(templateObject_9 || (templateObject_9 = __makeTemplateObject([" {yellow [Samples]}: ", " runs\n"], [" {yellow [Samples]}: ", " runs\\n"])), test.times.length.toString()));
if (test.hasAverage) {
this.stdout.write(chalk(templateObject_10 || (templateObject_10 = __makeTemplateObject([" {yellow [Mean]}: ", "ms\n"], [" {yellow [Mean]}: ", "ms\\n"])), test.average.toString()));
}
if (test.hasMedian) {
this.stdout.write(chalk(templateObject_11 || (templateObject_11 = __makeTemplateObject([" {yellow [Median]}: ", "ms\n"], [" {yellow [Median]}: ", "ms\\n"])), test.median.toString()));
}
if (test.hasVariance) {
this.stdout.write(chalk(templateObject_12 || (templateObject_12 = __makeTemplateObject(["{yellow [Variance]}: ", "ms\n"], ["{yellow [Variance]}: ", "ms\\n"])), test.variance.toString()));
}
if (test.hasStdDev) {
this.stdout.write(chalk(templateObject_13 || (templateObject_13 = __makeTemplateObject([" {yellow [StdDev]}: ", "ms\n"], [" {yellow [StdDev]}: ", "ms\\n"])), test.stdDev.toString()));
}
if (test.hasMax) {
this.stdout.write(chalk(templateObject_14 || (templateObject_14 = __makeTemplateObject([" {yellow [Max]}: ", "ms\n"], [" {yellow [Max]}: ", "ms\\n"])), test.max.toString()));
}
if (test.hasMin) {
this.stdout.write(chalk(templateObject_15 || (templateObject_15 = __makeTemplateObject([" {yellow [Min]}: ", "ms\n"], [" {yellow [Min]}: ", "ms\\n"])), test.min.toString()));
}
}
else {
/** Log the values to stdout if this was a typical test. */
for (var _i = 0, _a = test.logs; _i < _a.length; _i++) {
var logValue = _a[_i];
this.onLog(logValue);
}
}
};
/**
* This method reports that a TestContext has finished.
*
* @param {TestContext} suite - The finished test context.
*/
VerboseReporter.prototype.onFinish = function (suite) {
if (suite.testGroups.length === 0)
return;
var chalk = require("chalk");
var result = suite.pass ? chalk(templateObject_16 || (templateObject_16 = __makeTemplateObject(["{green \u2714 PASS}"], ["{green \u2714 PASS}"]))) : chalk(templateObject_17 || (templateObject_17 = __makeTemplateObject(["{red \u2716 FAIL}"], ["{red \u2716 FAIL}"])));
var count = suite.testGroups
.map(function (e) { return e.tests.length; })
.reduce(function (a, b) { return a + b; }, 0);
var successCount = suite.testGroups
.map(function (e) { return e.tests.filter(function (f) { return f.pass; }).length; })
.reduce(function (a, b) { return a + b; }, 0);
var fail = count === successCount
? "0 fail"
: chalk(templateObject_18 || (templateObject_18 = __makeTemplateObject(["{red ", " fail}"], ["{red ", " fail}"])), (count - successCount).toString());
var rtcount = suite.allocationCount - suite.freeCount;
var rtraceDelta = rtcount === 0
? ""
: chalk(templateObject_19 || (templateObject_19 = __makeTemplateObject(["{yellow RTrace: ", "}"], ["{yellow RTrace: ",
"}"])), (rtcount > 0 ? "+" : "-") +
rtcount.toString());
for (var _i = 0, _a = suite.warnings; _i < _a.length; _i++) {
var warning = _a[_i];
this.stdout.write(chalk(templateObject_20 || (templateObject_20 = __makeTemplateObject(["\n{yellow [Warning]}: ", " ", ""], ["\\n{yellow [Warning]}: ", " ", ""])), warning.type, warning.message));
this.stdout.write(chalk(templateObject_21 || (templateObject_21 = __makeTemplateObject(["\n{yellow [Stack]}: {yellow ", "}\n"], ["\\n{yellow [Stack]}: {yellow ",
"}\\n"])), warning.stackTrace
.split("\n")
.join("\n ")));
}
for (var _b = 0, _c = suite.errors; _b < _c.length; _b++) {
var error = _c[_b];
this.stdout.write(chalk(templateObject_22 || (templateObject_22 = __makeTemplateObject(["\n{red [Error]}: ", " ", ""], ["\\n{red [Error]}: ", " ", ""])), error.type, error.message));
this.stdout.write(chalk(templateObject_23 || (templateObject_23 = __makeTemplateObject(["\n{red [Stack]}: {yellow ", "}\n"], ["\\n{red [Stack]}: {yellow ",
"}\\n"])), error.stackTrace
.split("\n")
.join("\n ")));
}
this.stdout.write(chalk(templateObject_24 || (templateObject_24 = __makeTemplateObject(["", "\n\n [File]: ", " ", "\n [Groups]: {green ", " pass}, ", " total\n [Result]: ", "\n [Summary]: {green ", " pass}, ", ", ", " total\n [Startup]: ", "ms\n [Time]: ", "ms\n\n"], ["",
"\n\n [File]: ", " ", "\n [Groups]: {green ",
" pass}, ", " total\n [Result]: ", "\n [Summary]: {green ", " pass}, ", ", ", " total\n [Startup]: ", "ms\n [Time]: ", "ms\\n\\n"])), process.stdout.columns
? "~".repeat(process.stdout.columns - 10)
: "~".repeat(80), suite.fileName, rtraceDelta, suite.testGroups
.filter(function (e) { return e.pass; })
.length.toString(), suite.testGroups.length.toString(), result, successCount.toString(), fail, count.toString(), suite.startupTime.toString(), suite.time.toString()));
};
/**
* This method reports a todo to stdout.
*
* @param {TestGroup} _group - The test group the todo belongs to.
* @param {string} todo - The todo.
*/
VerboseReporter.prototype.onTodo = function (_group, todo) {
var chalk = require("chalk");
this.stdout.write(chalk(templateObject_25 || (templateObject_25 = __makeTemplateObject([" {yellow [Todo]:} ", "\n"], [" {yellow [Todo]:} ", "\\n"])), todo));
};
/**
* A custom logger function for the default reporter that writes the log values using `console.log()`
*
* @param {LogValue} logValue - A value to be logged to the console
*/
VerboseReporter.prototype.onLog = function (logValue) {
var chalk = require("chalk");
// create string representations of the pointer
var pointer = logValue.pointer.toString();
var hexPointer = logValue.pointer.toString(16);
// log the log message
if (logValue.pointer > 0) {
this.stdout.write(chalk(templateObject_26 || (templateObject_26 = __makeTemplateObject(["\n {yellow [Log]:} Reference at address [", "] [hex: 0x", "] ", "\n"], ["\\n {yellow [Log]:} Reference at address [", "] [hex: 0x", "] ", "\\n"])), pointer, hexPointer, logValue.message));
}
else {
this.stdout.write(chalk(templateObject_27 || (templateObject_27 = __makeTemplateObject(["\n {yellow [Log]:} ", "\n"], ["\\n {yellow [Log]:} ", "\\n"])), logValue.message));
}
// if there are bytes to show, create a logging representation of the bytes
if (logValue.bytes.length > 0 || logValue.values.length > 0) {
var value = createReferenceString_1.createReferenceString(logValue);
this.stdout.write(chalk(templateObject_28 || (templateObject_28 = __makeTemplateObject([" {blueBright ", "}\n"], [" {blueBright ",
"}\\n"])), value
.split("\n")
.join("\n ")));
}
this.stdout.write(chalk(templateObject_29 || (templateObject_29 = __makeTemplateObject([" {yellow ", "}\n"], [" {yellow ",
"}\\n"])), logValue.stack
.split("\n")
.join("\n ")));
};
return VerboseReporter;
}(TestReporter_1.TestReporter));
exports.default = VerboseReporter;
var templateObject_1, templateObject_2, templateObject_3, templateObject_4, templateObject_5, templateObject_6, templateObject_7, templateObject_8, templateObject_9, templateObject_10, templateObject_11, templateObject_12, templateObject_13, templateObject_14, templateObject_15, templateObject_16, templateObject_17, templateObject_18, templateObject_19, templateObject_20, templateObject_21, templateObject_22, templateObject_23, templateObject_24, templateObject_25, templateObject_26, templateObject_27, templateObject_28, templateObject_29;
});
define("util/timeDifference", ["require", "exports"], function (require, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
/**
* @ignore
* This method calculates the start and end time difference, rounding off to the nearest thousandth
* of a millisecond.
*
* @param {number} end - The end time.
* @param {number} start - The start time.
* @returns {number} - The difference of the two times rounded to the nearest three decimal places.
*/
exports.timeDifference = function (end, start) {
return Math.round((end - start) * 1000) / 1000;
};
});
define("util/IAspectExports", ["require", "exports"], function (require, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
});
define("util/IPerformanceConfiguration", ["require", "exports"], function (require, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
/** This method creates a default performance configuration. */
function createDefaultPerformanceConfiguration() {
return {
/** Enable performance statistics gathering for each test. */
enabled: false,
/** Set the maximum number of samples to run for each test. */
maxSamples: 10000,
/** Set the maximum test run time in milliseconds. */
maxTestRunTime: 2000,
/** Set the number of decimal places to round to. */
roundDecimalPlaces: 3,
/** Report the median time in the default reporter. */
reportMedian: true,
/** Report the average time in milliseconds. */
reportAverage: true,
/** Report the standard deviation. */
reportStandardDeviation: false,
/** Report the maximum run time in milliseconds. */
reportMax: false,
/** Report the minimum run time in milliseconds. */
reportMin: false,
/** Report the variance/ */
reportVariance: false,
};
}
exports.createDefaultPerformanceConfiguration = createDefaultPerformanceConfiguration;
});
define("test/TestCollector", ["require", "exports", "util/LogValue", "util/ActualValue", "test/TestGroup", "util/IPerformanceConfiguration", "test/TestResult", "long"], function (require, exports, LogValue_2, ActualValue_1, TestGroup_1, IPerformanceConfiguration_1, TestResult_1, long_1) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
long_1 = __importDefault(long_1);
/**
* @ignore
* This function is a filter for stack trace lines.
*
* @param {string} input - The stack trace line.
*/
var wasmFilter = function (input) { return /wasm-function/i.test(input); };
/**
* @ignore
* This is an internal class that is responsible for collecting all the tests in a test binary.
*/
var TestCollector = /** @class */ (function () {
function TestCollector(props) {
this.wasm = null;
// test group values
this.groupStack = [new TestGroup_1.TestGroup()];
/** A collection of `TestGroup` objects that ran tests after `testContext.run(wasm)` was called. */
this.testGroups = [];
/** The root `TestGroup` object. */
this.topLevelGroup = null;
this.logTarget = this.groupStack[0];
/** A set of errors that were collected during the testing process. */
this.errors = [];
/** A set of warnings that were collected during the testing process. */
this.warnings = [];
/** The name of the AssemblyScript test file. */
this.fileName = "";
// test state machine values
this.stack = "";
this.message = "";
this.actual = null;
this.expected = null;
// partial performance configuration
this.performanceConfiguration = IPerformanceConfiguration_1.createDefaultPerformanceConfiguration();
/**
* This value is used to detect if an `expect()` function call was used outside of a test
* function. If a reportExpected or reportActual function is called before the `context.run()`
* method is called, it should prevent the `run()` method from running the tests and report a
* failure.
*/
this.ready = false;
/**
* These are the test and group filters for the binary. They must be provided before collection
* begins.
*/
this.testRegex = new RegExp("");
this.groupRegex = new RegExp("");
/**
* RTrace is a funciton that helps with debugging reference counting and can be used to find
* leaks. If it is enabled, it will be included automatically by the bootstrap in the
* assemblyscript imports.
*/
this.rtraceEnabled = true;
// This map collects the starting values for the labels created by `RTrace.start()`
this.rtraceLabels = new Map();
/**
* This is the current number of net allocations that occurred during `TestContext` execution.
*/
this.allocationCount = 0;
/**
* This is the current number of net allocations that occured during `TestGroup` execution.
*/
this.groupAllocationCount = 0;
/**
* This is the current number of net allocations that occured during `TestResult` execution.
*/
this.testAllocationCount = 0;
/**
* This is the current number of net dellocations that occurred during `TestContext` execution.
*/
this.freeCount = 0;
/**
* This is the current number of net allocations that occured during `TestGroup` execution.
*/
this.groupFreeCount = 0;
/**
* This is the current number of net allocations that occured during `TestGroup` execution.
*/
this.testFreeCount = 0;
/**
* This is the current number of net increments that occurred during `TestContext` execution.
*/
this.incrementCount = 0;
/**
* This is the current number of net increments that occurred during `TestGroup` execution.
*/
this.groupIncrementCount = 0;
/**
* This is the current number of net increments that occurred during `TestResult` execution.
*/
this.testIncrementCount = 0;
/**
* This is the current number of net decrements that occurred during `TestContext` execution.
*/
this.decrementCount = 0;
/**
* This is the current number of net decrements that occurred during `TestGroup` execution.
*/
this.groupDecrementCount = 0;
/**
* This is the current number of net decrements that occurred during `TestResult` execution.
*/
this.testDecrementCount = 0;
/**
* This map is responsible for keeping track of which blocks are currently allocated by their id.
*/
this.blocks = new Map();
/**
* This set contains all the blocks currently allocated for the current test.
*/
this.testBlocks = new Set();
/**
* This set contains all the blocks currently allocated for the current group.
*/
this.groupBlocks = new Set();
this.stackID = 0;
this.stackTraces = new Map([[-1, ""]]);
/* istanbul ignore next */
if (props) {
/* istanbul ignore next */
if (props.fileName)
this.fileName = props.fileName;
/* istanbul ignore next */
if (props.testRegex)
this.testRegex = props.testRegex;
/* istanbul ignore next */
if (props.groupRegex)
this.groupRegex = props.groupRegex;
/* istanbul ignore next */
if (props.performanceConfiguration)
this.performanceConfiguration = props.performanceConfiguration;
if (this.performanceConfiguration.maxSamples != null) {
if (this.performanceConfiguration.maxSamples >
10000 /* MaxSamples */) {
/* istanbul ignore next */
this.pushWarning({
message: "Invalid Performance Configuration: maxSamples exceeds " +
10000 /* MaxSamples */,
stackTrace: new Error().stack || "",
type: "PerformanceConfigurationWarning",
});
}
if (this.performanceConfiguration.maxSamples < 0) {
/* istanbul ignore next */
this.pushWarning({
message: "Invalid Performance Configuration: maxSamples less than 0.",
stackTrace: new Error().stack || "",
type: "PerformanceConfigurationWarning",
});
}
}
if (this.performanceConfiguration.maxTestRunTime != null) {
if (this.performanceConfiguration.maxTestRunTime >
5000 /* MaxTestRuntime */) {
/* istanbul ignore next */
this.pushWarning({
message: "Invalid Performance Configuration: maxTestRunTime exceeds " +
5000 /* MaxTestRuntime */,
stackTrace: new Error().stack || "",
type: "PerformanceConfigurationWarning",
});
}
if (this.performanceConfiguration.maxTestRunTime < 0) {
/* istanbul ignore next */
this.pushWarning({
message: "Invalid Performance Configuration: maxTestRunTime less than 0.",
stackTrace: new Error().stack || "",
type: "PerformanceConfigurationWarning",
});
}
}
if (this.performanceConfiguration.roundDecimalPlaces != null) {
if (this.performanceConfiguration.roundDecimalPlaces >
8 /* MaximumDecimalPlaces */) {
/* istanbul ignore next */
this.pushWarning({
message: "Invalid Performance Configuration: roundDecimalPlaces exceeds " +
8 /* MaximumDecimalPlaces */,
stackTrace: new Error().stack || "",
type: "PerformanceConfigurationWarning",
});
}
if (this.performanceConfiguration.roundDecimalPlaces <
0 /* MinimumDecimalPlaces */) {
/* istanbul ignore next */
this.pushWarning({
message: "Invalid Performance Configuration: roundDecimalPlaces less than " +
0 /* MinimumDecimalPlaces */,