@effectionx/bdd 0.3.1 → 0.4.1

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