@effectionx/bdd 0.3.0 → 0.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.
Files changed (67) hide show
  1. package/bdd.test.ts +12 -0
  2. package/bdd.ts +124 -0
  3. package/dist/bdd.d.ts +41 -0
  4. package/dist/bdd.d.ts.map +1 -0
  5. package/dist/bdd.js +77 -0
  6. package/dist/mod.d.ts +2 -0
  7. package/dist/mod.d.ts.map +1 -0
  8. package/dist/mod.js +3 -0
  9. package/dist/mod.node.d.ts +10 -0
  10. package/dist/mod.node.d.ts.map +1 -0
  11. package/dist/mod.node.js +8 -0
  12. package/dist/tsconfig.tsbuildinfo +1 -0
  13. package/mod.deno.ts +128 -0
  14. package/mod.node.ts +10 -0
  15. package/mod.ts +3 -0
  16. package/package.json +20 -18
  17. package/tsconfig.json +14 -0
  18. package/esm/_dnt.shims.d.ts +0 -2
  19. package/esm/_dnt.shims.d.ts.map +0 -1
  20. package/esm/_dnt.shims.js +0 -57
  21. package/esm/deps/jsr.io/@effectionx/test-adapter/0.5.1/box.d.ts +0 -4
  22. package/esm/deps/jsr.io/@effectionx/test-adapter/0.5.1/box.d.ts.map +0 -1
  23. package/esm/deps/jsr.io/@effectionx/test-adapter/0.5.1/box.js +0 -15
  24. package/esm/deps/jsr.io/@effectionx/test-adapter/0.5.1/mod.d.ts +0 -77
  25. package/esm/deps/jsr.io/@effectionx/test-adapter/0.5.1/mod.d.ts.map +0 -1
  26. package/esm/deps/jsr.io/@effectionx/test-adapter/0.5.1/mod.js +0 -89
  27. package/esm/deps/jsr.io/@std/assert/1.0.16/assertion_error.d.ts +0 -26
  28. package/esm/deps/jsr.io/@std/assert/1.0.16/assertion_error.d.ts.map +0 -1
  29. package/esm/deps/jsr.io/@std/assert/1.0.16/assertion_error.js +0 -30
  30. package/esm/deps/jsr.io/@std/internal/1.0.12/assertion_state.d.ts +0 -150
  31. package/esm/deps/jsr.io/@std/internal/1.0.12/assertion_state.d.ts.map +0 -1
  32. package/esm/deps/jsr.io/@std/internal/1.0.12/assertion_state.js +0 -237
  33. package/esm/deps/jsr.io/@std/testing/1.0.16/_test_suite.d.ts +0 -78
  34. package/esm/deps/jsr.io/@std/testing/1.0.16/_test_suite.d.ts.map +0 -1
  35. package/esm/deps/jsr.io/@std/testing/1.0.16/_test_suite.js +0 -385
  36. package/esm/deps/jsr.io/@std/testing/1.0.16/bdd.d.ts +0 -336
  37. package/esm/deps/jsr.io/@std/testing/1.0.16/bdd.d.ts.map +0 -1
  38. package/esm/deps/jsr.io/@std/testing/1.0.16/bdd.js +0 -1057
  39. package/esm/mod.d.ts +0 -26
  40. package/esm/mod.d.ts.map +0 -1
  41. package/esm/mod.js +0 -78
  42. package/esm/package.json +0 -3
  43. package/script/_dnt.shims.d.ts +0 -2
  44. package/script/_dnt.shims.d.ts.map +0 -1
  45. package/script/_dnt.shims.js +0 -60
  46. package/script/deps/jsr.io/@effectionx/test-adapter/0.5.1/box.d.ts +0 -4
  47. package/script/deps/jsr.io/@effectionx/test-adapter/0.5.1/box.d.ts.map +0 -1
  48. package/script/deps/jsr.io/@effectionx/test-adapter/0.5.1/box.js +0 -19
  49. package/script/deps/jsr.io/@effectionx/test-adapter/0.5.1/mod.d.ts +0 -77
  50. package/script/deps/jsr.io/@effectionx/test-adapter/0.5.1/mod.d.ts.map +0 -1
  51. package/script/deps/jsr.io/@effectionx/test-adapter/0.5.1/mod.js +0 -92
  52. package/script/deps/jsr.io/@std/assert/1.0.16/assertion_error.d.ts +0 -26
  53. package/script/deps/jsr.io/@std/assert/1.0.16/assertion_error.d.ts.map +0 -1
  54. package/script/deps/jsr.io/@std/assert/1.0.16/assertion_error.js +0 -34
  55. package/script/deps/jsr.io/@std/internal/1.0.12/assertion_state.d.ts +0 -150
  56. package/script/deps/jsr.io/@std/internal/1.0.12/assertion_state.d.ts.map +0 -1
  57. package/script/deps/jsr.io/@std/internal/1.0.12/assertion_state.js +0 -275
  58. package/script/deps/jsr.io/@std/testing/1.0.16/_test_suite.d.ts +0 -78
  59. package/script/deps/jsr.io/@std/testing/1.0.16/_test_suite.d.ts.map +0 -1
  60. package/script/deps/jsr.io/@std/testing/1.0.16/_test_suite.js +0 -389
  61. package/script/deps/jsr.io/@std/testing/1.0.16/bdd.d.ts +0 -336
  62. package/script/deps/jsr.io/@std/testing/1.0.16/bdd.d.ts.map +0 -1
  63. package/script/deps/jsr.io/@std/testing/1.0.16/bdd.js +0 -1068
  64. package/script/mod.d.ts +0 -26
  65. package/script/mod.d.ts.map +0 -1
  66. package/script/mod.js +0 -84
  67. package/script/package.json +0 -3
@@ -1,385 +0,0 @@
1
- // Copyright 2018-2025 the Deno authors. MIT license.
2
- import { getAssertionState } from "../../internal/1.0.12/assertion_state.js";
3
- import { AssertionError } from "../../assert/1.0.16/assertion_error.js";
4
- export const globalSanitizersState = {
5
- sanitizeExit: undefined,
6
- sanitizeOps: undefined,
7
- sanitizeResources: undefined,
8
- };
9
- const assertionState = getAssertionState();
10
- /**
11
- * An internal representation of a group of tests.
12
- */
13
- export class TestSuiteInternal {
14
- constructor(describe) {
15
- Object.defineProperty(this, "symbol", {
16
- enumerable: true,
17
- configurable: true,
18
- writable: true,
19
- value: void 0
20
- });
21
- Object.defineProperty(this, "describe", {
22
- enumerable: true,
23
- configurable: true,
24
- writable: true,
25
- value: void 0
26
- });
27
- Object.defineProperty(this, "steps", {
28
- enumerable: true,
29
- configurable: true,
30
- writable: true,
31
- value: void 0
32
- });
33
- Object.defineProperty(this, "hasOnlyStep", {
34
- enumerable: true,
35
- configurable: true,
36
- writable: true,
37
- value: void 0
38
- });
39
- this.describe = describe;
40
- this.steps = [];
41
- this.hasOnlyStep = false;
42
- const { suite } = describe;
43
- if (suite && !TestSuiteInternal.suites.has(suite.symbol)) {
44
- throw new Error("Cannot construct Test Suite: suite does not represent a registered test suite");
45
- }
46
- const testSuite = suite
47
- ? TestSuiteInternal.suites.get(suite.symbol)
48
- : TestSuiteInternal.current;
49
- this.symbol = Symbol();
50
- TestSuiteInternal.suites.set(this.symbol, this);
51
- const { fn, ignore } = describe;
52
- if (ignore) {
53
- const { name, only, permissions, sanitizeExit = globalSanitizersState.sanitizeExit, sanitizeOps = globalSanitizersState.sanitizeOps, sanitizeResources = globalSanitizersState.sanitizeResources, } = describe;
54
- const options = {
55
- name,
56
- fn: async () => { },
57
- ignore: true,
58
- };
59
- if (only !== undefined) {
60
- options.only = only;
61
- }
62
- if (permissions !== undefined) {
63
- options.permissions = permissions;
64
- }
65
- if (sanitizeExit !== undefined) {
66
- options.sanitizeExit = sanitizeExit;
67
- }
68
- if (sanitizeOps !== undefined) {
69
- options.sanitizeOps = sanitizeOps;
70
- }
71
- if (sanitizeResources !== undefined) {
72
- options.sanitizeResources = sanitizeResources;
73
- }
74
- TestSuiteInternal.registerTest(options);
75
- return;
76
- }
77
- if (fn) {
78
- const temp = TestSuiteInternal.current;
79
- TestSuiteInternal.current = this;
80
- try {
81
- // deno-lint-ignore no-explicit-any
82
- const value = fn();
83
- if (value instanceof Promise) {
84
- throw new Error('Returning a Promise from "describe" is not supported: tests must be defined synchronously');
85
- }
86
- }
87
- finally {
88
- TestSuiteInternal.current = temp;
89
- }
90
- }
91
- if (testSuite) {
92
- TestSuiteInternal.addStep(testSuite, this);
93
- }
94
- else {
95
- const { name, ignore, permissions, sanitizeExit = globalSanitizersState.sanitizeExit, sanitizeOps = globalSanitizersState.sanitizeOps, sanitizeResources = globalSanitizersState.sanitizeResources, } = describe;
96
- let { only } = describe;
97
- if (!ignore && this.hasOnlyStep) {
98
- only = true;
99
- }
100
- const options = {
101
- name,
102
- fn: async (t) => {
103
- TestSuiteInternal.runningCount++;
104
- try {
105
- const context = {};
106
- const { beforeAll } = this.describe;
107
- if (typeof beforeAll === "function") {
108
- await beforeAll.call(context);
109
- }
110
- else if (beforeAll) {
111
- for (const hook of beforeAll) {
112
- await hook.call(context);
113
- }
114
- }
115
- try {
116
- TestSuiteInternal.active.push(this.symbol);
117
- await TestSuiteInternal.run(this, context, t);
118
- }
119
- finally {
120
- TestSuiteInternal.active.pop();
121
- const { afterAll } = this.describe;
122
- if (typeof afterAll === "function") {
123
- await afterAll.call(context);
124
- }
125
- else if (afterAll) {
126
- for (const hook of afterAll) {
127
- await hook.call(context);
128
- }
129
- }
130
- }
131
- }
132
- finally {
133
- TestSuiteInternal.runningCount--;
134
- }
135
- },
136
- };
137
- if (ignore !== undefined) {
138
- options.ignore = ignore;
139
- }
140
- if (only !== undefined) {
141
- options.only = only;
142
- }
143
- if (permissions !== undefined) {
144
- options.permissions = permissions;
145
- }
146
- if (sanitizeExit !== undefined) {
147
- options.sanitizeExit = sanitizeExit;
148
- }
149
- if (sanitizeOps !== undefined) {
150
- options.sanitizeOps = sanitizeOps;
151
- }
152
- if (sanitizeResources !== undefined) {
153
- options.sanitizeResources = sanitizeResources;
154
- }
155
- TestSuiteInternal.registerTest(options);
156
- }
157
- }
158
- /** This is used internally for testing this module. */
159
- static reset() {
160
- TestSuiteInternal.runningCount = 0;
161
- TestSuiteInternal.started = false;
162
- TestSuiteInternal.current = null;
163
- TestSuiteInternal.active = [];
164
- }
165
- /** This is used internally to register tests. */
166
- static registerTest(options) {
167
- options = { ...options };
168
- if (options.only === undefined) {
169
- delete options.only;
170
- }
171
- if (options.permissions === undefined) {
172
- delete options.permissions;
173
- }
174
- if (options.ignore === undefined) {
175
- delete options.ignore;
176
- }
177
- if (options.sanitizeExit === undefined) {
178
- delete options.sanitizeExit;
179
- }
180
- if (options.sanitizeOps === undefined) {
181
- delete options.sanitizeOps;
182
- }
183
- if (options.sanitizeResources === undefined) {
184
- delete options.sanitizeResources;
185
- }
186
- Deno.test(options);
187
- }
188
- /** Updates all steps within top level suite to have ignore set to true if only is not set to true on step. */
189
- static addingOnlyStep(suite) {
190
- if (!suite.hasOnlyStep) {
191
- for (let i = 0; i < suite.steps.length; i++) {
192
- const step = suite.steps[i];
193
- if (!(step instanceof TestSuiteInternal) && !step.only) {
194
- suite.steps.splice(i--, 1);
195
- }
196
- }
197
- suite.hasOnlyStep = true;
198
- }
199
- const parentSuite = suite.describe.suite;
200
- const parentTestSuite = parentSuite &&
201
- TestSuiteInternal.suites.get(parentSuite.symbol);
202
- if (parentTestSuite) {
203
- TestSuiteInternal.addingOnlyStep(parentTestSuite);
204
- }
205
- }
206
- /** This is used internally to add steps to a test suite. */
207
- static addStep(suite, step) {
208
- if (!suite.hasOnlyStep) {
209
- if (step instanceof TestSuiteInternal) {
210
- if (step.hasOnlyStep || step.describe.only) {
211
- TestSuiteInternal.addingOnlyStep(suite);
212
- }
213
- }
214
- else {
215
- if (step.only)
216
- TestSuiteInternal.addingOnlyStep(suite);
217
- }
218
- }
219
- if (!(suite.hasOnlyStep && !(step instanceof TestSuiteInternal) && !step.only)) {
220
- suite.steps.push(step);
221
- }
222
- }
223
- /** This is used internally to add hooks to a test suite. */
224
- static setHook(suite, name, fn) {
225
- if (suite.describe[name]) {
226
- if (typeof suite.describe[name] === "function") {
227
- suite.describe[name] = [
228
- suite.describe[name],
229
- ];
230
- }
231
- suite.describe[name].push(fn);
232
- }
233
- else {
234
- suite.describe[name] = fn;
235
- }
236
- }
237
- /** This is used internally to run all steps for a test suite. */
238
- static async run(suite, context, t) {
239
- const hasOnly = suite.hasOnlyStep || suite.describe.only || false;
240
- for (const step of suite.steps) {
241
- if (hasOnly && step instanceof TestSuiteInternal &&
242
- !(step.hasOnlyStep || step.describe.only || false)) {
243
- continue;
244
- }
245
- const { name, fn, ignore, permissions, sanitizeExit = globalSanitizersState.sanitizeExit, sanitizeOps = globalSanitizersState.sanitizeOps, sanitizeResources = globalSanitizersState.sanitizeResources, } = step instanceof TestSuiteInternal ? step.describe : step;
246
- const options = {
247
- name,
248
- fn: async (t) => {
249
- if (permissions) {
250
- throw new Error(
251
- // deno-lint-ignore deno-style-guide/error-message
252
- "permissions option not available for nested tests");
253
- }
254
- context = { ...context };
255
- if (step instanceof TestSuiteInternal) {
256
- const { beforeAll } = step.describe;
257
- if (typeof beforeAll === "function") {
258
- await beforeAll.call(context);
259
- }
260
- else if (beforeAll) {
261
- for (const hook of beforeAll) {
262
- await hook.call(context);
263
- }
264
- }
265
- try {
266
- TestSuiteInternal.active.push(step.symbol);
267
- await TestSuiteInternal.run(step, context, t);
268
- }
269
- finally {
270
- TestSuiteInternal.active.pop();
271
- const { afterAll } = step.describe;
272
- if (typeof afterAll === "function") {
273
- await afterAll.call(context);
274
- }
275
- else if (afterAll) {
276
- for (const hook of afterAll) {
277
- await hook.call(context);
278
- }
279
- }
280
- }
281
- }
282
- else {
283
- await TestSuiteInternal.runTest(t, fn, context);
284
- }
285
- },
286
- };
287
- if (ignore !== undefined) {
288
- options.ignore = ignore;
289
- }
290
- if (sanitizeExit !== undefined) {
291
- options.sanitizeExit = sanitizeExit;
292
- }
293
- if (sanitizeOps !== undefined) {
294
- options.sanitizeOps = sanitizeOps;
295
- }
296
- if (sanitizeResources !== undefined) {
297
- options.sanitizeResources = sanitizeResources;
298
- }
299
- await t.step(options);
300
- }
301
- }
302
- static async runTest(t, fn, context, activeIndex = 0) {
303
- const suite = TestSuiteInternal.active[activeIndex];
304
- const testSuite = suite && TestSuiteInternal.suites.get(suite);
305
- if (testSuite) {
306
- if (activeIndex === 0)
307
- context = { ...context };
308
- const { beforeEach } = testSuite.describe;
309
- if (typeof beforeEach === "function") {
310
- await beforeEach.call(context);
311
- }
312
- else if (beforeEach) {
313
- for (const hook of beforeEach) {
314
- await hook.call(context);
315
- }
316
- }
317
- try {
318
- await TestSuiteInternal.runTest(t, fn, context, activeIndex + 1);
319
- }
320
- finally {
321
- const { afterEach } = testSuite.describe;
322
- if (typeof afterEach === "function") {
323
- await afterEach.call(context);
324
- }
325
- else if (afterEach) {
326
- for (const hook of afterEach) {
327
- await hook.call(context);
328
- }
329
- }
330
- }
331
- }
332
- else {
333
- await fn.call(context, t);
334
- }
335
- try {
336
- if (assertionState.checkAssertionErrorState()) {
337
- throw new AssertionError("Expected at least one assertion to be called but received none");
338
- }
339
- if (assertionState.checkAssertionCountSatisfied()) {
340
- throw new AssertionError(`Expected exactly ${assertionState.assertionCount} ${assertionState.assertionCount === 1 ? "assertion" : "assertions"} to be called, ` +
341
- `but received ${assertionState.assertionTriggeredCount}`);
342
- }
343
- }
344
- finally {
345
- assertionState.resetAssertionState();
346
- }
347
- }
348
- }
349
- /** Stores how many test suites are executing. */
350
- Object.defineProperty(TestSuiteInternal, "runningCount", {
351
- enumerable: true,
352
- configurable: true,
353
- writable: true,
354
- value: 0
355
- });
356
- /** If a test has been registered yet. Block adding global hooks if a test has been registered. */
357
- Object.defineProperty(TestSuiteInternal, "started", {
358
- enumerable: true,
359
- configurable: true,
360
- writable: true,
361
- value: false
362
- });
363
- /** A map of all test suites by symbol. */
364
- // deno-lint-ignore no-explicit-any
365
- Object.defineProperty(TestSuiteInternal, "suites", {
366
- enumerable: true,
367
- configurable: true,
368
- writable: true,
369
- value: new Map()
370
- });
371
- /** The current test suite being registered. */
372
- // deno-lint-ignore no-explicit-any
373
- Object.defineProperty(TestSuiteInternal, "current", {
374
- enumerable: true,
375
- configurable: true,
376
- writable: true,
377
- value: null
378
- });
379
- /** The stack of tests that are actively running. */
380
- Object.defineProperty(TestSuiteInternal, "active", {
381
- enumerable: true,
382
- configurable: true,
383
- writable: true,
384
- value: []
385
- });