@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.
- package/lib/esm/index.js +461 -571
- package/lib/esm/spy.js +135 -131
- 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
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
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
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
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
|
-
|
|
136
|
+
return call.type === "return";
|
|
133
137
|
}
|
|
134
138
|
function isThrown(call) {
|
|
135
|
-
|
|
139
|
+
return call.type === "throw";
|
|
136
140
|
}
|
|
137
|
-
|
|
138
|
-
|
|
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.
|
|
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": "
|
|
45
|
-
"@girs/glib-2.0": "
|
|
46
|
-
"@gjsify/cli": "^0.3.
|
|
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.
|
|
52
|
-
"@gjsify/process": "^0.3.
|
|
53
|
-
"@gjsify/utils": "^0.3.
|
|
51
|
+
"@gjsify/assert": "^0.3.15",
|
|
52
|
+
"@gjsify/process": "^0.3.15",
|
|
53
|
+
"@gjsify/utils": "^0.3.15"
|
|
54
54
|
}
|
|
55
55
|
}
|