@gjsify/unit 0.3.13 → 0.3.15

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 (3) hide show
  1. package/lib/esm/index.js +461 -571
  2. package/lib/esm/spy.js +135 -131
  3. package/package.json +7 -7
package/lib/esm/spy.js CHANGED
@@ -1,139 +1,143 @@
1
+ //#region src/spy.ts
1
2
  function spy(f) {
2
- const calls = [];
3
- function spy2(...args) {
4
- let retv;
5
- try {
6
- retv = f ? f.apply(this, args) : void 0;
7
- } catch (error) {
8
- calls.push({
9
- type: "throw",
10
- this: this,
11
- arguments: args,
12
- throw: error
13
- });
14
- throw error;
15
- }
16
- calls.push({
17
- type: "return",
18
- this: this,
19
- arguments: args,
20
- return: retv
21
- });
22
- return retv;
23
- }
24
- Object.defineProperties(spy2, {
25
- calls: descriptors.calls(calls),
26
- returnedCalls: descriptors.returnedCalls,
27
- thrownCalls: descriptors.thrownCalls,
28
- firstCall: descriptors.firstCall,
29
- lastCall: descriptors.lastCall,
30
- firstReturnedCall: descriptors.firstReturnedCall,
31
- lastReturnedCall: descriptors.lastReturnedCall,
32
- firstThrownCall: descriptors.firstThrownCall,
33
- lastThrownCall: descriptors.lastThrownCall,
34
- reset: descriptors.reset,
35
- toString: descriptors.toString(f)
36
- });
37
- return spy2;
3
+ const calls = [];
4
+ function spy(...args) {
5
+ let retv;
6
+ try {
7
+ retv = f ? f.apply(this, args) : undefined;
8
+ } catch (error) {
9
+ calls.push({
10
+ type: "throw",
11
+ this: this,
12
+ arguments: args,
13
+ throw: error
14
+ });
15
+ throw error;
16
+ }
17
+ calls.push({
18
+ type: "return",
19
+ this: this,
20
+ arguments: args,
21
+ return: retv
22
+ });
23
+ return retv;
24
+ }
25
+ Object.defineProperties(spy, {
26
+ calls: descriptors.calls(calls),
27
+ returnedCalls: descriptors.returnedCalls,
28
+ thrownCalls: descriptors.thrownCalls,
29
+ firstCall: descriptors.firstCall,
30
+ lastCall: descriptors.lastCall,
31
+ firstReturnedCall: descriptors.firstReturnedCall,
32
+ lastReturnedCall: descriptors.lastReturnedCall,
33
+ firstThrownCall: descriptors.firstThrownCall,
34
+ lastThrownCall: descriptors.lastThrownCall,
35
+ reset: descriptors.reset,
36
+ toString: descriptors.toString(f)
37
+ });
38
+ return spy;
38
39
  }
39
40
  const descriptors = {
40
- calls(value) {
41
- return { value, configurable: true };
42
- },
43
- returnedCalls: {
44
- get: function returnedCalls() {
45
- return this.calls.filter(isReturned);
46
- },
47
- configurable: true
48
- },
49
- thrownCalls: {
50
- get: function thrownCalls() {
51
- return this.calls.filter(isThrown);
52
- },
53
- configurable: true
54
- },
55
- firstCall: {
56
- get: function firstCall() {
57
- return this.calls[0] || null;
58
- },
59
- configurable: true
60
- },
61
- lastCall: {
62
- get: function lastCall() {
63
- return this.calls[this.calls.length - 1] || null;
64
- },
65
- configurable: true
66
- },
67
- firstReturnedCall: {
68
- get: function firstReturnedCall() {
69
- for (let i = 0; i < this.calls.length; ++i) {
70
- const call = this.calls[i];
71
- if (isReturned(call)) {
72
- return call;
73
- }
74
- }
75
- return null;
76
- },
77
- configurable: true
78
- },
79
- lastReturnedCall: {
80
- get: function lastReturnedCall() {
81
- for (let i = this.calls.length - 1; i >= 0; --i) {
82
- const call = this.calls[i];
83
- if (isReturned(call)) {
84
- return call;
85
- }
86
- }
87
- return null;
88
- },
89
- configurable: true
90
- },
91
- firstThrownCall: {
92
- get: function firstThrownCall() {
93
- for (let i = 0; i < this.calls.length; ++i) {
94
- const call = this.calls[i];
95
- if (isThrown(call)) {
96
- return call;
97
- }
98
- }
99
- return null;
100
- },
101
- configurable: true
102
- },
103
- lastThrownCall: {
104
- get: function lastThrownCall() {
105
- for (let i = this.calls.length - 1; i >= 0; --i) {
106
- const call = this.calls[i];
107
- if (isThrown(call)) {
108
- return call;
109
- }
110
- }
111
- return null;
112
- },
113
- configurable: true
114
- },
115
- reset: {
116
- value: function reset() {
117
- ;
118
- this.calls.length = 0;
119
- },
120
- configurable: true
121
- },
122
- toString(f) {
123
- return {
124
- value: function toString() {
125
- return `/* The spy of */ ${f ? f.toString() : "function(){}"}`;
126
- },
127
- configurable: true
128
- };
129
- }
41
+ calls(value) {
42
+ return {
43
+ value,
44
+ configurable: true
45
+ };
46
+ },
47
+ returnedCalls: {
48
+ get: function returnedCalls() {
49
+ return this.calls.filter(isReturned);
50
+ },
51
+ configurable: true
52
+ },
53
+ thrownCalls: {
54
+ get: function thrownCalls() {
55
+ return this.calls.filter(isThrown);
56
+ },
57
+ configurable: true
58
+ },
59
+ firstCall: {
60
+ get: function firstCall() {
61
+ return this.calls[0] || null;
62
+ },
63
+ configurable: true
64
+ },
65
+ lastCall: {
66
+ get: function lastCall() {
67
+ return this.calls[this.calls.length - 1] || null;
68
+ },
69
+ configurable: true
70
+ },
71
+ firstReturnedCall: {
72
+ get: function firstReturnedCall() {
73
+ for (let i = 0; i < this.calls.length; ++i) {
74
+ const call = this.calls[i];
75
+ if (isReturned(call)) {
76
+ return call;
77
+ }
78
+ }
79
+ return null;
80
+ },
81
+ configurable: true
82
+ },
83
+ lastReturnedCall: {
84
+ get: function lastReturnedCall() {
85
+ for (let i = this.calls.length - 1; i >= 0; --i) {
86
+ const call = this.calls[i];
87
+ if (isReturned(call)) {
88
+ return call;
89
+ }
90
+ }
91
+ return null;
92
+ },
93
+ configurable: true
94
+ },
95
+ firstThrownCall: {
96
+ get: function firstThrownCall() {
97
+ for (let i = 0; i < this.calls.length; ++i) {
98
+ const call = this.calls[i];
99
+ if (isThrown(call)) {
100
+ return call;
101
+ }
102
+ }
103
+ return null;
104
+ },
105
+ configurable: true
106
+ },
107
+ lastThrownCall: {
108
+ get: function lastThrownCall() {
109
+ for (let i = this.calls.length - 1; i >= 0; --i) {
110
+ const call = this.calls[i];
111
+ if (isThrown(call)) {
112
+ return call;
113
+ }
114
+ }
115
+ return null;
116
+ },
117
+ configurable: true
118
+ },
119
+ reset: {
120
+ value: function reset() {
121
+ ;
122
+ this.calls.length = 0;
123
+ },
124
+ configurable: true
125
+ },
126
+ toString(f) {
127
+ return {
128
+ value: function toString() {
129
+ return `/* The spy of */ ${f ? f.toString() : "function(){}"}`;
130
+ },
131
+ configurable: true
132
+ };
133
+ }
130
134
  };
131
135
  function isReturned(call) {
132
- return call.type === "return";
136
+ return call.type === "return";
133
137
  }
134
138
  function isThrown(call) {
135
- return call.type === "throw";
139
+ return call.type === "throw";
136
140
  }
137
- export {
138
- spy
139
- };
141
+
142
+ //#endregion
143
+ export { spy };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gjsify/unit",
3
- "version": "0.3.13",
3
+ "version": "0.3.15",
4
4
  "description": "A BDD-style testing framework for Gjs",
5
5
  "module": "lib/esm/index.js",
6
6
  "types": "lib/types/index.d.ts",
@@ -41,15 +41,15 @@
41
41
  },
42
42
  "homepage": "https://github.com/gjsify/unit#readme",
43
43
  "devDependencies": {
44
- "@girs/gjs": "^4.0.0-rc.9",
45
- "@girs/glib-2.0": "^2.88.0-4.0.0-rc.9",
46
- "@gjsify/cli": "^0.3.13",
44
+ "@girs/gjs": "4.0.0-rc.9",
45
+ "@girs/glib-2.0": "2.88.0-4.0.0-rc.9",
46
+ "@gjsify/cli": "^0.3.15",
47
47
  "@types/node": "^25.6.0",
48
48
  "typescript": "^6.0.3"
49
49
  },
50
50
  "dependencies": {
51
- "@gjsify/assert": "^0.3.13",
52
- "@gjsify/process": "^0.3.13",
53
- "@gjsify/utils": "^0.3.13"
51
+ "@gjsify/assert": "^0.3.15",
52
+ "@gjsify/process": "^0.3.15",
53
+ "@gjsify/utils": "^0.3.15"
54
54
  }
55
55
  }