@platforma-sdk/workflow-tengo 2.3.1 → 2.4.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.
@@ -0,0 +1,204 @@
1
+ /*
2
+ * Library for tengo unit tests.
3
+ * Contains collection of helpers, that make tengo unit tests more compact, easier for reading and writing.
4
+ *
5
+ * WARNING: It is designed to be imported ONLY in *.test.tengo files.
6
+ * As it works ONLY in tengo unit tests context, it will break any workflow if imported
7
+ * in .lib.tengo or .tpl.tengo file.
8
+ */
9
+
10
+ test := import("test")
11
+
12
+ //
13
+ // Basic re-export from "test" builtin library with some conveniences
14
+ //
15
+
16
+ /**
17
+ * Skip the test writing given message to the console log.
18
+ *
19
+ * @param args: []any - message to be written.
20
+ * Each argument is converted to string with its default formatter.
21
+ */
22
+ skip := func(...args) {
23
+ test.skip(args...)
24
+ }
25
+
26
+ /**
27
+ * Formatted version of skip(). skipf(msg, ...args) == skip(format(msg, args...))
28
+ *
29
+ * @param msg: string - message with formatting directives.
30
+ * @param args: []any - arguments for directives in <msg>.
31
+ */
32
+ skipf := func(msg, ...args) {
33
+ skip(format(msg, args...))
34
+ }
35
+
36
+ /**
37
+ * Fail the test in place. Interrupts execution of single test and prints a
38
+ * failure message to the console log.
39
+ *
40
+ * @param args: []any - message to be written.
41
+ * Each argument is converted to string with its default formatter.
42
+ */
43
+ fail := func(...args) {
44
+ test.fail(args...)
45
+ }
46
+
47
+ /**
48
+ * Formatted version of fail(). failf(msg, ...args) == fail(format(msg, args...))
49
+ *
50
+ * @param msg: string - message with formatting directives.
51
+ * @param args: []any - arguments for directives in <msg>.
52
+ */
53
+ failf := func(msg, ...args) {
54
+ fail(format(msg, args...))
55
+ }
56
+
57
+ /**
58
+ * Write message to console log.
59
+ *
60
+ * @param args: []any - message to be written.
61
+ * Each argument is converted to string with its default formatter.
62
+ */
63
+ log := func(...args) {
64
+ test.log(args...)
65
+ }
66
+
67
+ /**
68
+ * Formatted version of log(). logf(msg, ...args) == log(format(msg, args...))
69
+ *
70
+ * @param msg: string - message with formatting directives.
71
+ * @param args: []any - arguments for directives in <msg>.
72
+ */
73
+ logf := func(msg, ...args) {
74
+ test.log(format(msg, args...))
75
+ }
76
+
77
+ /**
78
+ * Mark test as executed for tengo testing engine.
79
+ *
80
+ * Regular tengo file with tests contains bunch of fuctions starting with 'Test' prefix, like `TestMyFunction := func() { ... }`.
81
+ * You DO NOT need to call this Done() method if you have file with Test* functions.
82
+ *
83
+ * For some rare cases, you may want to define your own custom testing script, that will call functions on its own instead
84
+ * of using the standard test functions naming. In this case, testing engine needs to know the difference between "nothing was called at all"
85
+ * and "everything was done well". This is what this method for.
86
+ *
87
+ * You don't need it in 99.9% of cases.
88
+ *
89
+ * This method does not interrupt test execution and is intended for use in custom test scripts
90
+ * without declared test functions.
91
+ */
92
+ done := func() {
93
+ test.done()
94
+ }
95
+
96
+ //
97
+ // Boolean assertions
98
+ //
99
+
100
+ /**
101
+ * Require <condition> to be true, failing test when not.
102
+ *
103
+ * @param condition: bool
104
+ * @param msg: []any - message to be printed on check failure
105
+ */
106
+ isTrue := func(condition, ...msg) {
107
+ if !condition {
108
+ test.fail("<condition> != 'true': ", msg...)
109
+ }
110
+ }
111
+
112
+ /**
113
+ * Formatted version of isTrue(). isTruef(condition, msg, ...args) == isTrue(condition, format(msg, args...))
114
+ *
115
+ * @param condition: bool
116
+ * @param msg: string - message with formatting directives to be printed on check failure
117
+ * @param args: []any - arguments for formatting directives in <msg>
118
+ */
119
+ isTruef := func(condition, msg, ...args) {
120
+ isTrue(condition, format(msg, args...))
121
+ }
122
+
123
+ /**
124
+ * Require <condition> to be false, failing test when not.
125
+ *
126
+ * @param condition: bool
127
+ * @param args: []any - message to be printed on check failure
128
+ */
129
+ isFalse := func(condition, ...args) {
130
+ if condition {
131
+ test.fail("<condition> != 'false'", args...)
132
+ }
133
+ }
134
+
135
+ /**
136
+ * Formatted version of isFalse(). isFalsef(condition, msg, ..args) == isFalse(condition, format(msg, args...))
137
+ *
138
+ * @param condition: bool
139
+ * @param msg: string - message with formatting directives to be printed on check failure
140
+ * @param args: []any - arguments for formatting directives in <msg>
141
+ */
142
+ isFalsef := func(condition, msg, ...args) {
143
+ isFalse(condition, format(msg, args...))
144
+ }
145
+
146
+ //
147
+ // Equality assertions
148
+ //
149
+
150
+ /**
151
+ * Fails test when <expect> != <value>
152
+ *
153
+ * @param expect: any - expected value for the equality check
154
+ * @param value: any - the value to be checked
155
+ * @param args: []any - the message to be printed on check failure
156
+ */
157
+ isEqual := func(expect, value, ...args) {
158
+ if expect == value {
159
+ return
160
+ }
161
+
162
+ msg := format("%q != %q (expect: %#v, got %#v)", expect, value, expect, value)
163
+
164
+ fail(msg, args...)
165
+ }
166
+
167
+ /**
168
+ * Formatted version of isEqual(). isEqualf(expect, value, msg, ..args) == isEqual(expect, value, format(msg, args...))
169
+ *
170
+ * @param expect: any - expected value for the equality check
171
+ * @param value: any - the value to be checked
172
+ * @param msg: string - message with formatting directives to be printed on check failure
173
+ * @param args: []any - arguments for formatting directives in <msg>
174
+ */
175
+ isEqualf := func(expect, value, msg, ...args) {
176
+ isEqual(expect, value, format(msg, args...))
177
+ }
178
+
179
+ export {
180
+ //
181
+ // Builtin 'test' module method wrappers
182
+ //
183
+ done : done,
184
+ skip : skip,
185
+ skipf : skipf,
186
+ fail : fail,
187
+ failf : failf,
188
+ log : log,
189
+ logf : logf,
190
+
191
+ //
192
+ // Boolean assertions
193
+ //
194
+ isTrue : isTrue,
195
+ isTruef : isTruef,
196
+ isFalse : isFalse,
197
+ isFalsef : isFalsef,
198
+
199
+ //
200
+ // Equality assertions
201
+ //
202
+ isEqual : isEqual,
203
+ isEqualf : isEqualf
204
+ }
Binary file
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@platforma-sdk/workflow-tengo",
3
- "version": "2.3.1",
3
+ "version": "2.4.0",
4
4
  "description": "Tengo SDK library",
5
5
  "types": "./dist/index.d.ts",
6
6
  "main": "./dist/index.js",