@sap-ux/ui5-test-writer 0.7.113 → 0.9.2

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.
@@ -10,6 +10,7 @@ import type { Logger } from '@sap-ux/logger';
10
10
  * @param opaConfig.scriptName - the name of the OPA journey file. If not specified, 'FirstJourney' will be used
11
11
  * @param opaConfig.htmlTarget - the name of the html that will be used in OPA journey file. If not specified, 'index.html' will be used
12
12
  * @param opaConfig.appID - the appID. If not specified, will be read from the manifest in sap.app/id
13
+ * @param opaConfig.useVirtualPreviewEndpoints - when true, OPA harness files are served virtually; skip writing them to disk
13
14
  * @param metadata - optional metadata for the OPA test generation
14
15
  * @param fs - an optional reference to a mem-fs editor
15
16
  * @param log - optional logger instance
@@ -20,6 +21,7 @@ export declare function generateOPAFiles(basePath: string, opaConfig: {
20
21
  scriptName?: string;
21
22
  appID?: string;
22
23
  htmlTarget?: string;
24
+ useVirtualPreviewEndpoints?: boolean;
23
25
  }, metadata?: string, fs?: Editor, log?: Logger, standalone?: boolean): Promise<Editor>;
24
26
  /**
25
27
  * Reads the manifest for an app.
@@ -23,6 +23,7 @@ const flpSandboxUtils_1 = require("./utils/flpSandboxUtils");
23
23
  * @param opaConfig.scriptName - the name of the OPA journey file. If not specified, 'FirstJourney' will be used
24
24
  * @param opaConfig.htmlTarget - the name of the html that will be used in OPA journey file. If not specified, 'index.html' will be used
25
25
  * @param opaConfig.appID - the appID. If not specified, will be read from the manifest in sap.app/id
26
+ * @param opaConfig.useVirtualPreviewEndpoints - when true, OPA harness files are served virtually; skip writing them to disk
26
27
  * @param metadata - optional metadata for the OPA test generation
27
28
  * @param fs - an optional reference to a mem-fs editor
28
29
  * @param log - optional logger instance
@@ -64,8 +65,11 @@ async function generateOPAFiles(basePath, opaConfig, metadata, fs, log, standalo
64
65
  }
65
66
  }
66
67
  else {
67
- writeCommonAndPageFiles(writeContext, rootCommonTemplateDirPath);
68
- writeJourneyFiles(appFeatures, writeContext, false);
68
+ writeCommonAndPageFiles(writeContext, rootCommonTemplateDirPath, opaConfig.useVirtualPreviewEndpoints ?? false);
69
+ writeJourneyFiles(appFeatures, writeContext, false, false, opaConfig.useVirtualPreviewEndpoints ?? false);
70
+ if (opaConfig.useVirtualPreviewEndpoints) {
71
+ await (0, opaQUnitUtils_1.addVirtualTestConfig)(basePath, [{ framework: 'OPA5', path: '/test/integration/opaTests.qunit.html' }, { framework: 'Testsuite' }], editor);
72
+ }
69
73
  }
70
74
  return editor;
71
75
  }
@@ -307,15 +311,18 @@ function findLROP(pages, manifest) {
307
311
  *
308
312
  * @param writeContext - shared write context (config, paths, editor, journey params)
309
313
  * @param rootCommonTemplateDirPath - template root directory for common files
314
+ * @param useVirtualPreviewEndpoints - when true, testsuite harness files are served virtually; skip writing them to disk
310
315
  */
311
- function writeCommonAndPageFiles(writeContext, rootCommonTemplateDirPath) {
316
+ function writeCommonAndPageFiles(writeContext, rootCommonTemplateDirPath, useVirtualPreviewEndpoints = false) {
312
317
  const { config, rootV4TemplateDirPath, testOutDirPath, editor, journeyParams } = writeContext;
313
- // Common test files
314
- editor.copyTpl((0, node_path_1.join)(rootCommonTemplateDirPath), testOutDirPath,
315
- // unit tests are not added for Fiori elements app
316
- { appId: config.appID }, undefined, {
317
- globOptions: { dot: true }
318
- });
318
+ // Common test files (testsuite served virtually when useVirtualPreviewEndpoints is enabled)
319
+ if (!useVirtualPreviewEndpoints) {
320
+ editor.copyTpl((0, node_path_1.join)(rootCommonTemplateDirPath), testOutDirPath,
321
+ // unit tests are not added for Fiori elements app
322
+ { appId: config.appID }, undefined, {
323
+ globOptions: { dot: true }
324
+ });
325
+ }
319
326
  config.pages.forEach((page) => {
320
327
  writePageObject(page, rootV4TemplateDirPath, testOutDirPath, editor);
321
328
  });
@@ -108,7 +108,7 @@ function getDestFilePath(filePath, freestyleTemplateDir, commonTemplateDir, temp
108
108
  */
109
109
  async function generateFreestyleOPAFiles(basePath, opaConfig, fs, log) {
110
110
  const fsEditor = fs ?? (0, mem_fs_editor_1.create)((0, mem_fs_1.create)());
111
- const { enableTypeScript, ui5Version, viewName, appId } = opaConfig;
111
+ const { enableTypeScript, ui5Version, viewName, appId, useVirtualPreviewEndpoints } = opaConfig;
112
112
  const freestyleTemplateDir = (0, node_path_1.join)(__dirname, '../templates/freestyle/webapp/test');
113
113
  const commonTemplateDir = (0, node_path_1.join)(__dirname, '../templates/common');
114
114
  const testOutDir = (0, node_path_1.join)(basePath, 'webapp/test');
@@ -118,11 +118,14 @@ async function generateFreestyleOPAFiles(basePath, opaConfig, fs, log) {
118
118
  const templateFiles = await (0, project_access_1.getFilePaths)(freestyleTemplateDir);
119
119
  const isTypeScript = Boolean(enableTypeScript);
120
120
  const templateFilteredFiles = filterByUi5Version(templateFiles, templateUi5Version);
121
- const filteredFiles = filterByTypeScript(templateFilteredFiles, isTypeScript);
122
- // copy common templates
123
- const commonFiles = await (0, project_access_1.getFilePaths)(commonTemplateDir);
124
- const filteredCommonFiles = commonFiles.filter((filePath) => filePath.endsWith('.html'));
125
- filteredFiles.push(...filteredCommonFiles);
121
+ let filteredFiles = filterByTypeScript(templateFilteredFiles, isTypeScript);
122
+ if (useVirtualPreviewEndpoints) {
123
+ filteredFiles = filteredFiles.filter((filePath) => !['testsuite.qunit', 'unitTests.qunit', 'opaTests.qunit'].some((pattern) => filePath.includes(pattern)));
124
+ }
125
+ else {
126
+ const commonFiles = await (0, project_access_1.getFilePaths)(commonTemplateDir);
127
+ filteredFiles.push(...commonFiles.filter((f) => f.endsWith('.html')));
128
+ }
126
129
  const config = {
127
130
  ...opaConfig,
128
131
  viewNamePage: `${viewName}Page`,
package/dist/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  export { generateOPAFiles } from './fiori-elements-opa-writer';
2
2
  export { generateFreestyleOPAFiles } from './fiori-freestyle-opa-writer';
3
+ export { addVirtualTestConfig } from './utils/opaQUnitUtils';
3
4
  //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -1,8 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.generateFreestyleOPAFiles = exports.generateOPAFiles = void 0;
3
+ exports.addVirtualTestConfig = exports.generateFreestyleOPAFiles = exports.generateOPAFiles = void 0;
4
4
  var fiori_elements_opa_writer_1 = require("./fiori-elements-opa-writer");
5
5
  Object.defineProperty(exports, "generateOPAFiles", { enumerable: true, get: function () { return fiori_elements_opa_writer_1.generateOPAFiles; } });
6
6
  var fiori_freestyle_opa_writer_1 = require("./fiori-freestyle-opa-writer");
7
7
  Object.defineProperty(exports, "generateFreestyleOPAFiles", { enumerable: true, get: function () { return fiori_freestyle_opa_writer_1.generateFreestyleOPAFiles; } });
8
+ var opaQUnitUtils_1 = require("./utils/opaQUnitUtils");
9
+ Object.defineProperty(exports, "addVirtualTestConfig", { enumerable: true, get: function () { return opaQUnitUtils_1.addVirtualTestConfig; } });
8
10
  //# sourceMappingURL=index.js.map
package/dist/types.d.ts CHANGED
@@ -75,6 +75,7 @@ export interface FFOPAConfig {
75
75
  viewName?: string;
76
76
  ui5Version?: string;
77
77
  ui5Theme?: string;
78
+ useVirtualPreviewEndpoints?: boolean;
78
79
  }
79
80
  export type ObjectPageNavigationParents = {
80
81
  parentLRName?: string;
@@ -4,6 +4,7 @@
4
4
  * all other content (formatting, comments, whitespace) is preserved exactly.
5
5
  */
6
6
  import type { Editor } from 'mem-fs-editor';
7
+ import type { TestConfig as PreviewMiddlewareTestConfig } from '@sap-ux/preview-middleware';
7
8
  /**
8
9
  * Splices new module paths into the sap.ui.require array of the content string.
9
10
  * Entries that are already present are skipped. All other content is preserved exactly.
@@ -90,4 +91,13 @@ export declare function addPagesToJourneyRunner(pages: JourneyRunnerPage[], test
90
91
  * @returns true when OPA5 is configured in a preview middleware, false otherwise
91
92
  */
92
93
  export declare function hasVirtualOPA5(basePath: string): Promise<boolean>;
94
+ /**
95
+ * Updates the fiori-tools-preview middleware in ui5-mock.yaml to support virtual OPA test endpoints.
96
+ * Adds test framework entries to ui5-mock.yaml.
97
+ *
98
+ * @param basePath - the absolute target path of the application
99
+ * @param testFrameworks - the test framework entries to add to ui5-mock.yaml
100
+ * @param fs - the memfs editor instance
101
+ */
102
+ export declare function addVirtualTestConfig(basePath: string, testFrameworks: PreviewMiddlewareTestConfig[], fs: Editor): Promise<void>;
93
103
  //# sourceMappingURL=opaQUnitUtils.d.ts.map
@@ -12,6 +12,7 @@ exports.addPathsToQUnitJs = addPathsToQUnitJs;
12
12
  exports.splicePageIntoJourneyRunner = splicePageIntoJourneyRunner;
13
13
  exports.addPagesToJourneyRunner = addPagesToJourneyRunner;
14
14
  exports.hasVirtualOPA5 = hasVirtualOPA5;
15
+ exports.addVirtualTestConfig = addVirtualTestConfig;
15
16
  const node_path_1 = require("node:path");
16
17
  const flpSandboxUtils_1 = require("./flpSandboxUtils");
17
18
  const project_access_1 = require("@sap-ux/project-access");
@@ -300,4 +301,25 @@ async function hasVirtualOPA5(basePath) {
300
301
  }
301
302
  return false;
302
303
  }
304
+ /**
305
+ * Updates the fiori-tools-preview middleware in ui5-mock.yaml to support virtual OPA test endpoints.
306
+ * Adds test framework entries to ui5-mock.yaml.
307
+ *
308
+ * @param basePath - the absolute target path of the application
309
+ * @param testFrameworks - the test framework entries to add to ui5-mock.yaml
310
+ * @param fs - the memfs editor instance
311
+ */
312
+ async function addVirtualTestConfig(basePath, testFrameworks, fs) {
313
+ const yamlPath = (0, node_path_1.join)(basePath, project_access_1.FileName.Ui5MockYaml);
314
+ if (!fs.exists(yamlPath)) {
315
+ return;
316
+ }
317
+ const yamlConfig = await (0, project_access_1.readUi5Yaml)(basePath, project_access_1.FileName.Ui5MockYaml, fs);
318
+ const previewMiddleware = yamlConfig.findCustomMiddleware('fiori-tools-preview');
319
+ if (previewMiddleware?.configuration && !previewMiddleware.configuration.test?.length) {
320
+ previewMiddleware.configuration.test = [...testFrameworks];
321
+ yamlConfig.updateCustomMiddleware(previewMiddleware);
322
+ fs.write(yamlPath, yamlConfig.toString());
323
+ }
324
+ }
303
325
  //# sourceMappingURL=opaQUnitUtils.js.map
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@sap-ux/ui5-test-writer",
3
3
  "description": "SAP UI5 tests writer",
4
- "version": "0.7.113",
4
+ "version": "0.9.2",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "https://github.com/SAP/open-ux-tools.git",
@@ -27,10 +27,11 @@
27
27
  "@sap/ux-specification": "1.144.0",
28
28
  "@sap-ux/edmx-parser": "0.10.0",
29
29
  "@sap-ux/annotation-converter": "0.10.21",
30
- "@sap-ux/ui5-application-writer": "1.8.8",
31
- "@sap-ux/logger": "0.8.5",
32
- "@sap-ux/fiori-generator-shared": "0.14.1",
33
- "@sap-ux/project-access": "1.36.4"
30
+ "@sap-ux/ui5-application-writer": "1.9.0",
31
+ "@sap-ux/logger": "0.9.0",
32
+ "@sap-ux/fiori-generator-shared": "0.15.1",
33
+ "@sap-ux/project-access": "1.37.0",
34
+ "@sap-ux/preview-middleware": "0.26.2"
34
35
  },
35
36
  "devDependencies": {
36
37
  "@types/ejs": "3.1.5",
@@ -40,10 +41,10 @@
40
41
  "rimraf": "6.1.3",
41
42
  "fs-extra": "11.3.4",
42
43
  "@sap-ux/vocabularies-types": "0.15.0",
43
- "@sap-ux/jest-file-matchers": "0.2.11"
44
+ "@sap-ux/jest-file-matchers": "0.3.0"
44
45
  },
45
46
  "engines": {
46
- "node": ">=20.x"
47
+ "node": ">=22.x"
47
48
  },
48
49
  "scripts": {
49
50
  "build": "tsc --build",