@sap-ux/preview-middleware 0.13.45 → 0.13.46

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 CHANGED
@@ -13,24 +13,24 @@ When this middleware is used together with the `reload-middleware`, then the ord
13
13
  ```
14
14
 
15
15
  ## Configuration Options
16
- | Option | Type | Default Value | Description |
17
- | ---------------------- | --------- | ---------------- | ----------------------------------------------------------------------------------------------------------------------------------- |
18
- | `flp` | | | Optional configuration object for the local Fiori launchpad |
19
- | `flp.path` | `string` | `/test/flp.html` | The mount point of the local Fiori launchpad. |
20
- | `flp.init` | `string` | `undefined` | Optional UI5 module/script to be executed after the standard initialization |
21
- | `flp.intent` | | | Optional intent to be used for the application |
22
- | `flp.intent.object` | `string` | `app` | Optional intent object |
23
- | `flp.intent.action` | `string` | `preview` | Optional intent action |
24
- | `flp.apps` | `array` | `undefined` | Optional additional local apps that are available in local Fiori launchpad |
16
+ | Option | Type | Default Value | Description |
17
+ | ---------------------- | --------- | ---------------- |-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
18
+ | `flp` | | | Optional configuration object for the local Fiori launchpad |
19
+ | `flp.path` | `string` | `/test/flp.html` | The mount point of the local Fiori launchpad. |
20
+ | `flp.init` | `string` | `undefined` | Optional UI5 module/script to be executed after the standard initialization |
21
+ | `flp.intent` | | | Optional intent to be used for the application |
22
+ | `flp.intent.object` | `string` | `app` | Optional intent object |
23
+ | `flp.intent.action` | `string` | `preview` | Optional intent action |
24
+ | `flp.apps` | `array` | `undefined` | Optional additional local apps that are available in local Fiori launchpad |
25
25
  | `flp.libs` | `boolean` | `undefined` | Optional flag to add a generic script fetching the paths of used libraries not available in UI5. To disable set it to `false`, if not set, then the project is checked for a `load-reuse-libs` script and if available the libraries are fetched as well. |
26
- | `flp.theme` | `string` | `undefined` | Optional flag for setting the UI5 Theme. |
27
- | `adp.target` | | | Required configuration for adaptation projects defining the connected backend |
28
- | `adp.ignoreCertErrors` | `boolean` | `false` | Optional setting to ignore certification validation errors when working with e.g. development systems with self signed certificates |
29
- | `rta` | | | Optional configuration allowing to add mount points for runtime adaptation |
30
- | `rta.layer` | `string` | `(calculated)` | Optional property for defining the runtime adaptation layer for changes (default is `CUSTOMER_BASE` or read from the project for adaptation projects) |
31
- | `rta.editors` | `array` | `undefined` | Optional list of mount points for editing |
32
- | `test` | `array` | `undefined` | Optional list of configurations for automated testing |
33
- | `debug` | `boolean` | `false` | Enables debug output |
26
+ | `flp.theme` | `string` | `undefined` | Optional flag for setting the UI5 Theme. |
27
+ | `adp.target` | | | Required configuration for adaptation projects defining the connected backend |
28
+ | `adp.ignoreCertErrors` | `boolean` | `false` | Optional setting to ignore certification validation errors when working with e.g. development systems with self signed certificates |
29
+ | `rta` | | | Optional configuration allowing to add mount points for runtime adaptation |
30
+ | `rta.layer` | `string` | `(calculated)` | Optional property for defining the runtime adaptation layer for changes (default is `CUSTOMER_BASE` or read from the project for adaptation projects) |
31
+ | `rta.editors` | `array` | `undefined` | Optional list of mount points for editing |
32
+ | `test` | `array` | `undefined` | Optional list of configurations for automated testing. |
33
+ | `debug` | `boolean` | `false` | Enables debug output |
34
34
 
35
35
  ### `flp.apps`
36
36
  Array of additional application configurations:
@@ -57,12 +57,12 @@ Array of additional application configurations:
57
57
  | `developerMode` | `boolean` optional | Enables/disables the runtime adaptation developer mode (only supported for adaptation projects) |
58
58
 
59
59
  ### `test`
60
- | Option | Type | Description |
61
- | --------------- | -------------------| -----------------------------------------------------------------------------------------------|
62
- | `framework` | `string` mandatory | Currently `OPA5` and `QUnit` are supported |
63
- | `path` | `string` optional | The mount point to be used for test suite |
64
- | `init` | `string` optional | The mount point to be used for test runner script |
65
- | `pattern` | `string` optional | Optional glob pattern to find the tests. By default `/test/**/*Journey.*` is used for `OPA5` and `/test/**/*Test.*` is used for `QUnit`|
60
+ | Option | Type | Description |
61
+ | --------------- | -------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------|
62
+ | `framework` | `string` mandatory | Currently `OPA5`, `QUnit` and `Testsuite` are supported. `Testsuite` will generate a testsuite for all configured frameworks that can be be used with a test runner (like e.g. karma) |
63
+ | `path` | `string` optional | The mount point to be used for test suite |
64
+ | `init` | `string` optional | The mount point to be used for test runner script |
65
+ | `pattern` | `string` optional | Optional glob pattern to find the tests. By default `/test/**/*Journey.*` is used for `OPA5` and `/test/**/*Test.*` is used for `QUnit` (n.a. for `Testsuite`) |
66
66
 
67
67
 
68
68
  ## Usage
@@ -130,6 +130,13 @@ export declare class FlpSandbox {
130
130
  * Create required routes for flex.
131
131
  */
132
132
  private createFlexHandler;
133
+ /**
134
+ * If it is part of TestConfig, create a test suite for the test configurations.
135
+ *
136
+ * @param configs test configurations
137
+ * @private
138
+ */
139
+ private createTestSuite;
133
140
  /**
134
141
  * Send a response with the given content type, status and body.
135
142
  * Ensure compliance with common APIs in express and connect.
package/dist/base/flp.js CHANGED
@@ -169,7 +169,8 @@ class FlpSandbox {
169
169
  this.addEditorRoutes(this.rta);
170
170
  }
171
171
  if (this.test) {
172
- this.addTestRoutes(this.test, id);
172
+ this.addTestRoutes(this.test.filter((config) => config.framework !== 'Testsuite'), id);
173
+ this.createTestSuite(this.test);
173
174
  }
174
175
  yield this.addRoutesForAdditionalApps();
175
176
  this.logger.info(`Initialized for app ${id}`);
@@ -382,6 +383,56 @@ class FlpSandbox {
382
383
  }
383
384
  })));
384
385
  }
386
+ /**
387
+ * If it is part of TestConfig, create a test suite for the test configurations.
388
+ *
389
+ * @param configs test configurations
390
+ * @private
391
+ */
392
+ createTestSuite(configs) {
393
+ const testsuiteConfig = configs.find((config) => config.framework === 'Testsuite');
394
+ if (!testsuiteConfig) {
395
+ //silent skip: create a testsuite only if it is explicitly part of the test configuration
396
+ return;
397
+ }
398
+ if (configs.length <= 1) {
399
+ this.logger.warn('Skip testsuite generation. No test frameworks configured.');
400
+ return;
401
+ }
402
+ const testsuite = (0, fs_1.readFileSync)((0, path_1.join)(__dirname, '../../templates/test/testsuite.qunit.html'), 'utf-8');
403
+ const initTemplate = (0, fs_1.readFileSync)((0, path_1.join)(__dirname, '../../templates/test/testsuite.qunit.js'), 'utf-8');
404
+ const config = (0, test_1.mergeTestConfigDefaults)(testsuiteConfig);
405
+ this.logger.debug(`Add route for ${config.path}`);
406
+ this.router.get(config.path, ((_req, res) => __awaiter(this, void 0, void 0, function* () {
407
+ this.logger.debug(`Serving test route: ${config.path}`);
408
+ const templateConfig = {
409
+ initPath: config.init
410
+ };
411
+ const html = (0, ejs_1.render)(testsuite, templateConfig);
412
+ this.sendResponse(res, 'text/html', 200, html);
413
+ })));
414
+ if (testsuiteConfig.init !== undefined) {
415
+ this.logger.debug(`Skip serving testsuite init script in favor of provided script: ${testsuiteConfig.init}`);
416
+ return;
417
+ }
418
+ const testPaths = [];
419
+ for (const testConfig of configs) {
420
+ if (testConfig.framework === 'Testsuite') {
421
+ continue;
422
+ }
423
+ const config = (0, test_1.mergeTestConfigDefaults)(testConfig);
424
+ testPaths.push(config.path);
425
+ }
426
+ this.logger.debug(`Add route for ${config.init}`);
427
+ this.router.get(config.init, ((_req, res) => __awaiter(this, void 0, void 0, function* () {
428
+ this.logger.debug(`Serving test route: ${config.init}`);
429
+ const templateConfig = {
430
+ testPaths: testPaths
431
+ };
432
+ const js = (0, ejs_1.render)(initTemplate, templateConfig);
433
+ this.sendResponse(res, 'application/javascript', 200, js);
434
+ })));
435
+ }
385
436
  /**
386
437
  * Send a response with the given content type, status and body.
387
438
  * Ensure compliance with common APIs in express and connect.
@@ -461,24 +512,18 @@ class FlpSandbox {
461
512
  * @param app configuration for the preview
462
513
  */
463
514
  addApp(manifest, app) {
464
- var _a, _b, _c, _d, _e, _f, _g, _h;
515
+ var _a, _b, _c, _d, _e, _f;
465
516
  return __awaiter(this, void 0, void 0, function* () {
466
517
  const id = manifest['sap.app'].id;
467
518
  (_a = app.intent) !== null && _a !== void 0 ? _a : (app.intent = {
468
519
  object: id.replace(/\./g, ''),
469
520
  action: 'preview'
470
521
  });
471
- let title = (_b = manifest['sap.app'].title) !== null && _b !== void 0 ? _b : id;
472
- let description = (_c = manifest['sap.app'].description) !== null && _c !== void 0 ? _c : '';
473
- if (app.local) {
474
- title = (_d = (yield this.getI18nTextFromProperty(app.local, manifest['sap.app'].title))) !== null && _d !== void 0 ? _d : id;
475
- description = (_e = (yield this.getI18nTextFromProperty(app.local, manifest['sap.app'].description))) !== null && _e !== void 0 ? _e : '';
476
- }
477
522
  this.templateConfig.ui5.resources[id] = app.target;
478
- this.templateConfig.apps[`${(_f = app.intent) === null || _f === void 0 ? void 0 : _f.object}-${(_g = app.intent) === null || _g === void 0 ? void 0 : _g.action}`] = {
479
- title: title,
480
- description: description,
481
- additionalInformation: `SAPUI5.Component=${(_h = app.componentId) !== null && _h !== void 0 ? _h : id}`,
523
+ this.templateConfig.apps[`${(_b = app.intent) === null || _b === void 0 ? void 0 : _b.object}-${(_c = app.intent) === null || _c === void 0 ? void 0 : _c.action}`] = {
524
+ title: (_d = (yield this.getI18nTextFromProperty(app.local, manifest['sap.app'].title))) !== null && _d !== void 0 ? _d : id,
525
+ description: (_e = (yield this.getI18nTextFromProperty(app.local, manifest['sap.app'].description))) !== null && _e !== void 0 ? _e : '',
526
+ additionalInformation: `SAPUI5.Component=${(_f = app.componentId) !== null && _f !== void 0 ? _f : id}`,
482
527
  applicationType: 'URL',
483
528
  url: app.target,
484
529
  applicationDependencies: { manifest: true }
@@ -497,7 +542,7 @@ class FlpSandbox {
497
542
  var _a, _b, _c, _d;
498
543
  return __awaiter(this, void 0, void 0, function* () {
499
544
  //i18n model format could be {{key}} or {i18n>key}
500
- if (!propertyValue || propertyValue.search(/{{\w+}}|{i18n>\w+}/g) === -1) {
545
+ if (!projectRoot || !propertyValue || propertyValue.search(/{{\w+}}|{i18n>\w+}/g) === -1) {
501
546
  return propertyValue;
502
547
  }
503
548
  const propertyI18nKey = propertyValue.replace(/i18n>|[{}]/g, '');
@@ -8,7 +8,7 @@ import type { TestConfig } from '../types';
8
8
  * @returns merged test configuration
9
9
  */
10
10
  export declare function mergeTestConfigDefaults(config: TestConfig): {
11
- framework: "OPA5" | "QUnit";
11
+ framework: "OPA5" | "QUnit" | "Testsuite";
12
12
  path: string;
13
13
  init: string;
14
14
  pattern: string;
package/dist/base/test.js CHANGED
@@ -13,6 +13,12 @@ const DEFAULTS = {
13
13
  init: '/test/opaTests.qunit.js',
14
14
  pattern: '/test/**/*Journey.*',
15
15
  framework: 'OPA5'
16
+ },
17
+ testsuite: {
18
+ path: '/test/testsuite.qunit.html',
19
+ init: '/test/testsuite.qunit.js',
20
+ pattern: '',
21
+ framework: 'Testsuite'
16
22
  }
17
23
  };
18
24
  /**
@@ -68,7 +68,7 @@ interface OptionalTestConfig {
68
68
  pattern: string;
69
69
  }
70
70
  export interface TestConfig extends Partial<OptionalTestConfig> {
71
- framework: 'OPA5' | 'QUnit';
71
+ framework: 'OPA5' | 'QUnit' | 'Testsuite';
72
72
  }
73
73
  export type InternalTestConfig = TestConfig & OptionalTestConfig;
74
74
  /**
package/package.json CHANGED
@@ -9,7 +9,7 @@
9
9
  "bugs": {
10
10
  "url": "https://github.com/SAP/open-ux-tools/issues?q=is%3Aopen+is%3Aissue+label%3Abug+label%3Apreview-middleware"
11
11
  },
12
- "version": "0.13.45",
12
+ "version": "0.13.46",
13
13
  "license": "Apache-2.0",
14
14
  "author": "@SAP/ux-tools-team",
15
15
  "main": "dist/index.js",
@@ -45,11 +45,11 @@
45
45
  "supertest": "6.3.3",
46
46
  "@sap-ux-private/playwright": "0.0.3",
47
47
  "dotenv": "16.3.1",
48
- "@private/preview-middleware-client": "npm:@sap-ux-private/preview-middleware-client@0.9.13",
49
48
  "@sap-ux/axios-extension": "1.12.4",
50
- "@sap-ux/store": "0.5.0",
49
+ "@private/preview-middleware-client": "npm:@sap-ux-private/preview-middleware-client@0.9.13",
51
50
  "@sap-ux/ui5-info": "0.5.0",
52
- "@sap-ux/i18n": "0.0.6"
51
+ "@sap-ux/i18n": "0.0.6",
52
+ "@sap-ux/store": "0.5.0"
53
53
  },
54
54
  "peerDependencies": {
55
55
  "express": "4"
@@ -0,0 +1,10 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <title>QUnit TestSuite</title>
5
+ <script src="/resources/sap/ui/qunit/qunit-redirect.js"></script>
6
+ <script src="<%- locals.initPath %>" data-sap-ui-testsuite></script>
7
+ </head>
8
+ <body>
9
+ </body>
10
+ </html>
@@ -0,0 +1,7 @@
1
+ window.suite = function () {
2
+ const oSuite = new parent.jsUnitTestSuite();
3
+ <% for (const path of locals.testPaths) { %>
4
+ oSuite.addTestPage("<%- path %>");
5
+ <% } %>
6
+ return oSuite;
7
+ }