@effectionx/bdd 0.1.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/README.md +171 -0
- package/esm/_dnt.shims.d.ts +2 -0
- package/esm/_dnt.shims.d.ts.map +1 -0
- package/esm/_dnt.shims.js +57 -0
- package/esm/deps/jsr.io/@std/assert/1.0.14/assertion_error.d.ts +26 -0
- package/esm/deps/jsr.io/@std/assert/1.0.14/assertion_error.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.14/assertion_error.js +30 -0
- package/esm/deps/jsr.io/@std/internal/1.0.10/assertion_state.d.ts +150 -0
- package/esm/deps/jsr.io/@std/internal/1.0.10/assertion_state.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/internal/1.0.10/assertion_state.js +237 -0
- package/esm/deps/jsr.io/@std/testing/1.0.15/_test_suite.d.ts +78 -0
- package/esm/deps/jsr.io/@std/testing/1.0.15/_test_suite.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/testing/1.0.15/_test_suite.js +385 -0
- package/esm/deps/jsr.io/@std/testing/1.0.15/bdd.d.ts +336 -0
- package/esm/deps/jsr.io/@std/testing/1.0.15/bdd.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/testing/1.0.15/bdd.js +1057 -0
- package/esm/mod.d.ts +13 -0
- package/esm/mod.d.ts.map +1 -0
- package/esm/mod.js +47 -0
- package/esm/package.json +3 -0
- package/package.json +31 -0
- package/script/_dnt.shims.d.ts +2 -0
- package/script/_dnt.shims.d.ts.map +1 -0
- package/script/_dnt.shims.js +60 -0
- package/script/deps/jsr.io/@std/assert/1.0.14/assertion_error.d.ts +26 -0
- package/script/deps/jsr.io/@std/assert/1.0.14/assertion_error.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/assert/1.0.14/assertion_error.js +34 -0
- package/script/deps/jsr.io/@std/internal/1.0.10/assertion_state.d.ts +150 -0
- package/script/deps/jsr.io/@std/internal/1.0.10/assertion_state.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/internal/1.0.10/assertion_state.js +275 -0
- package/script/deps/jsr.io/@std/testing/1.0.15/_test_suite.d.ts +78 -0
- package/script/deps/jsr.io/@std/testing/1.0.15/_test_suite.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/testing/1.0.15/_test_suite.js +389 -0
- package/script/deps/jsr.io/@std/testing/1.0.15/bdd.d.ts +336 -0
- package/script/deps/jsr.io/@std/testing/1.0.15/bdd.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/testing/1.0.15/bdd.js +1068 -0
- package/script/mod.d.ts +13 -0
- package/script/mod.d.ts.map +1 -0
- package/script/mod.js +52 -0
- package/script/package.json +3 -0
package/README.md
ADDED
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
# @effectionx/bdd
|
|
2
|
+
|
|
3
|
+
A BDD (Behavior-Driven Development) testing harness for Deno that integrates
|
|
4
|
+
seamlessly with [Effection](https://github.com/thefrontside/effection)
|
|
5
|
+
operations. This package provides a familiar `describe`/`it`/`beforeEach` API
|
|
6
|
+
that works natively with Effection's generator-based operations.
|
|
7
|
+
|
|
8
|
+
## Features
|
|
9
|
+
|
|
10
|
+
- ๐ **Native Effection Support**: Test functions can be generator functions
|
|
11
|
+
that yield operations
|
|
12
|
+
- ๐๏ธ **Familiar BDD API**: Uses the standard `describe`, `it`, and `beforeEach`
|
|
13
|
+
functions you know and love
|
|
14
|
+
- ๐งน **Automatic Cleanup**: Proper resource management and cleanup for Effection
|
|
15
|
+
operations
|
|
16
|
+
- ๐ฏ **Skip and Only**: Full support for `.skip` and `.only` modifiers
|
|
17
|
+
- ๐ฆ **Zero Configuration**: Works out of the box with Deno's built-in testing
|
|
18
|
+
framework
|
|
19
|
+
|
|
20
|
+
## Installation
|
|
21
|
+
|
|
22
|
+
Add to your `deno.json` imports:
|
|
23
|
+
|
|
24
|
+
```json
|
|
25
|
+
{
|
|
26
|
+
"imports": {
|
|
27
|
+
"@effectionx/bdd": "npm:@effectionx/bdd"
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Basic Usage
|
|
33
|
+
|
|
34
|
+
```typescript
|
|
35
|
+
import { beforeEach, describe, it } from "@effectionx/bdd";
|
|
36
|
+
import { expect } from "@std/expect";
|
|
37
|
+
import { sleep, spawn } from "effection";
|
|
38
|
+
import { createSignal, is } from "@effectionx/signals";
|
|
39
|
+
|
|
40
|
+
describe("My async operations", () => {
|
|
41
|
+
let counter: ReturnType<typeof createSignal<number, void>>;
|
|
42
|
+
|
|
43
|
+
beforeEach(function* () {
|
|
44
|
+
// Setup that runs before each test
|
|
45
|
+
counter = yield* createSignal(0);
|
|
46
|
+
yield* sleep(10); // Can use Effection operations in setup
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it("should increment counter", function* () {
|
|
50
|
+
// Test function is a generator that can yield operations
|
|
51
|
+
counter.update((n) => n + 1);
|
|
52
|
+
yield* is(counter, (value) => value === 1);
|
|
53
|
+
expect(counter.valueOf()).toBe(1);
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## Real-World Examples
|
|
59
|
+
|
|
60
|
+
The following packages have been migrated to use `@effectionx/bdd` and provide
|
|
61
|
+
excellent examples of testing patterns:
|
|
62
|
+
|
|
63
|
+
- **stream-helpers**: See [`batch.test.ts`](../stream-helpers/batch.test.ts) for
|
|
64
|
+
testing stream batching with time and size limits
|
|
65
|
+
- **signals**: See [`array.test.ts`](../signals/array.test.ts) for testing array
|
|
66
|
+
signal operations like push, set, and update
|
|
67
|
+
- **timebox**: See [`timebox.test.ts`](../timebox/timebox.test.ts) for testing
|
|
68
|
+
timeout scenarios with both success and timeout cases
|
|
69
|
+
- **task-buffer**: See
|
|
70
|
+
[`task-buffer.test.ts`](../task-buffer/task-buffer.test.ts) for testing task
|
|
71
|
+
queuing and buffer management
|
|
72
|
+
- **websocket**: See [`websocket.test.ts`](../websocket/websocket.test.ts) for
|
|
73
|
+
testing bidirectional WebSocket communication and connection lifecycle
|
|
74
|
+
- **worker**: See [`worker.test.ts`](../worker/worker.test.ts) for testing web
|
|
75
|
+
worker communication, error handling, and lifecycle management
|
|
76
|
+
|
|
77
|
+
### Common Patterns Demonstrated
|
|
78
|
+
|
|
79
|
+
These test files show how to:
|
|
80
|
+
|
|
81
|
+
- **Handle async operations** without `run()` wrappers
|
|
82
|
+
- **Test error scenarios** using try/catch blocks instead of Promise rejections
|
|
83
|
+
- **Use `beforeEach`** for test setup with Effection operations
|
|
84
|
+
- **Wait for signal changes** using the `is` helper
|
|
85
|
+
- **Test resource cleanup** and proper teardown
|
|
86
|
+
- **Handle timeouts and concurrent operations**
|
|
87
|
+
|
|
88
|
+
## API Reference
|
|
89
|
+
|
|
90
|
+
### `describe(name: string, body: () => void)`
|
|
91
|
+
|
|
92
|
+
Creates a test suite with the given name. Test suites can be nested.
|
|
93
|
+
|
|
94
|
+
**Options:**
|
|
95
|
+
|
|
96
|
+
- `describe.skip()` - Skip this test suite
|
|
97
|
+
- `describe.only()` - Run only this test suite
|
|
98
|
+
|
|
99
|
+
### `it(desc: string, body?: () => Operation<void>)`
|
|
100
|
+
|
|
101
|
+
Creates a test case with the given description. The body function should be a
|
|
102
|
+
generator function that can yield Effection operations.
|
|
103
|
+
|
|
104
|
+
**Options:**
|
|
105
|
+
|
|
106
|
+
- `it.skip()` - Skip this test case
|
|
107
|
+
- `it.only()` - Run only this test case
|
|
108
|
+
|
|
109
|
+
**Parameters:**
|
|
110
|
+
|
|
111
|
+
- `desc` - Description of what the test should do
|
|
112
|
+
- `body` - Generator function containing the test logic (optional for pending
|
|
113
|
+
tests)
|
|
114
|
+
|
|
115
|
+
### `beforeEach(body: () => Operation<void>)`
|
|
116
|
+
|
|
117
|
+
Registers a setup function that runs before each test in the current suite. The
|
|
118
|
+
body function should be a generator function that can yield Effection
|
|
119
|
+
operations.
|
|
120
|
+
|
|
121
|
+
### ~~`afterEach`~~
|
|
122
|
+
|
|
123
|
+
This package doesn't include `afterEach` because it's typically used for clean
|
|
124
|
+
up. With Effection, clean up is done in `finally` block of the resource.
|
|
125
|
+
Consider creating a resource in beforeEach if you encounter a need for
|
|
126
|
+
`afterEach`.
|
|
127
|
+
|
|
128
|
+
### `beforeAll`
|
|
129
|
+
|
|
130
|
+
Is not implemented yet.
|
|
131
|
+
|
|
132
|
+
## Migration from Standard Deno Testing
|
|
133
|
+
|
|
134
|
+
If you're migrating from standard Deno testing with Effection, the changes are
|
|
135
|
+
minimal:
|
|
136
|
+
|
|
137
|
+
**Before:**
|
|
138
|
+
|
|
139
|
+
```typescript
|
|
140
|
+
import { describe, it } from "@std/testing/bdd";
|
|
141
|
+
import { run } from "effection";
|
|
142
|
+
|
|
143
|
+
describe("my tests", () => {
|
|
144
|
+
it("should work", async () => {
|
|
145
|
+
await run(function* () {
|
|
146
|
+
const result = yield* someOperation();
|
|
147
|
+
expect(result).toBe("success");
|
|
148
|
+
});
|
|
149
|
+
});
|
|
150
|
+
});
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
**After:**
|
|
154
|
+
|
|
155
|
+
```typescript
|
|
156
|
+
import { describe, it } from "@effectionx/bdd";
|
|
157
|
+
// No need to import 'run'
|
|
158
|
+
|
|
159
|
+
describe("my tests", () => {
|
|
160
|
+
it("should work", function* () {
|
|
161
|
+
const result = yield* someOperation();
|
|
162
|
+
expect(result).toBe("success");
|
|
163
|
+
});
|
|
164
|
+
});
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
## Contributing
|
|
168
|
+
|
|
169
|
+
This package is part of the
|
|
170
|
+
[Effection](https://github.com/thefrontside/effection) ecosystem. Contributions
|
|
171
|
+
are welcome!
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_dnt.shims.d.ts","sourceRoot":"","sources":["../src/_dnt.shims.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,aAAa,gCAA2C,CAAC"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
const dntGlobals = {};
|
|
2
|
+
export const dntGlobalThis = createMergeProxy(globalThis, dntGlobals);
|
|
3
|
+
function createMergeProxy(baseObj, extObj) {
|
|
4
|
+
return new Proxy(baseObj, {
|
|
5
|
+
get(_target, prop, _receiver) {
|
|
6
|
+
if (prop in extObj) {
|
|
7
|
+
return extObj[prop];
|
|
8
|
+
}
|
|
9
|
+
else {
|
|
10
|
+
return baseObj[prop];
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
set(_target, prop, value) {
|
|
14
|
+
if (prop in extObj) {
|
|
15
|
+
delete extObj[prop];
|
|
16
|
+
}
|
|
17
|
+
baseObj[prop] = value;
|
|
18
|
+
return true;
|
|
19
|
+
},
|
|
20
|
+
deleteProperty(_target, prop) {
|
|
21
|
+
let success = false;
|
|
22
|
+
if (prop in extObj) {
|
|
23
|
+
delete extObj[prop];
|
|
24
|
+
success = true;
|
|
25
|
+
}
|
|
26
|
+
if (prop in baseObj) {
|
|
27
|
+
delete baseObj[prop];
|
|
28
|
+
success = true;
|
|
29
|
+
}
|
|
30
|
+
return success;
|
|
31
|
+
},
|
|
32
|
+
ownKeys(_target) {
|
|
33
|
+
const baseKeys = Reflect.ownKeys(baseObj);
|
|
34
|
+
const extKeys = Reflect.ownKeys(extObj);
|
|
35
|
+
const extKeysSet = new Set(extKeys);
|
|
36
|
+
return [...baseKeys.filter((k) => !extKeysSet.has(k)), ...extKeys];
|
|
37
|
+
},
|
|
38
|
+
defineProperty(_target, prop, desc) {
|
|
39
|
+
if (prop in extObj) {
|
|
40
|
+
delete extObj[prop];
|
|
41
|
+
}
|
|
42
|
+
Reflect.defineProperty(baseObj, prop, desc);
|
|
43
|
+
return true;
|
|
44
|
+
},
|
|
45
|
+
getOwnPropertyDescriptor(_target, prop) {
|
|
46
|
+
if (prop in extObj) {
|
|
47
|
+
return Reflect.getOwnPropertyDescriptor(extObj, prop);
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
return Reflect.getOwnPropertyDescriptor(baseObj, prop);
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
has(_target, prop) {
|
|
54
|
+
return prop in extObj || prop in baseObj;
|
|
55
|
+
},
|
|
56
|
+
});
|
|
57
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Error thrown when an assertion fails.
|
|
3
|
+
*
|
|
4
|
+
* @example Usage
|
|
5
|
+
* ```ts ignore
|
|
6
|
+
* import { AssertionError } from "@std/assert";
|
|
7
|
+
*
|
|
8
|
+
* try {
|
|
9
|
+
* throw new AssertionError("foo", { cause: "bar" });
|
|
10
|
+
* } catch (error) {
|
|
11
|
+
* if (error instanceof AssertionError) {
|
|
12
|
+
* error.message === "foo"; // true
|
|
13
|
+
* error.cause === "bar"; // true
|
|
14
|
+
* }
|
|
15
|
+
* }
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export declare class AssertionError extends Error {
|
|
19
|
+
/** Constructs a new instance.
|
|
20
|
+
*
|
|
21
|
+
* @param message The error message.
|
|
22
|
+
* @param options Additional options. This argument is still unstable. It may change in the future release.
|
|
23
|
+
*/
|
|
24
|
+
constructor(message: string, options?: ErrorOptions);
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=assertion_error.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assertion_error.d.ts","sourceRoot":"","sources":["../../../../../../src/deps/jsr.io/@std/assert/1.0.14/assertion_error.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;;;;GAgBG;AACH,qBAAa,cAAe,SAAQ,KAAK;IACvC;;;;OAIG;gBACS,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY;CAIpD"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// Copyright 2018-2025 the Deno authors. MIT license.
|
|
2
|
+
// This module is browser compatible.
|
|
3
|
+
/**
|
|
4
|
+
* Error thrown when an assertion fails.
|
|
5
|
+
*
|
|
6
|
+
* @example Usage
|
|
7
|
+
* ```ts ignore
|
|
8
|
+
* import { AssertionError } from "@std/assert";
|
|
9
|
+
*
|
|
10
|
+
* try {
|
|
11
|
+
* throw new AssertionError("foo", { cause: "bar" });
|
|
12
|
+
* } catch (error) {
|
|
13
|
+
* if (error instanceof AssertionError) {
|
|
14
|
+
* error.message === "foo"; // true
|
|
15
|
+
* error.cause === "bar"; // true
|
|
16
|
+
* }
|
|
17
|
+
* }
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export class AssertionError extends Error {
|
|
21
|
+
/** Constructs a new instance.
|
|
22
|
+
*
|
|
23
|
+
* @param message The error message.
|
|
24
|
+
* @param options Additional options. This argument is still unstable. It may change in the future release.
|
|
25
|
+
*/
|
|
26
|
+
constructor(message, options) {
|
|
27
|
+
super(message, options);
|
|
28
|
+
this.name = "AssertionError";
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
export declare class AssertionState {
|
|
2
|
+
#private;
|
|
3
|
+
constructor();
|
|
4
|
+
/**
|
|
5
|
+
* Get the number that through `expect.assertions` api set.
|
|
6
|
+
*
|
|
7
|
+
* @returns the number that through `expect.assertions` api set.
|
|
8
|
+
*
|
|
9
|
+
* @example Usage
|
|
10
|
+
* ```ts ignore
|
|
11
|
+
* import { AssertionState } from "@std/internal";
|
|
12
|
+
*
|
|
13
|
+
* const assertionState = new AssertionState();
|
|
14
|
+
* assertionState.assertionCount;
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
get assertionCount(): number | undefined;
|
|
18
|
+
/**
|
|
19
|
+
* Get a certain number that assertions were called before.
|
|
20
|
+
*
|
|
21
|
+
* @returns return a certain number that assertions were called before.
|
|
22
|
+
*
|
|
23
|
+
* @example Usage
|
|
24
|
+
* ```ts ignore
|
|
25
|
+
* import { AssertionState } from "@std/internal";
|
|
26
|
+
*
|
|
27
|
+
* const assertionState = new AssertionState();
|
|
28
|
+
* assertionState.assertionTriggeredCount;
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
get assertionTriggeredCount(): number;
|
|
32
|
+
/**
|
|
33
|
+
* If `expect.hasAssertions` called, then through this method to update #state.assertionCheck value.
|
|
34
|
+
*
|
|
35
|
+
* @param val Set #state.assertionCheck's value
|
|
36
|
+
*
|
|
37
|
+
* @example Usage
|
|
38
|
+
* ```ts ignore
|
|
39
|
+
* import { AssertionState } from "@std/internal";
|
|
40
|
+
*
|
|
41
|
+
* const assertionState = new AssertionState();
|
|
42
|
+
* assertionState.setAssertionCheck(true);
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
setAssertionCheck(val: boolean): void;
|
|
46
|
+
/**
|
|
47
|
+
* If any matchers was called, `#state.assertionTriggered` will be set through this method.
|
|
48
|
+
*
|
|
49
|
+
* @param val Set #state.assertionTriggered's value
|
|
50
|
+
*
|
|
51
|
+
* @example Usage
|
|
52
|
+
* ```ts ignore
|
|
53
|
+
* import { AssertionState } from "@std/internal";
|
|
54
|
+
*
|
|
55
|
+
* const assertionState = new AssertionState();
|
|
56
|
+
* assertionState.setAssertionTriggered(true);
|
|
57
|
+
* ```
|
|
58
|
+
*/
|
|
59
|
+
setAssertionTriggered(val: boolean): void;
|
|
60
|
+
/**
|
|
61
|
+
* If `expect.assertions` called, then through this method to update #state.assertionCheck value.
|
|
62
|
+
*
|
|
63
|
+
* @param num Set #state.assertionCount's value, for example if the value is set 2, that means
|
|
64
|
+
* you must have two assertion matchers call in your test suite.
|
|
65
|
+
*
|
|
66
|
+
* @example Usage
|
|
67
|
+
* ```ts ignore
|
|
68
|
+
* import { AssertionState } from "@std/internal";
|
|
69
|
+
*
|
|
70
|
+
* const assertionState = new AssertionState();
|
|
71
|
+
* assertionState.setAssertionCount(2);
|
|
72
|
+
* ```
|
|
73
|
+
*/
|
|
74
|
+
setAssertionCount(num: number): void;
|
|
75
|
+
/**
|
|
76
|
+
* If any matchers was called, `#state.assertionTriggeredCount` value will plus one internally.
|
|
77
|
+
*
|
|
78
|
+
* @example Usage
|
|
79
|
+
* ```ts ignore
|
|
80
|
+
* import { AssertionState } from "@std/internal";
|
|
81
|
+
*
|
|
82
|
+
* const assertionState = new AssertionState();
|
|
83
|
+
* assertionState.updateAssertionTriggerCount();
|
|
84
|
+
* ```
|
|
85
|
+
*/
|
|
86
|
+
updateAssertionTriggerCount(): void;
|
|
87
|
+
/**
|
|
88
|
+
* Check Assertion internal state, if `#state.assertionCheck` is set true, but
|
|
89
|
+
* `#state.assertionTriggered` is still false, then should throw an Assertion Error.
|
|
90
|
+
*
|
|
91
|
+
* @returns a boolean value, that the test suite is satisfied with the check. If not,
|
|
92
|
+
* it should throw an AssertionError.
|
|
93
|
+
*
|
|
94
|
+
* @example Usage
|
|
95
|
+
* ```ts ignore
|
|
96
|
+
* import { AssertionState } from "@std/internal";
|
|
97
|
+
*
|
|
98
|
+
* const assertionState = new AssertionState();
|
|
99
|
+
* if (assertionState.checkAssertionErrorState()) {
|
|
100
|
+
* // throw AssertionError("");
|
|
101
|
+
* }
|
|
102
|
+
* ```
|
|
103
|
+
*/
|
|
104
|
+
checkAssertionErrorState(): boolean;
|
|
105
|
+
/**
|
|
106
|
+
* Reset all assertion state when every test suite function ran completely.
|
|
107
|
+
*
|
|
108
|
+
* @example Usage
|
|
109
|
+
* ```ts ignore
|
|
110
|
+
* import { AssertionState } from "@std/internal";
|
|
111
|
+
*
|
|
112
|
+
* const assertionState = new AssertionState();
|
|
113
|
+
* assertionState.resetAssertionState();
|
|
114
|
+
* ```
|
|
115
|
+
*/
|
|
116
|
+
resetAssertionState(): void;
|
|
117
|
+
/**
|
|
118
|
+
* Check Assertion called state, if `#state.assertionCount` is set to a number value, but
|
|
119
|
+
* `#state.assertionTriggeredCount` is less then it, then should throw an assertion error.
|
|
120
|
+
*
|
|
121
|
+
* @returns a boolean value, that the test suite is satisfied with the check. If not,
|
|
122
|
+
* it should throw an AssertionError.
|
|
123
|
+
*
|
|
124
|
+
* @example Usage
|
|
125
|
+
* ```ts ignore
|
|
126
|
+
* import { AssertionState } from "@std/internal";
|
|
127
|
+
*
|
|
128
|
+
* const assertionState = new AssertionState();
|
|
129
|
+
* if (assertionState.checkAssertionCountSatisfied()) {
|
|
130
|
+
* // throw AssertionError("");
|
|
131
|
+
* }
|
|
132
|
+
* ```
|
|
133
|
+
*/
|
|
134
|
+
checkAssertionCountSatisfied(): boolean;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* return an instance of AssertionState
|
|
138
|
+
*
|
|
139
|
+
* @returns AssertionState
|
|
140
|
+
*
|
|
141
|
+
* @example Usage
|
|
142
|
+
* ```ts ignore
|
|
143
|
+
* import { getAssertionState } from "@std/internal";
|
|
144
|
+
*
|
|
145
|
+
* const assertionState = getAssertionState();
|
|
146
|
+
* assertionState.setAssertionTriggered(true);
|
|
147
|
+
* ```
|
|
148
|
+
*/
|
|
149
|
+
export declare function getAssertionState(): AssertionState;
|
|
150
|
+
//# sourceMappingURL=assertion_state.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assertion_state.d.ts","sourceRoot":"","sources":["../../../../../../src/deps/jsr.io/@std/internal/1.0.10/assertion_state.ts"],"names":[],"mappings":"AAeA,qBAAa,cAAc;;;IAgDzB;;;;;;;;;;;;OAYG;IACH,IAAI,cAAc,IAAI,MAAM,GAAG,SAAS,CAEvC;IAED;;;;;;;;;;;;OAYG;IACH,IAAI,uBAAuB,IAAI,MAAM,CAEpC;IAED;;;;;;;;;;;;OAYG;IACH,iBAAiB,CAAC,GAAG,EAAE,OAAO;IAI9B;;;;;;;;;;;;OAYG;IACH,qBAAqB,CAAC,GAAG,EAAE,OAAO;IAIlC;;;;;;;;;;;;;OAaG;IACH,iBAAiB,CAAC,GAAG,EAAE,MAAM;IAI7B;;;;;;;;;;OAUG;IACH,2BAA2B;IAM3B;;;;;;;;;;;;;;;;OAgBG;IACH,wBAAwB,IAAI,OAAO;IAInC;;;;;;;;;;OAUG;IACH,mBAAmB,IAAI,IAAI;IAS3B;;;;;;;;;;;;;;;;OAgBG;IACH,4BAA4B,IAAI,OAAO;CAIxC;AAID;;;;;;;;;;;;GAYG;AACH,wBAAgB,iBAAiB,IAAI,cAAc,CAElD"}
|
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
// Copyright 2018-2025 the Deno authors. MIT license.
|
|
2
|
+
// This module is browser compatible.
|
|
3
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
4
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
5
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
6
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
7
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
8
|
+
};
|
|
9
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
10
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
11
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
12
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
13
|
+
};
|
|
14
|
+
var _AssertionState_instances, _AssertionState_state, _AssertionState_ensureCleanedUp;
|
|
15
|
+
/**
|
|
16
|
+
* Check the test suite internal state
|
|
17
|
+
*
|
|
18
|
+
* @example Usage
|
|
19
|
+
* ```ts ignore
|
|
20
|
+
* import { AssertionState } from "@std/internal";
|
|
21
|
+
*
|
|
22
|
+
* const assertionState = new AssertionState();
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
import * as dntShim from "../../../../../_dnt.shims.js";
|
|
26
|
+
export class AssertionState {
|
|
27
|
+
constructor() {
|
|
28
|
+
_AssertionState_instances.add(this);
|
|
29
|
+
_AssertionState_state.set(this, void 0);
|
|
30
|
+
__classPrivateFieldSet(this, _AssertionState_state, {
|
|
31
|
+
assertionCount: undefined,
|
|
32
|
+
assertionCheck: false,
|
|
33
|
+
assertionTriggered: false,
|
|
34
|
+
assertionTriggeredCount: 0,
|
|
35
|
+
}, "f");
|
|
36
|
+
if (typeof globalThis?.addEventListener === "function") {
|
|
37
|
+
globalThis.addEventListener("unload", () => {
|
|
38
|
+
__classPrivateFieldGet(this, _AssertionState_instances, "m", _AssertionState_ensureCleanedUp).call(this);
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
else if (
|
|
42
|
+
// deno-lint-ignore no-explicit-any
|
|
43
|
+
typeof dntShim.dntGlobalThis?.process?.on === "function") {
|
|
44
|
+
// deno-lint-ignore no-explicit-any
|
|
45
|
+
dntShim.dntGlobalThis.process.on("exit", () => {
|
|
46
|
+
__classPrivateFieldGet(this, _AssertionState_instances, "m", _AssertionState_ensureCleanedUp).call(this);
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
// deno-lint-ignore no-console
|
|
51
|
+
console.warn("AssertionCounter cleanup step was not registered");
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Get the number that through `expect.assertions` api set.
|
|
56
|
+
*
|
|
57
|
+
* @returns the number that through `expect.assertions` api set.
|
|
58
|
+
*
|
|
59
|
+
* @example Usage
|
|
60
|
+
* ```ts ignore
|
|
61
|
+
* import { AssertionState } from "@std/internal";
|
|
62
|
+
*
|
|
63
|
+
* const assertionState = new AssertionState();
|
|
64
|
+
* assertionState.assertionCount;
|
|
65
|
+
* ```
|
|
66
|
+
*/
|
|
67
|
+
get assertionCount() {
|
|
68
|
+
return __classPrivateFieldGet(this, _AssertionState_state, "f").assertionCount;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Get a certain number that assertions were called before.
|
|
72
|
+
*
|
|
73
|
+
* @returns return a certain number that assertions were called before.
|
|
74
|
+
*
|
|
75
|
+
* @example Usage
|
|
76
|
+
* ```ts ignore
|
|
77
|
+
* import { AssertionState } from "@std/internal";
|
|
78
|
+
*
|
|
79
|
+
* const assertionState = new AssertionState();
|
|
80
|
+
* assertionState.assertionTriggeredCount;
|
|
81
|
+
* ```
|
|
82
|
+
*/
|
|
83
|
+
get assertionTriggeredCount() {
|
|
84
|
+
return __classPrivateFieldGet(this, _AssertionState_state, "f").assertionTriggeredCount;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* If `expect.hasAssertions` called, then through this method to update #state.assertionCheck value.
|
|
88
|
+
*
|
|
89
|
+
* @param val Set #state.assertionCheck's value
|
|
90
|
+
*
|
|
91
|
+
* @example Usage
|
|
92
|
+
* ```ts ignore
|
|
93
|
+
* import { AssertionState } from "@std/internal";
|
|
94
|
+
*
|
|
95
|
+
* const assertionState = new AssertionState();
|
|
96
|
+
* assertionState.setAssertionCheck(true);
|
|
97
|
+
* ```
|
|
98
|
+
*/
|
|
99
|
+
setAssertionCheck(val) {
|
|
100
|
+
__classPrivateFieldGet(this, _AssertionState_state, "f").assertionCheck = val;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* If any matchers was called, `#state.assertionTriggered` will be set through this method.
|
|
104
|
+
*
|
|
105
|
+
* @param val Set #state.assertionTriggered's value
|
|
106
|
+
*
|
|
107
|
+
* @example Usage
|
|
108
|
+
* ```ts ignore
|
|
109
|
+
* import { AssertionState } from "@std/internal";
|
|
110
|
+
*
|
|
111
|
+
* const assertionState = new AssertionState();
|
|
112
|
+
* assertionState.setAssertionTriggered(true);
|
|
113
|
+
* ```
|
|
114
|
+
*/
|
|
115
|
+
setAssertionTriggered(val) {
|
|
116
|
+
__classPrivateFieldGet(this, _AssertionState_state, "f").assertionTriggered = val;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* If `expect.assertions` called, then through this method to update #state.assertionCheck value.
|
|
120
|
+
*
|
|
121
|
+
* @param num Set #state.assertionCount's value, for example if the value is set 2, that means
|
|
122
|
+
* you must have two assertion matchers call in your test suite.
|
|
123
|
+
*
|
|
124
|
+
* @example Usage
|
|
125
|
+
* ```ts ignore
|
|
126
|
+
* import { AssertionState } from "@std/internal";
|
|
127
|
+
*
|
|
128
|
+
* const assertionState = new AssertionState();
|
|
129
|
+
* assertionState.setAssertionCount(2);
|
|
130
|
+
* ```
|
|
131
|
+
*/
|
|
132
|
+
setAssertionCount(num) {
|
|
133
|
+
__classPrivateFieldGet(this, _AssertionState_state, "f").assertionCount = num;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* If any matchers was called, `#state.assertionTriggeredCount` value will plus one internally.
|
|
137
|
+
*
|
|
138
|
+
* @example Usage
|
|
139
|
+
* ```ts ignore
|
|
140
|
+
* import { AssertionState } from "@std/internal";
|
|
141
|
+
*
|
|
142
|
+
* const assertionState = new AssertionState();
|
|
143
|
+
* assertionState.updateAssertionTriggerCount();
|
|
144
|
+
* ```
|
|
145
|
+
*/
|
|
146
|
+
updateAssertionTriggerCount() {
|
|
147
|
+
if (__classPrivateFieldGet(this, _AssertionState_state, "f").assertionCount !== undefined) {
|
|
148
|
+
__classPrivateFieldGet(this, _AssertionState_state, "f").assertionTriggeredCount += 1;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Check Assertion internal state, if `#state.assertionCheck` is set true, but
|
|
153
|
+
* `#state.assertionTriggered` is still false, then should throw an Assertion Error.
|
|
154
|
+
*
|
|
155
|
+
* @returns a boolean value, that the test suite is satisfied with the check. If not,
|
|
156
|
+
* it should throw an AssertionError.
|
|
157
|
+
*
|
|
158
|
+
* @example Usage
|
|
159
|
+
* ```ts ignore
|
|
160
|
+
* import { AssertionState } from "@std/internal";
|
|
161
|
+
*
|
|
162
|
+
* const assertionState = new AssertionState();
|
|
163
|
+
* if (assertionState.checkAssertionErrorState()) {
|
|
164
|
+
* // throw AssertionError("");
|
|
165
|
+
* }
|
|
166
|
+
* ```
|
|
167
|
+
*/
|
|
168
|
+
checkAssertionErrorState() {
|
|
169
|
+
return __classPrivateFieldGet(this, _AssertionState_state, "f").assertionCheck && !__classPrivateFieldGet(this, _AssertionState_state, "f").assertionTriggered;
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Reset all assertion state when every test suite function ran completely.
|
|
173
|
+
*
|
|
174
|
+
* @example Usage
|
|
175
|
+
* ```ts ignore
|
|
176
|
+
* import { AssertionState } from "@std/internal";
|
|
177
|
+
*
|
|
178
|
+
* const assertionState = new AssertionState();
|
|
179
|
+
* assertionState.resetAssertionState();
|
|
180
|
+
* ```
|
|
181
|
+
*/
|
|
182
|
+
resetAssertionState() {
|
|
183
|
+
__classPrivateFieldSet(this, _AssertionState_state, {
|
|
184
|
+
assertionCount: undefined,
|
|
185
|
+
assertionCheck: false,
|
|
186
|
+
assertionTriggered: false,
|
|
187
|
+
assertionTriggeredCount: 0,
|
|
188
|
+
}, "f");
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Check Assertion called state, if `#state.assertionCount` is set to a number value, but
|
|
192
|
+
* `#state.assertionTriggeredCount` is less then it, then should throw an assertion error.
|
|
193
|
+
*
|
|
194
|
+
* @returns a boolean value, that the test suite is satisfied with the check. If not,
|
|
195
|
+
* it should throw an AssertionError.
|
|
196
|
+
*
|
|
197
|
+
* @example Usage
|
|
198
|
+
* ```ts ignore
|
|
199
|
+
* import { AssertionState } from "@std/internal";
|
|
200
|
+
*
|
|
201
|
+
* const assertionState = new AssertionState();
|
|
202
|
+
* if (assertionState.checkAssertionCountSatisfied()) {
|
|
203
|
+
* // throw AssertionError("");
|
|
204
|
+
* }
|
|
205
|
+
* ```
|
|
206
|
+
*/
|
|
207
|
+
checkAssertionCountSatisfied() {
|
|
208
|
+
return __classPrivateFieldGet(this, _AssertionState_state, "f").assertionCount !== undefined &&
|
|
209
|
+
__classPrivateFieldGet(this, _AssertionState_state, "f").assertionCount !== __classPrivateFieldGet(this, _AssertionState_state, "f").assertionTriggeredCount;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
_AssertionState_state = new WeakMap(), _AssertionState_instances = new WeakSet(), _AssertionState_ensureCleanedUp = function _AssertionState_ensureCleanedUp() {
|
|
213
|
+
// If any checks were registered, after the test suite runs the checks,
|
|
214
|
+
// `resetAssertionState` should also have been called. If it was not,
|
|
215
|
+
// then the test suite did not run the checks.
|
|
216
|
+
if (__classPrivateFieldGet(this, _AssertionState_state, "f").assertionCheck ||
|
|
217
|
+
__classPrivateFieldGet(this, _AssertionState_state, "f").assertionCount !== undefined) {
|
|
218
|
+
throw new Error("AssertionCounter was not cleaned up: If tests are not otherwise failing, ensure `expect.hasAssertion` and `expect.assertions` are only run in bdd tests");
|
|
219
|
+
}
|
|
220
|
+
};
|
|
221
|
+
const assertionState = new AssertionState();
|
|
222
|
+
/**
|
|
223
|
+
* return an instance of AssertionState
|
|
224
|
+
*
|
|
225
|
+
* @returns AssertionState
|
|
226
|
+
*
|
|
227
|
+
* @example Usage
|
|
228
|
+
* ```ts ignore
|
|
229
|
+
* import { getAssertionState } from "@std/internal";
|
|
230
|
+
*
|
|
231
|
+
* const assertionState = getAssertionState();
|
|
232
|
+
* assertionState.setAssertionTriggered(true);
|
|
233
|
+
* ```
|
|
234
|
+
*/
|
|
235
|
+
export function getAssertionState() {
|
|
236
|
+
return assertionState;
|
|
237
|
+
}
|