@egen-civitas/esm-embed-testing 0.7.9 → 0.9.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/CHANGELOG.md +12 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/runtime-conformance.d.ts +19 -0
- package/dist/runtime-conformance.d.ts.map +1 -0
- package/dist/runtime-conformance.js +677 -0
- package/dist/test-host.d.ts +11 -1
- package/dist/test-host.d.ts.map +1 -1
- package/dist/test-host.js +5 -0
- package/package.json +1 -1
- package/src/index.ts +1 -0
- package/src/runtime-conformance.ts +154 -0
- package/src/test-host.ts +14 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @egen-civitas/esm-embed-testing
|
|
2
2
|
|
|
3
|
+
## 0.9.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 94ab5bd: B12 — `createTestShell` (sous-chemin `@egen-civitas/sdk/testing`) : Shell simulé pour tester une app EGEN dans le mode `embedded` (vrai `HostConnection` en mémoire) ou `standalone`, sans navigateur ni Core. Expose `app`, `calls`, `notifications`, `published`, `provide`, `emit.*`, `hostDown`, `advance`, `destroy` ; valide le manifeste comme le Shell. `createTestHost` gagne l'option `providers`, `providers` (fournisseurs vivants) et `hostDown()`. `@egen-civitas/esm-embed-testing` devient pair facultatif du SDK.
|
|
8
|
+
|
|
9
|
+
## 0.8.0
|
|
10
|
+
|
|
11
|
+
### Minor Changes
|
|
12
|
+
|
|
13
|
+
- 6af1520: A4 : `defineRuntimeConformance` (contrat commun à tous les runtimes : embarqué, autonome, factice) et tests de types du SDK (`*.test-d.ts`). A5 (D-04) : le vocabulaire « platform feature » désigne la capacité de plateforme native — alias `hasPlatformFeature`, `setPlatformFeatureResolver`, `PlatformFeatureName`, `EgenPlatformFeatureExtensions` dans `esm-globals` (noms historiques inchangés). Le SDK réexporte davantage de types publics.
|
|
14
|
+
|
|
3
15
|
## 0.7.9
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
package/dist/index.d.ts
CHANGED
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,kBAAkB,CAAC;AACjC,cAAc,YAAY,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,kBAAkB,CAAC;AACjC,cAAc,YAAY,CAAC;AAC3B,cAAc,0BAA0B,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { type CapabilityId } from '@egen-civitas/esm-embed-protocol';
|
|
2
|
+
import type { EgenClient } from '@egen-civitas/esm-embed-client';
|
|
3
|
+
import type { ConformanceApi } from './conformance.js';
|
|
4
|
+
/**
|
|
5
|
+
* Un « runtime » est ce qui sert les capacités derrière un `EgenClient` : le Shell réel (embarqué), le mode autonome du SDK,
|
|
6
|
+
* un simulateur, un runtime factice… `defineRuntimeConformance` vérifie le CONTRAT COMMUN que tous doivent honorer, de sorte que
|
|
7
|
+
* le code d'une app ne change pas selon le runtime (cahier §1 : « la même app fonctionne avec ou sans EGEN »).
|
|
8
|
+
*/
|
|
9
|
+
export interface ConformanceRuntime {
|
|
10
|
+
/** Nom affiché dans les résultats de test. */
|
|
11
|
+
name: string;
|
|
12
|
+
/** Fournit un client prêt à l'emploi pour ce runtime, avec les capacités demandées ; `dispose` libère ses ressources. */
|
|
13
|
+
create(capabilities: CapabilityId[]): Promise<{
|
|
14
|
+
client: EgenClient;
|
|
15
|
+
dispose(): void;
|
|
16
|
+
}>;
|
|
17
|
+
}
|
|
18
|
+
export declare function defineRuntimeConformance(runtime: ConformanceRuntime, t: ConformanceApi): void;
|
|
19
|
+
//# sourceMappingURL=runtime-conformance.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtime-conformance.d.ts","sourceRoot":"","sources":["../src/runtime-conformance.ts"],"names":[],"mappings":"AAAA,OAAO,EAA2B,KAAK,YAAY,EAAE,MAAM,kCAAkC,CAAC;AAC9F,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAC;AACjE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAEvD;;;;GAIG;AACH,MAAM,WAAW,kBAAkB;IACjC,8CAA8C;IAC9C,IAAI,EAAE,MAAM,CAAC;IACb,yHAAyH;IACzH,MAAM,CAAC,YAAY,EAAE,YAAY,EAAE,GAAG,OAAO,CAAC;QAAE,MAAM,EAAE,UAAU,CAAC;QAAC,OAAO,IAAI,IAAI,CAAA;KAAE,CAAC,CAAC;CACxF;AAmBD,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,kBAAkB,EAAE,CAAC,EAAE,cAAc,GAAG,IAAI,CAwH7F"}
|
|
@@ -0,0 +1,677 @@
|
|
|
1
|
+
function _array_like_to_array(arr, len) {
|
|
2
|
+
if (len == null || len > arr.length) len = arr.length;
|
|
3
|
+
for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
|
|
4
|
+
return arr2;
|
|
5
|
+
}
|
|
6
|
+
function _array_with_holes(arr) {
|
|
7
|
+
if (Array.isArray(arr)) return arr;
|
|
8
|
+
}
|
|
9
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
10
|
+
try {
|
|
11
|
+
var info = gen[key](arg);
|
|
12
|
+
var value = info.value;
|
|
13
|
+
} catch (error) {
|
|
14
|
+
reject(error);
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
if (info.done) {
|
|
18
|
+
resolve(value);
|
|
19
|
+
} else {
|
|
20
|
+
Promise.resolve(value).then(_next, _throw);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
function _async_to_generator(fn) {
|
|
24
|
+
return function() {
|
|
25
|
+
var self = this, args = arguments;
|
|
26
|
+
return new Promise(function(resolve, reject) {
|
|
27
|
+
var gen = fn.apply(self, args);
|
|
28
|
+
function _next(value) {
|
|
29
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
30
|
+
}
|
|
31
|
+
function _throw(err) {
|
|
32
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
33
|
+
}
|
|
34
|
+
_next(undefined);
|
|
35
|
+
});
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
function _instanceof(left, right) {
|
|
39
|
+
"@swc/helpers - instanceof";
|
|
40
|
+
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
|
|
41
|
+
return !!right[Symbol.hasInstance](left);
|
|
42
|
+
} else {
|
|
43
|
+
return left instanceof right;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
function _iterable_to_array_limit(arr, i) {
|
|
47
|
+
var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
|
|
48
|
+
if (_i == null) return;
|
|
49
|
+
var _arr = [];
|
|
50
|
+
var _n = true;
|
|
51
|
+
var _d = false;
|
|
52
|
+
var _s, _e;
|
|
53
|
+
try {
|
|
54
|
+
for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
|
|
55
|
+
_arr.push(_s.value);
|
|
56
|
+
if (i && _arr.length === i) break;
|
|
57
|
+
}
|
|
58
|
+
} catch (err) {
|
|
59
|
+
_d = true;
|
|
60
|
+
_e = err;
|
|
61
|
+
} finally{
|
|
62
|
+
try {
|
|
63
|
+
if (!_n && _i["return"] != null) _i["return"]();
|
|
64
|
+
} finally{
|
|
65
|
+
if (_d) throw _e;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return _arr;
|
|
69
|
+
}
|
|
70
|
+
function _non_iterable_rest() {
|
|
71
|
+
throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
72
|
+
}
|
|
73
|
+
function _sliced_to_array(arr, i) {
|
|
74
|
+
return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
|
|
75
|
+
}
|
|
76
|
+
function _type_of(obj) {
|
|
77
|
+
"@swc/helpers - typeof";
|
|
78
|
+
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
|
|
79
|
+
}
|
|
80
|
+
function _unsupported_iterable_to_array(o, minLen) {
|
|
81
|
+
if (!o) return;
|
|
82
|
+
if (typeof o === "string") return _array_like_to_array(o, minLen);
|
|
83
|
+
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
84
|
+
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
85
|
+
if (n === "Map" || n === "Set") return Array.from(n);
|
|
86
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
|
|
87
|
+
}
|
|
88
|
+
function _ts_generator(thisArg, body) {
|
|
89
|
+
var f, y, t, _ = {
|
|
90
|
+
label: 0,
|
|
91
|
+
sent: function() {
|
|
92
|
+
if (t[0] & 1) throw t[1];
|
|
93
|
+
return t[1];
|
|
94
|
+
},
|
|
95
|
+
trys: [],
|
|
96
|
+
ops: []
|
|
97
|
+
}, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype), d = Object.defineProperty;
|
|
98
|
+
return d(g, "next", {
|
|
99
|
+
value: verb(0)
|
|
100
|
+
}), d(g, "throw", {
|
|
101
|
+
value: verb(1)
|
|
102
|
+
}), d(g, "return", {
|
|
103
|
+
value: verb(2)
|
|
104
|
+
}), typeof Symbol === "function" && d(g, Symbol.iterator, {
|
|
105
|
+
value: function() {
|
|
106
|
+
return this;
|
|
107
|
+
}
|
|
108
|
+
}), g;
|
|
109
|
+
function verb(n) {
|
|
110
|
+
return function(v) {
|
|
111
|
+
return step([
|
|
112
|
+
n,
|
|
113
|
+
v
|
|
114
|
+
]);
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
function step(op) {
|
|
118
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
119
|
+
while(g && (g = 0, op[0] && (_ = 0)), _)try {
|
|
120
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
121
|
+
if (y = 0, t) op = [
|
|
122
|
+
op[0] & 2,
|
|
123
|
+
t.value
|
|
124
|
+
];
|
|
125
|
+
switch(op[0]){
|
|
126
|
+
case 0:
|
|
127
|
+
case 1:
|
|
128
|
+
t = op;
|
|
129
|
+
break;
|
|
130
|
+
case 4:
|
|
131
|
+
_.label++;
|
|
132
|
+
return {
|
|
133
|
+
value: op[1],
|
|
134
|
+
done: false
|
|
135
|
+
};
|
|
136
|
+
case 5:
|
|
137
|
+
_.label++;
|
|
138
|
+
y = op[1];
|
|
139
|
+
op = [
|
|
140
|
+
0
|
|
141
|
+
];
|
|
142
|
+
continue;
|
|
143
|
+
case 7:
|
|
144
|
+
op = _.ops.pop();
|
|
145
|
+
_.trys.pop();
|
|
146
|
+
continue;
|
|
147
|
+
default:
|
|
148
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
149
|
+
_ = 0;
|
|
150
|
+
continue;
|
|
151
|
+
}
|
|
152
|
+
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
153
|
+
_.label = op[1];
|
|
154
|
+
break;
|
|
155
|
+
}
|
|
156
|
+
if (op[0] === 6 && _.label < t[1]) {
|
|
157
|
+
_.label = t[1];
|
|
158
|
+
t = op;
|
|
159
|
+
break;
|
|
160
|
+
}
|
|
161
|
+
if (t && _.label < t[2]) {
|
|
162
|
+
_.label = t[2];
|
|
163
|
+
_.ops.push(op);
|
|
164
|
+
break;
|
|
165
|
+
}
|
|
166
|
+
if (t[2]) _.ops.pop();
|
|
167
|
+
_.trys.pop();
|
|
168
|
+
continue;
|
|
169
|
+
}
|
|
170
|
+
op = body.call(thisArg, _);
|
|
171
|
+
} catch (e) {
|
|
172
|
+
op = [
|
|
173
|
+
6,
|
|
174
|
+
e
|
|
175
|
+
];
|
|
176
|
+
y = 0;
|
|
177
|
+
} finally{
|
|
178
|
+
f = t = 0;
|
|
179
|
+
}
|
|
180
|
+
if (op[0] & 5) throw op[1];
|
|
181
|
+
return {
|
|
182
|
+
value: op[0] ? op[1] : void 0,
|
|
183
|
+
done: true
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
import { EmbedError, ERROR_CODES } from '@egen-civitas/esm-embed-protocol';
|
|
188
|
+
var ALL = [
|
|
189
|
+
'tenant',
|
|
190
|
+
'locale',
|
|
191
|
+
'navigation',
|
|
192
|
+
'events',
|
|
193
|
+
'notifications',
|
|
194
|
+
'dialogs',
|
|
195
|
+
'flags',
|
|
196
|
+
'config',
|
|
197
|
+
'telemetry',
|
|
198
|
+
'lifecycle',
|
|
199
|
+
'extensions'
|
|
200
|
+
];
|
|
201
|
+
var STATES = [
|
|
202
|
+
'connecting',
|
|
203
|
+
'ready',
|
|
204
|
+
'active',
|
|
205
|
+
'hidden',
|
|
206
|
+
'closing',
|
|
207
|
+
'closed',
|
|
208
|
+
'failed',
|
|
209
|
+
'standalone'
|
|
210
|
+
];
|
|
211
|
+
var SURFACE = {
|
|
212
|
+
tenant: [
|
|
213
|
+
'get',
|
|
214
|
+
'onChange'
|
|
215
|
+
],
|
|
216
|
+
locale: [
|
|
217
|
+
'get',
|
|
218
|
+
'onChange',
|
|
219
|
+
'set',
|
|
220
|
+
'fallbackChain'
|
|
221
|
+
],
|
|
222
|
+
navigation: [
|
|
223
|
+
'report',
|
|
224
|
+
'navigate',
|
|
225
|
+
'current',
|
|
226
|
+
'exists',
|
|
227
|
+
'back',
|
|
228
|
+
'canGoBack',
|
|
229
|
+
'intent',
|
|
230
|
+
'link',
|
|
231
|
+
'notFound',
|
|
232
|
+
'setTitle',
|
|
233
|
+
'resize',
|
|
234
|
+
'onGoto'
|
|
235
|
+
],
|
|
236
|
+
events: [
|
|
237
|
+
'publish',
|
|
238
|
+
'subscribe',
|
|
239
|
+
'on',
|
|
240
|
+
'once',
|
|
241
|
+
'request',
|
|
242
|
+
'respond',
|
|
243
|
+
'define'
|
|
244
|
+
],
|
|
245
|
+
notifications: [
|
|
246
|
+
'show'
|
|
247
|
+
],
|
|
248
|
+
dialogs: [
|
|
249
|
+
'confirm',
|
|
250
|
+
'alert'
|
|
251
|
+
],
|
|
252
|
+
flags: [
|
|
253
|
+
'isEnabled'
|
|
254
|
+
],
|
|
255
|
+
config: [
|
|
256
|
+
'get',
|
|
257
|
+
'getValue',
|
|
258
|
+
'environment',
|
|
259
|
+
'onChange'
|
|
260
|
+
],
|
|
261
|
+
telemetry: [
|
|
262
|
+
'log',
|
|
263
|
+
'metric',
|
|
264
|
+
'error',
|
|
265
|
+
'trace',
|
|
266
|
+
'health'
|
|
267
|
+
],
|
|
268
|
+
lifecycle: [
|
|
269
|
+
'ready',
|
|
270
|
+
'onBeforeLeave',
|
|
271
|
+
'onClosing',
|
|
272
|
+
'onError',
|
|
273
|
+
'onStateChange',
|
|
274
|
+
'onVisibilityChange',
|
|
275
|
+
'onFocusChange',
|
|
276
|
+
'setBeforeLeave'
|
|
277
|
+
],
|
|
278
|
+
extensions: [
|
|
279
|
+
'list'
|
|
280
|
+
]
|
|
281
|
+
};
|
|
282
|
+
export function defineRuntimeConformance(runtime, t) {
|
|
283
|
+
var describe = t.describe, it = t.it, expect = t.expect;
|
|
284
|
+
var use = function use(caps, fn) {
|
|
285
|
+
return _async_to_generator(function() {
|
|
286
|
+
var _ref, client, dispose;
|
|
287
|
+
return _ts_generator(this, function(_state) {
|
|
288
|
+
switch(_state.label){
|
|
289
|
+
case 0:
|
|
290
|
+
return [
|
|
291
|
+
4,
|
|
292
|
+
runtime.create(caps)
|
|
293
|
+
];
|
|
294
|
+
case 1:
|
|
295
|
+
_ref = _state.sent(), client = _ref.client, dispose = _ref.dispose;
|
|
296
|
+
_state.label = 2;
|
|
297
|
+
case 2:
|
|
298
|
+
_state.trys.push([
|
|
299
|
+
2,
|
|
300
|
+
,
|
|
301
|
+
4,
|
|
302
|
+
5
|
|
303
|
+
]);
|
|
304
|
+
return [
|
|
305
|
+
4,
|
|
306
|
+
fn(client)
|
|
307
|
+
];
|
|
308
|
+
case 3:
|
|
309
|
+
return [
|
|
310
|
+
2,
|
|
311
|
+
_state.sent()
|
|
312
|
+
];
|
|
313
|
+
case 4:
|
|
314
|
+
client.close();
|
|
315
|
+
dispose();
|
|
316
|
+
return [
|
|
317
|
+
7
|
|
318
|
+
];
|
|
319
|
+
case 5:
|
|
320
|
+
return [
|
|
321
|
+
2
|
|
322
|
+
];
|
|
323
|
+
}
|
|
324
|
+
});
|
|
325
|
+
})();
|
|
326
|
+
};
|
|
327
|
+
describe("conformit\xe9 du runtime \xab ".concat(runtime.name, " \xbb"), function() {
|
|
328
|
+
it('surface : mêmes domaines et méthodes que le SDK, quel que soit le runtime', function() {
|
|
329
|
+
return use(ALL, function(c) {
|
|
330
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
331
|
+
try {
|
|
332
|
+
for(var _iterator = Object.entries(SURFACE)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
333
|
+
var _step_value = _sliced_to_array(_step.value, 2), domain = _step_value[0], methods = _step_value[1];
|
|
334
|
+
var _iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = undefined;
|
|
335
|
+
try {
|
|
336
|
+
for(var _iterator1 = methods[Symbol.iterator](), _step1; !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true){
|
|
337
|
+
var m = _step1.value;
|
|
338
|
+
expect(_type_of(c[domain][m])).toBe('function');
|
|
339
|
+
}
|
|
340
|
+
} catch (err) {
|
|
341
|
+
_didIteratorError1 = true;
|
|
342
|
+
_iteratorError1 = err;
|
|
343
|
+
} finally{
|
|
344
|
+
try {
|
|
345
|
+
if (!_iteratorNormalCompletion1 && _iterator1.return != null) {
|
|
346
|
+
_iterator1.return();
|
|
347
|
+
}
|
|
348
|
+
} finally{
|
|
349
|
+
if (_didIteratorError1) {
|
|
350
|
+
throw _iteratorError1;
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
} catch (err) {
|
|
356
|
+
_didIteratorError = true;
|
|
357
|
+
_iteratorError = err;
|
|
358
|
+
} finally{
|
|
359
|
+
try {
|
|
360
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
361
|
+
_iterator.return();
|
|
362
|
+
}
|
|
363
|
+
} finally{
|
|
364
|
+
if (_didIteratorError) {
|
|
365
|
+
throw _iteratorError;
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
for(var _i = 0, _iter = [
|
|
370
|
+
'has',
|
|
371
|
+
'close',
|
|
372
|
+
'notify',
|
|
373
|
+
'diagnostics'
|
|
374
|
+
]; _i < _iter.length; _i++){
|
|
375
|
+
var m1 = _iter[_i];
|
|
376
|
+
expect(_type_of(c[m1])).toBe('function');
|
|
377
|
+
}
|
|
378
|
+
expect(_type_of(c.locale.format.number)).toBe('function');
|
|
379
|
+
expect(_type_of(c.telemetry.trace)).toBe('function');
|
|
380
|
+
});
|
|
381
|
+
});
|
|
382
|
+
it('identité : moduleName, connected et listes accordées/refusées cohérents', function() {
|
|
383
|
+
return use([
|
|
384
|
+
'tenant'
|
|
385
|
+
], function(c) {
|
|
386
|
+
expect(_type_of(c.moduleName)).toBe('string');
|
|
387
|
+
expect(_type_of(c.connected)).toBe('boolean');
|
|
388
|
+
expect(c.has('tenant')).toBe(true);
|
|
389
|
+
expect(Array.isArray(c.capabilities)).toBe(true);
|
|
390
|
+
expect(Array.isArray(c.denied)).toBe(true);
|
|
391
|
+
expect(c.capabilities.every(function(g) {
|
|
392
|
+
return typeof g.id === 'string' && typeof g.version === 'number';
|
|
393
|
+
})).toBe(true);
|
|
394
|
+
});
|
|
395
|
+
});
|
|
396
|
+
it('arguments invalides : INVALID_ARGS identique partout (jamais de comportement permissif)', function() {
|
|
397
|
+
return use([
|
|
398
|
+
'navigation',
|
|
399
|
+
'events'
|
|
400
|
+
], function(c) {
|
|
401
|
+
return _async_to_generator(function() {
|
|
402
|
+
return _ts_generator(this, function(_state) {
|
|
403
|
+
switch(_state.label){
|
|
404
|
+
case 0:
|
|
405
|
+
return [
|
|
406
|
+
4,
|
|
407
|
+
expect(c.navigation.navigate('http://evil.example')).rejects.toMatchObject({
|
|
408
|
+
code: 'INVALID_ARGS'
|
|
409
|
+
})
|
|
410
|
+
];
|
|
411
|
+
case 1:
|
|
412
|
+
_state.sent();
|
|
413
|
+
return [
|
|
414
|
+
4,
|
|
415
|
+
expect(c.events.publish('Pas Valide', 1)).rejects.toMatchObject({
|
|
416
|
+
code: 'INVALID_ARGS'
|
|
417
|
+
})
|
|
418
|
+
];
|
|
419
|
+
case 2:
|
|
420
|
+
_state.sent();
|
|
421
|
+
return [
|
|
422
|
+
2
|
|
423
|
+
];
|
|
424
|
+
}
|
|
425
|
+
});
|
|
426
|
+
})();
|
|
427
|
+
});
|
|
428
|
+
});
|
|
429
|
+
// Méthodes FACULTATIVES (le Shell ne les sert que s'il sait les honorer) : un refus propre est permis, jamais un succès.
|
|
430
|
+
it('méthodes facultatives (locale.set, config.environment, dialogs.alert) : jamais de succès sur un appel invalide', function() {
|
|
431
|
+
return use([
|
|
432
|
+
'locale'
|
|
433
|
+
], function(c) {
|
|
434
|
+
return _async_to_generator(function() {
|
|
435
|
+
var code;
|
|
436
|
+
return _ts_generator(this, function(_state) {
|
|
437
|
+
switch(_state.label){
|
|
438
|
+
case 0:
|
|
439
|
+
return [
|
|
440
|
+
4,
|
|
441
|
+
c.locale.set('fr_GA').then(function() {
|
|
442
|
+
return 'resolved';
|
|
443
|
+
}, function(e) {
|
|
444
|
+
return e.code;
|
|
445
|
+
})
|
|
446
|
+
];
|
|
447
|
+
case 1:
|
|
448
|
+
code = _state.sent();
|
|
449
|
+
expect([
|
|
450
|
+
'INVALID_ARGS',
|
|
451
|
+
'UNKNOWN_METHOD',
|
|
452
|
+
'DENIED'
|
|
453
|
+
]).toContain(code);
|
|
454
|
+
return [
|
|
455
|
+
2
|
|
456
|
+
];
|
|
457
|
+
}
|
|
458
|
+
});
|
|
459
|
+
})();
|
|
460
|
+
});
|
|
461
|
+
});
|
|
462
|
+
it('erreurs : toujours des EmbedError dont le code appartient au catalogue fermé', function() {
|
|
463
|
+
return use([
|
|
464
|
+
'navigation'
|
|
465
|
+
], function(c) {
|
|
466
|
+
return _async_to_generator(function() {
|
|
467
|
+
var e;
|
|
468
|
+
return _ts_generator(this, function(_state) {
|
|
469
|
+
switch(_state.label){
|
|
470
|
+
case 0:
|
|
471
|
+
return [
|
|
472
|
+
4,
|
|
473
|
+
c.navigation.navigate('http://evil.example').then(function() {
|
|
474
|
+
return undefined;
|
|
475
|
+
}, function(err) {
|
|
476
|
+
return err;
|
|
477
|
+
})
|
|
478
|
+
];
|
|
479
|
+
case 1:
|
|
480
|
+
e = _state.sent();
|
|
481
|
+
expect(_instanceof(e, EmbedError)).toBe(true);
|
|
482
|
+
expect(ERROR_CODES.includes(e.code)).toBe(true);
|
|
483
|
+
return [
|
|
484
|
+
2
|
|
485
|
+
];
|
|
486
|
+
}
|
|
487
|
+
});
|
|
488
|
+
})();
|
|
489
|
+
});
|
|
490
|
+
});
|
|
491
|
+
it('capacité non demandée : DENIED, jamais d’exception synchrone', function() {
|
|
492
|
+
return use([
|
|
493
|
+
'tenant'
|
|
494
|
+
], function(c) {
|
|
495
|
+
return _async_to_generator(function() {
|
|
496
|
+
var thrown, p;
|
|
497
|
+
return _ts_generator(this, function(_state) {
|
|
498
|
+
switch(_state.label){
|
|
499
|
+
case 0:
|
|
500
|
+
thrown = false;
|
|
501
|
+
try {
|
|
502
|
+
p = c.flags.isEnabled('x');
|
|
503
|
+
} catch (unused) {
|
|
504
|
+
thrown = true;
|
|
505
|
+
}
|
|
506
|
+
expect(thrown).toBe(false);
|
|
507
|
+
return [
|
|
508
|
+
4,
|
|
509
|
+
expect(p).rejects.toMatchObject({
|
|
510
|
+
code: 'DENIED'
|
|
511
|
+
})
|
|
512
|
+
];
|
|
513
|
+
case 1:
|
|
514
|
+
_state.sent();
|
|
515
|
+
return [
|
|
516
|
+
2
|
|
517
|
+
];
|
|
518
|
+
}
|
|
519
|
+
});
|
|
520
|
+
})();
|
|
521
|
+
});
|
|
522
|
+
});
|
|
523
|
+
it('link() est pur et identique partout', function() {
|
|
524
|
+
return use([
|
|
525
|
+
'navigation'
|
|
526
|
+
], function(c) {
|
|
527
|
+
expect(c.navigation.link('/a?x=1', {
|
|
528
|
+
query: {
|
|
529
|
+
y: 2,
|
|
530
|
+
x: null
|
|
531
|
+
},
|
|
532
|
+
hash: 'h'
|
|
533
|
+
})).toBe('/a?y=2#h');
|
|
534
|
+
expect(function() {
|
|
535
|
+
return c.navigation.link('https://x.example');
|
|
536
|
+
}).toThrowError(/chemin interne/);
|
|
537
|
+
});
|
|
538
|
+
});
|
|
539
|
+
it('format.* : texte, sans échange, jamais d’exception sur une langue inconnue', function() {
|
|
540
|
+
return use([
|
|
541
|
+
'locale'
|
|
542
|
+
], function(c) {
|
|
543
|
+
expect(_type_of(c.locale.format.number(1234.5))).toBe('string');
|
|
544
|
+
expect(_type_of(c.locale.format.date(0, {
|
|
545
|
+
timeZone: 'UTC'
|
|
546
|
+
}))).toBe('string');
|
|
547
|
+
expect(_type_of(c.locale.format.relativeTime(-1, 'day'))).toBe('string');
|
|
548
|
+
});
|
|
549
|
+
});
|
|
550
|
+
it('trace : rend la valeur (ou l’exception) de la fonction mesurée, quoi qu’il arrive à l’envoi', function() {
|
|
551
|
+
return use([
|
|
552
|
+
'telemetry'
|
|
553
|
+
], function(c) {
|
|
554
|
+
return _async_to_generator(function() {
|
|
555
|
+
return _ts_generator(this, function(_state) {
|
|
556
|
+
switch(_state.label){
|
|
557
|
+
case 0:
|
|
558
|
+
return [
|
|
559
|
+
4,
|
|
560
|
+
expect(c.telemetry.trace('op', function() {
|
|
561
|
+
return 7;
|
|
562
|
+
})).resolves.toBe(7)
|
|
563
|
+
];
|
|
564
|
+
case 1:
|
|
565
|
+
_state.sent();
|
|
566
|
+
return [
|
|
567
|
+
4,
|
|
568
|
+
expect(c.telemetry.trace('op', function() {
|
|
569
|
+
return _async_to_generator(function() {
|
|
570
|
+
return _ts_generator(this, function(_state) {
|
|
571
|
+
return [
|
|
572
|
+
2,
|
|
573
|
+
'ok'
|
|
574
|
+
];
|
|
575
|
+
});
|
|
576
|
+
})();
|
|
577
|
+
})).resolves.toBe('ok')
|
|
578
|
+
];
|
|
579
|
+
case 2:
|
|
580
|
+
_state.sent();
|
|
581
|
+
return [
|
|
582
|
+
4,
|
|
583
|
+
expect(c.telemetry.trace('op', function() {
|
|
584
|
+
return Promise.reject(new Error('boum'));
|
|
585
|
+
})).rejects.toThrow('boum')
|
|
586
|
+
];
|
|
587
|
+
case 3:
|
|
588
|
+
_state.sent();
|
|
589
|
+
return [
|
|
590
|
+
2
|
|
591
|
+
];
|
|
592
|
+
}
|
|
593
|
+
});
|
|
594
|
+
})();
|
|
595
|
+
});
|
|
596
|
+
});
|
|
597
|
+
it('cycle de vie : état valide, observateurs désabonnables', function() {
|
|
598
|
+
return use([
|
|
599
|
+
'lifecycle'
|
|
600
|
+
], function(c) {
|
|
601
|
+
expect(STATES.includes(c.lifecycle.state)).toBe(true);
|
|
602
|
+
var off = c.lifecycle.onBeforeLeave(function() {
|
|
603
|
+
return true;
|
|
604
|
+
});
|
|
605
|
+
var off2 = c.lifecycle.onClosing(function() {
|
|
606
|
+
return undefined;
|
|
607
|
+
});
|
|
608
|
+
var off3 = c.lifecycle.onError(function() {
|
|
609
|
+
return undefined;
|
|
610
|
+
});
|
|
611
|
+
var off4 = c.lifecycle.onStateChange(function() {
|
|
612
|
+
return undefined;
|
|
613
|
+
});
|
|
614
|
+
for(var _i = 0, _iter = [
|
|
615
|
+
off,
|
|
616
|
+
off2,
|
|
617
|
+
off3,
|
|
618
|
+
off4
|
|
619
|
+
]; _i < _iter.length; _i++){
|
|
620
|
+
var o = _iter[_i];
|
|
621
|
+
expect(typeof o === "undefined" ? "undefined" : _type_of(o)).toBe('function');
|
|
622
|
+
}
|
|
623
|
+
for(var _i1 = 0, _iter1 = [
|
|
624
|
+
off,
|
|
625
|
+
off2,
|
|
626
|
+
off3,
|
|
627
|
+
off4
|
|
628
|
+
]; _i1 < _iter1.length; _i1++){
|
|
629
|
+
var o1 = _iter1[_i1];
|
|
630
|
+
o1();
|
|
631
|
+
}
|
|
632
|
+
});
|
|
633
|
+
});
|
|
634
|
+
it('fermeture : close() idempotent ; ensuite les appels sont rejetés CLOSED ou DENIED, sans exception synchrone', function() {
|
|
635
|
+
return _async_to_generator(function() {
|
|
636
|
+
var _ref, client, dispose, p, code;
|
|
637
|
+
return _ts_generator(this, function(_state) {
|
|
638
|
+
switch(_state.label){
|
|
639
|
+
case 0:
|
|
640
|
+
return [
|
|
641
|
+
4,
|
|
642
|
+
runtime.create([
|
|
643
|
+
'tenant'
|
|
644
|
+
])
|
|
645
|
+
];
|
|
646
|
+
case 1:
|
|
647
|
+
_ref = _state.sent(), client = _ref.client, dispose = _ref.dispose;
|
|
648
|
+
client.close();
|
|
649
|
+
client.close();
|
|
650
|
+
expect(function() {
|
|
651
|
+
p = client.tenant.get();
|
|
652
|
+
}).not.toThrow();
|
|
653
|
+
return [
|
|
654
|
+
4,
|
|
655
|
+
p.then(function() {
|
|
656
|
+
return 'resolved';
|
|
657
|
+
}, function(e) {
|
|
658
|
+
return e.code;
|
|
659
|
+
})
|
|
660
|
+
];
|
|
661
|
+
case 2:
|
|
662
|
+
code = _state.sent();
|
|
663
|
+
expect([
|
|
664
|
+
'CLOSED',
|
|
665
|
+
'DENIED'
|
|
666
|
+
]).toContain(code);
|
|
667
|
+
expect(client.lifecycle.state === 'closed' || client.lifecycle.state === 'standalone').toBe(true);
|
|
668
|
+
dispose();
|
|
669
|
+
return [
|
|
670
|
+
2
|
|
671
|
+
];
|
|
672
|
+
}
|
|
673
|
+
});
|
|
674
|
+
})();
|
|
675
|
+
});
|
|
676
|
+
});
|
|
677
|
+
}
|
package/dist/test-host.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type ApprovedGrants, type CapabilityId, type EffectiveIframeRights, type GrantConfig, type IframeRights } from '@egen-civitas/esm-embed-protocol';
|
|
2
2
|
import type { ConnectOptions } from '@egen-civitas/esm-embed-client';
|
|
3
|
-
import { HostConnection, type ExtensionInfo } from '@egen-civitas/esm-embed-host';
|
|
3
|
+
import { HostConnection, type ExtensionInfo, type HostProviders } from '@egen-civitas/esm-embed-host';
|
|
4
4
|
export interface TestHostOptions {
|
|
5
5
|
moduleName?: string;
|
|
6
6
|
/** Origine simulée du Shell (à mettre dans `hostOrigins` de l'app). */
|
|
@@ -24,6 +24,12 @@ export interface TestHostOptions {
|
|
|
24
24
|
message: string;
|
|
25
25
|
danger?: boolean;
|
|
26
26
|
}) => boolean);
|
|
27
|
+
/**
|
|
28
|
+
* Fournisseurs du Shell qui remplacent ceux du simulateur (par capacité), y compris les facultatifs que le simulateur ne sert pas
|
|
29
|
+
* (`environment`, `locale.set`, `dialogs.alert`, `routeExists`, `intents`…). Les facultatifs doivent être fournis AVANT la connexion :
|
|
30
|
+
* la table des capacités est construite à la poignée de main.
|
|
31
|
+
*/
|
|
32
|
+
providers?: Partial<HostProviders>;
|
|
27
33
|
}
|
|
28
34
|
export interface CallRecord {
|
|
29
35
|
cap: string;
|
|
@@ -34,6 +40,8 @@ export interface TestHost {
|
|
|
34
40
|
/** À passer à `connectToEgen({ ...host.connectOptions, capabilities: [...] })`. */
|
|
35
41
|
connectOptions: Pick<ConnectOptions, 'moduleName' | 'hostOrigins' | 'window' | 'host' | 'timeoutMs'>;
|
|
36
42
|
connection: HostConnection;
|
|
43
|
+
/** Fournisseurs vivants du Shell : `Object.assign(host.providers, …)` remplace le comportement d'une capacité déjà servie, à chaud. */
|
|
44
|
+
providers: HostProviders;
|
|
37
45
|
/** Droits d'iframe que le Core appliquerait (`demande ∩ plafond`) : de quoi vérifier ce que l'app obtient réellement. */
|
|
38
46
|
iframe: EffectiveIframeRights;
|
|
39
47
|
/** Journal des services du Core sollicités par l'app. */
|
|
@@ -61,6 +69,8 @@ export interface TestHost {
|
|
|
61
69
|
goto(path: string): void;
|
|
62
70
|
visibility(visible: boolean): void;
|
|
63
71
|
};
|
|
72
|
+
/** Coupe la liaison côté Shell (comme un Shell qui disparaît) : les appels suivants de l'app sont rejetés. */
|
|
73
|
+
hostDown(): void;
|
|
64
74
|
destroy(): void;
|
|
65
75
|
}
|
|
66
76
|
/**
|
package/dist/test-host.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"test-host.d.ts","sourceRoot":"","sources":["../src/test-host.ts"],"names":[],"mappings":"AAAA,OAAO,EAAoC,KAAK,cAAc,EAAE,KAAK,YAAY,EAAE,KAAK,qBAAqB,EAAE,KAAK,WAAW,EAAE,KAAK,YAAY,EAAE,MAAM,kCAAkC,CAAC;AAC7L,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AACrE,OAAO,EAAa,cAAc,EAAE,KAAK,aAAa,
|
|
1
|
+
{"version":3,"file":"test-host.d.ts","sourceRoot":"","sources":["../src/test-host.ts"],"names":[],"mappings":"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"}
|
package/dist/test-host.js
CHANGED
|
@@ -142,6 +142,7 @@ function watchable(initial) {
|
|
|
142
142
|
}
|
|
143
143
|
}
|
|
144
144
|
};
|
|
145
|
+
if (o.providers) Object.assign(providers, o.providers);
|
|
145
146
|
var appWindow = new EventTarget();
|
|
146
147
|
var hostWindow = {
|
|
147
148
|
postMessage: function postMessage(message) {
|
|
@@ -200,6 +201,7 @@ function watchable(initial) {
|
|
|
200
201
|
timeoutMs: 500
|
|
201
202
|
},
|
|
202
203
|
connection: connection,
|
|
204
|
+
providers: providers,
|
|
203
205
|
iframe: effectiveIframe(o.manifestIframe, (_o_approved1 = o.approved) === null || _o_approved1 === void 0 ? void 0 : _o_approved1.iframe),
|
|
204
206
|
calls: calls,
|
|
205
207
|
notifications: notifications,
|
|
@@ -237,6 +239,9 @@ function watchable(initial) {
|
|
|
237
239
|
return channel.emit('visibility', v);
|
|
238
240
|
}
|
|
239
241
|
},
|
|
242
|
+
hostDown: function hostDown() {
|
|
243
|
+
return connection.reset();
|
|
244
|
+
},
|
|
240
245
|
destroy: function destroy() {
|
|
241
246
|
return connection.destroy();
|
|
242
247
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@egen-civitas/esm-embed-testing",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0",
|
|
4
4
|
"license": "MPL-2.0",
|
|
5
5
|
"description": "Développer et tester une app embarquée sans le Core : hôte de test en mémoire, suite de conformité du protocole v2, simulateur de Shell (egen-embed-sim).",
|
|
6
6
|
"type": "module",
|
package/src/index.ts
CHANGED
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import { EmbedError, ERROR_CODES, type CapabilityId } from '@egen-civitas/esm-embed-protocol';
|
|
2
|
+
import type { EgenClient } from '@egen-civitas/esm-embed-client';
|
|
3
|
+
import type { ConformanceApi } from './conformance.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Un « runtime » est ce qui sert les capacités derrière un `EgenClient` : le Shell réel (embarqué), le mode autonome du SDK,
|
|
7
|
+
* un simulateur, un runtime factice… `defineRuntimeConformance` vérifie le CONTRAT COMMUN que tous doivent honorer, de sorte que
|
|
8
|
+
* le code d'une app ne change pas selon le runtime (cahier §1 : « la même app fonctionne avec ou sans EGEN »).
|
|
9
|
+
*/
|
|
10
|
+
export interface ConformanceRuntime {
|
|
11
|
+
/** Nom affiché dans les résultats de test. */
|
|
12
|
+
name: string;
|
|
13
|
+
/** Fournit un client prêt à l'emploi pour ce runtime, avec les capacités demandées ; `dispose` libère ses ressources. */
|
|
14
|
+
create(capabilities: CapabilityId[]): Promise<{ client: EgenClient; dispose(): void }>;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const ALL: CapabilityId[] = ['tenant', 'locale', 'navigation', 'events', 'notifications', 'dialogs', 'flags', 'config', 'telemetry', 'lifecycle', 'extensions'];
|
|
18
|
+
const STATES = ['connecting', 'ready', 'active', 'hidden', 'closing', 'closed', 'failed', 'standalone'];
|
|
19
|
+
|
|
20
|
+
const SURFACE: Record<string, string[]> = {
|
|
21
|
+
tenant: ['get', 'onChange'],
|
|
22
|
+
locale: ['get', 'onChange', 'set', 'fallbackChain'],
|
|
23
|
+
navigation: ['report', 'navigate', 'current', 'exists', 'back', 'canGoBack', 'intent', 'link', 'notFound', 'setTitle', 'resize', 'onGoto'],
|
|
24
|
+
events: ['publish', 'subscribe', 'on', 'once', 'request', 'respond', 'define'],
|
|
25
|
+
notifications: ['show'],
|
|
26
|
+
dialogs: ['confirm', 'alert'],
|
|
27
|
+
flags: ['isEnabled'],
|
|
28
|
+
config: ['get', 'getValue', 'environment', 'onChange'],
|
|
29
|
+
telemetry: ['log', 'metric', 'error', 'trace', 'health'],
|
|
30
|
+
lifecycle: ['ready', 'onBeforeLeave', 'onClosing', 'onError', 'onStateChange', 'onVisibilityChange', 'onFocusChange', 'setBeforeLeave'],
|
|
31
|
+
extensions: ['list'],
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export function defineRuntimeConformance(runtime: ConformanceRuntime, t: ConformanceApi): void {
|
|
35
|
+
const { describe, it, expect } = t;
|
|
36
|
+
const use = async <T>(caps: CapabilityId[], fn: (c: EgenClient) => Promise<T> | T): Promise<T> => {
|
|
37
|
+
const { client, dispose } = await runtime.create(caps);
|
|
38
|
+
try {
|
|
39
|
+
return await fn(client);
|
|
40
|
+
} finally {
|
|
41
|
+
client.close();
|
|
42
|
+
dispose();
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
describe(`conformité du runtime « ${runtime.name} »`, () => {
|
|
47
|
+
it('surface : mêmes domaines et méthodes que le SDK, quel que soit le runtime', () =>
|
|
48
|
+
use(ALL, (c) => {
|
|
49
|
+
for (const [domain, methods] of Object.entries(SURFACE)) {
|
|
50
|
+
for (const m of methods) expect(typeof (c as any)[domain][m]).toBe('function');
|
|
51
|
+
}
|
|
52
|
+
for (const m of ['has', 'close', 'notify', 'diagnostics']) expect(typeof (c as any)[m]).toBe('function');
|
|
53
|
+
expect(typeof c.locale.format.number).toBe('function');
|
|
54
|
+
expect(typeof c.telemetry.trace).toBe('function');
|
|
55
|
+
}));
|
|
56
|
+
|
|
57
|
+
it('identité : moduleName, connected et listes accordées/refusées cohérents', () =>
|
|
58
|
+
use(['tenant'], (c) => {
|
|
59
|
+
expect(typeof c.moduleName).toBe('string');
|
|
60
|
+
expect(typeof c.connected).toBe('boolean');
|
|
61
|
+
expect(c.has('tenant')).toBe(true);
|
|
62
|
+
expect(Array.isArray(c.capabilities)).toBe(true);
|
|
63
|
+
expect(Array.isArray(c.denied)).toBe(true);
|
|
64
|
+
expect(c.capabilities.every((g) => typeof g.id === 'string' && typeof g.version === 'number')).toBe(true);
|
|
65
|
+
}));
|
|
66
|
+
|
|
67
|
+
it('arguments invalides : INVALID_ARGS identique partout (jamais de comportement permissif)', () =>
|
|
68
|
+
use(['navigation', 'events'], async (c) => {
|
|
69
|
+
await expect(c.navigation.navigate('http://evil.example')).rejects.toMatchObject({ code: 'INVALID_ARGS' });
|
|
70
|
+
await expect(c.events.publish('Pas Valide', 1)).rejects.toMatchObject({ code: 'INVALID_ARGS' });
|
|
71
|
+
}));
|
|
72
|
+
|
|
73
|
+
// Méthodes FACULTATIVES (le Shell ne les sert que s'il sait les honorer) : un refus propre est permis, jamais un succès.
|
|
74
|
+
it('méthodes facultatives (locale.set, config.environment, dialogs.alert) : jamais de succès sur un appel invalide', () =>
|
|
75
|
+
use(['locale'], async (c) => {
|
|
76
|
+
const code = await c.locale.set('fr_GA' as string).then(
|
|
77
|
+
() => 'resolved',
|
|
78
|
+
(e: EmbedError) => e.code,
|
|
79
|
+
);
|
|
80
|
+
expect(['INVALID_ARGS', 'UNKNOWN_METHOD', 'DENIED']).toContain(code);
|
|
81
|
+
}));
|
|
82
|
+
|
|
83
|
+
it('erreurs : toujours des EmbedError dont le code appartient au catalogue fermé', () =>
|
|
84
|
+
use(['navigation'], async (c) => {
|
|
85
|
+
const e: unknown = await c.navigation.navigate('http://evil.example').then(
|
|
86
|
+
() => undefined,
|
|
87
|
+
(err) => err,
|
|
88
|
+
);
|
|
89
|
+
expect(e instanceof EmbedError).toBe(true);
|
|
90
|
+
expect((ERROR_CODES as readonly string[]).includes((e as EmbedError).code)).toBe(true);
|
|
91
|
+
}));
|
|
92
|
+
|
|
93
|
+
it('capacité non demandée : DENIED, jamais d’exception synchrone', () =>
|
|
94
|
+
use(['tenant'], async (c) => {
|
|
95
|
+
let thrown = false;
|
|
96
|
+
let p: Promise<unknown> | undefined;
|
|
97
|
+
try {
|
|
98
|
+
p = c.flags.isEnabled('x');
|
|
99
|
+
} catch {
|
|
100
|
+
thrown = true;
|
|
101
|
+
}
|
|
102
|
+
expect(thrown).toBe(false);
|
|
103
|
+
await expect(p).rejects.toMatchObject({ code: 'DENIED' });
|
|
104
|
+
}));
|
|
105
|
+
|
|
106
|
+
it('link() est pur et identique partout', () =>
|
|
107
|
+
use(['navigation'], (c) => {
|
|
108
|
+
expect(c.navigation.link('/a?x=1', { query: { y: 2, x: null }, hash: 'h' })).toBe('/a?y=2#h');
|
|
109
|
+
expect(() => c.navigation.link('https://x.example')).toThrowError(/chemin interne/);
|
|
110
|
+
}));
|
|
111
|
+
|
|
112
|
+
it('format.* : texte, sans échange, jamais d’exception sur une langue inconnue', () =>
|
|
113
|
+
use(['locale'], (c) => {
|
|
114
|
+
expect(typeof c.locale.format.number(1234.5)).toBe('string');
|
|
115
|
+
expect(typeof c.locale.format.date(0, { timeZone: 'UTC' })).toBe('string');
|
|
116
|
+
expect(typeof c.locale.format.relativeTime(-1, 'day')).toBe('string');
|
|
117
|
+
}));
|
|
118
|
+
|
|
119
|
+
it('trace : rend la valeur (ou l’exception) de la fonction mesurée, quoi qu’il arrive à l’envoi', () =>
|
|
120
|
+
use(['telemetry'], async (c) => {
|
|
121
|
+
await expect(c.telemetry.trace('op', () => 7)).resolves.toBe(7);
|
|
122
|
+
await expect(c.telemetry.trace('op', async () => 'ok')).resolves.toBe('ok');
|
|
123
|
+
await expect(c.telemetry.trace('op', () => Promise.reject(new Error('boum')))).rejects.toThrow('boum');
|
|
124
|
+
}));
|
|
125
|
+
|
|
126
|
+
it('cycle de vie : état valide, observateurs désabonnables', () =>
|
|
127
|
+
use(['lifecycle'], (c) => {
|
|
128
|
+
expect(STATES.includes(c.lifecycle.state)).toBe(true);
|
|
129
|
+
const off = c.lifecycle.onBeforeLeave(() => true);
|
|
130
|
+
const off2 = c.lifecycle.onClosing(() => undefined);
|
|
131
|
+
const off3 = c.lifecycle.onError(() => undefined);
|
|
132
|
+
const off4 = c.lifecycle.onStateChange(() => undefined);
|
|
133
|
+
for (const o of [off, off2, off3, off4]) expect(typeof o).toBe('function');
|
|
134
|
+
for (const o of [off, off2, off3, off4]) o();
|
|
135
|
+
}));
|
|
136
|
+
|
|
137
|
+
it('fermeture : close() idempotent ; ensuite les appels sont rejetés CLOSED ou DENIED, sans exception synchrone', async () => {
|
|
138
|
+
const { client, dispose } = await runtime.create(['tenant']);
|
|
139
|
+
client.close();
|
|
140
|
+
client.close();
|
|
141
|
+
let p: Promise<unknown> | undefined;
|
|
142
|
+
expect(() => {
|
|
143
|
+
p = client.tenant.get();
|
|
144
|
+
}).not.toThrow();
|
|
145
|
+
const code = await (p as Promise<unknown>).then(
|
|
146
|
+
() => 'resolved',
|
|
147
|
+
(e: EmbedError) => e.code,
|
|
148
|
+
);
|
|
149
|
+
expect(['CLOSED', 'DENIED']).toContain(code);
|
|
150
|
+
expect(client.lifecycle.state === 'closed' || client.lifecycle.state === 'standalone').toBe(true);
|
|
151
|
+
dispose();
|
|
152
|
+
});
|
|
153
|
+
});
|
|
154
|
+
}
|
package/src/test-host.ts
CHANGED
|
@@ -19,6 +19,12 @@ export interface TestHostOptions {
|
|
|
19
19
|
/** Extensions attachées à chaque slot (`{ 'topbar-nav-slot': [...] }`). */
|
|
20
20
|
extensions?: Record<string, ExtensionInfo[]>;
|
|
21
21
|
confirm?: boolean | ((d: { title: string; message: string; danger?: boolean }) => boolean);
|
|
22
|
+
/**
|
|
23
|
+
* Fournisseurs du Shell qui remplacent ceux du simulateur (par capacité), y compris les facultatifs que le simulateur ne sert pas
|
|
24
|
+
* (`environment`, `locale.set`, `dialogs.alert`, `routeExists`, `intents`…). Les facultatifs doivent être fournis AVANT la connexion :
|
|
25
|
+
* la table des capacités est construite à la poignée de main.
|
|
26
|
+
*/
|
|
27
|
+
providers?: Partial<HostProviders>;
|
|
22
28
|
}
|
|
23
29
|
|
|
24
30
|
export interface CallRecord {
|
|
@@ -31,6 +37,8 @@ export interface TestHost {
|
|
|
31
37
|
/** À passer à `connectToEgen({ ...host.connectOptions, capabilities: [...] })`. */
|
|
32
38
|
connectOptions: Pick<ConnectOptions, 'moduleName' | 'hostOrigins' | 'window' | 'host' | 'timeoutMs'>;
|
|
33
39
|
connection: HostConnection;
|
|
40
|
+
/** Fournisseurs vivants du Shell : `Object.assign(host.providers, …)` remplace le comportement d'une capacité déjà servie, à chaud. */
|
|
41
|
+
providers: HostProviders;
|
|
34
42
|
/** Droits d'iframe que le Core appliquerait (`demande ∩ plafond`) : de quoi vérifier ce que l'app obtient réellement. */
|
|
35
43
|
iframe: EffectiveIframeRights;
|
|
36
44
|
/** Journal des services du Core sollicités par l'app. */
|
|
@@ -47,6 +55,8 @@ export interface TestHost {
|
|
|
47
55
|
goto(path: string): void;
|
|
48
56
|
visibility(visible: boolean): void;
|
|
49
57
|
};
|
|
58
|
+
/** Coupe la liaison côté Shell (comme un Shell qui disparaît) : les appels suivants de l'app sont rejetés. */
|
|
59
|
+
hostDown(): void;
|
|
50
60
|
destroy(): void;
|
|
51
61
|
}
|
|
52
62
|
|
|
@@ -150,6 +160,8 @@ export function createTestHost(o: TestHostOptions = {}): TestHost {
|
|
|
150
160
|
telemetry: { log: (l, m, c) => log('telemetry', 'log', l, m, c), metric: (n, v, t) => log('telemetry', 'metric', n, v, t) },
|
|
151
161
|
};
|
|
152
162
|
|
|
163
|
+
if (o.providers) Object.assign(providers, o.providers);
|
|
164
|
+
|
|
153
165
|
const appWindow = new EventTarget();
|
|
154
166
|
const hostWindow: { postMessage(message: unknown, targetOrigin: string): void } = {
|
|
155
167
|
postMessage: (message) => void queueMicrotask(() => connection.handle(message)),
|
|
@@ -181,6 +193,7 @@ export function createTestHost(o: TestHostOptions = {}): TestHost {
|
|
|
181
193
|
return {
|
|
182
194
|
connectOptions: { moduleName, hostOrigins: [origin], window: appWindow as any, host: hostWindow as any, timeoutMs: 500 },
|
|
183
195
|
connection,
|
|
196
|
+
providers,
|
|
184
197
|
iframe: effectiveIframe(o.manifestIframe, o.approved?.iframe),
|
|
185
198
|
calls,
|
|
186
199
|
notifications,
|
|
@@ -197,6 +210,7 @@ export function createTestHost(o: TestHostOptions = {}): TestHost {
|
|
|
197
210
|
goto: (path) => channel.emit('goto', { path, seq: Date.now() }),
|
|
198
211
|
visibility: (v) => channel.emit('visibility', v),
|
|
199
212
|
},
|
|
213
|
+
hostDown: () => connection.reset(),
|
|
200
214
|
destroy: () => connection.destroy(),
|
|
201
215
|
};
|
|
202
216
|
}
|