Skip to content

Commit 865fb96

Browse files
authored
fix(ui5-test-writer): app info generation fixes (#4611)
* move integration fix, various other fixes * update snapshots * add tests * changeset * review feedback
1 parent fcde876 commit 865fb96

18 files changed

Lines changed: 2027 additions & 12 deletions

File tree

.changeset/odd-hounds-see.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@sap-ux/ui5-test-writer': patch
3+
---
4+
5+
fixes for app info generation

packages/ui5-test-writer/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
"mem-fs-editor": "9.4.0",
3939
"@sap-ux/ui5-application-writer": "workspace:*",
4040
"@sap-ux/logger": "workspace:*",
41+
"@sap-ux/fiori-generator-shared": "workspace:*",
4142
"@sap-ux/project-access": "workspace:*",
4243
"@sap/ux-specification": "1.144.0",
4344
"@sap-ux/edmx-parser": "0.10.0",

packages/ui5-test-writer/src/fiori-elements-opa-writer.ts

Lines changed: 72 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import type {
1414
} from './types';
1515
import { SupportedPageTypes, ValidationError } from './types';
1616
import { t } from './i18n';
17-
import { FileName, DirName, getWebappPath } from '@sap-ux/project-access';
17+
import { FileName, DirName, getWebappPath, updatePackageScript } from '@sap-ux/project-access';
1818
import type { Logger } from '@sap-ux/logger';
1919
import { getAppFeatures } from './utils/modelUtils';
2020
import {
@@ -25,6 +25,8 @@ import {
2525
readHtmlTargetFromQUnitJs,
2626
type JourneyRunnerPage
2727
} from './utils/opaQUnitUtils';
28+
import { getPackageScripts } from '@sap-ux/fiori-generator-shared';
29+
import { readHashFromFlpSandbox } from './utils/flpSandboxUtils';
2830

2931
/**
3032
* Generate OPA test files for a Fiori elements for OData V4 application.
@@ -80,12 +82,12 @@ export async function generateOPAFiles(
8082
if (hasJourneyRunner) {
8183
writeJourneyFiles(appFeatures, writeContext, true, true, virtualOPA5Configured);
8284
} else {
83-
editor.move(join(testOutDirPath, 'integration', '**'), join(testOutDirPath, 'integration_old'));
84-
85-
await addIntegrationOldToGitignore(basePath, editor);
86-
const htmlTarget = readHtmlTargetFromQUnitJs(testOutDirPath, editor) ?? config.htmlTarget;
87-
const standaloneConfig = { ...config, htmlTarget };
88-
const standaloneWriteContext: WriteContext = { ...writeContext, config: standaloneConfig };
85+
const standaloneWriteContext = await resolveStandaloneWriteContext(
86+
basePath,
87+
testOutDirPath,
88+
writeContext,
89+
editor
90+
);
8991
if (!virtualOPA5Configured) {
9092
writeCommonAndPageFiles(standaloneWriteContext, rootCommonTemplateDirPath);
9193
}
@@ -99,6 +101,69 @@ export async function generateOPAFiles(
99101
return editor;
100102
}
101103

104+
/**
105+
* Resolves the write context for standalone mode when no JourneyRunner.js exists yet.
106+
* Moves any existing integration folder to integration_old, or adds the int-test script
107+
* and resolves the htmlTarget from flpSandbox.html if present.
108+
*
109+
* @param basePath - the absolute target path of the application
110+
* @param testOutDirPath - output test directory (.../webapp/test)
111+
* @param writeContext - shared write context to base the resolved context on
112+
* @param editor - a reference to a mem-fs editor
113+
* @returns a new WriteContext with the resolved htmlTarget
114+
*/
115+
async function resolveStandaloneWriteContext(
116+
basePath: string,
117+
testOutDirPath: string,
118+
writeContext: WriteContext,
119+
editor: Editor
120+
): Promise<WriteContext> {
121+
const { config } = writeContext;
122+
let htmlTarget = readHtmlTargetFromQUnitJs(testOutDirPath, editor) ?? config.htmlTarget;
123+
124+
if (existsSync(join(testOutDirPath, 'integration'))) {
125+
editor.move(join(testOutDirPath, 'integration', '**'), join(testOutDirPath, 'integration_old'));
126+
await addIntegrationOldToGitignore(basePath, editor);
127+
} else {
128+
const hasIntTestScript = checkScriptInPackageJson(editor, basePath, 'int-test');
129+
if (!hasIntTestScript) {
130+
const script = getPackageScripts({ localOnly: false, addTest: true })['int-test'];
131+
if (script) {
132+
await updatePackageScript(basePath, 'int-test', script, editor);
133+
}
134+
}
135+
if (existsSync(join(testOutDirPath, 'flpSandbox.html'))) {
136+
const hashFromFlpSandbox = readHashFromFlpSandbox(
137+
join('test', 'flpSandbox.html'),
138+
await getWebappPath(basePath),
139+
editor
140+
);
141+
if (hashFromFlpSandbox) {
142+
htmlTarget = `test/flpSandbox.html#${hashFromFlpSandbox}`;
143+
}
144+
}
145+
}
146+
147+
return { ...writeContext, config: { ...config, htmlTarget } };
148+
}
149+
150+
/**
151+
* Checks whether a script with the given name exists in the package.json.
152+
*
153+
* @param editor - a reference to a mem-fs editor
154+
* @param basePath - the root folder of the app
155+
* @param scriptName - the name of the script to check for
156+
* @returns true if the script exists, false otherwise
157+
*/
158+
function checkScriptInPackageJson(editor: Editor, basePath: string, scriptName: string): boolean {
159+
const packageJsonPath = join(basePath, FileName.Package);
160+
if (!editor.exists(packageJsonPath)) {
161+
return false;
162+
}
163+
const packageJson = editor.readJSON(packageJsonPath) as { scripts?: Record<string, string> };
164+
return !!packageJson.scripts?.[scriptName];
165+
}
166+
102167
/**
103168
* Reads the manifest for an app.
104169
*

packages/ui5-test-writer/templates/v4/integration/ListReportJourney.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ sap.ui.define([
3939
});
4040
<%_ } -%>
4141

42+
<%_ if ((toolBarActions && toolBarActions.length > 0 ) || (tableColumns && Object.keys(tableColumns).length > 0)) { -%>
4243
opaTest("Check table columns and actions", function (Given, When, Then) {
4344
<%_ if (toolBarActions && toolBarActions.length > 0) { -%>
4445
<%_ if (createButton.visible && !isALP) { _%>
@@ -57,9 +58,10 @@ sap.ui.define([
5758
<%_ }); -%>
5859
<%_ } -%>
5960
<%_ if (tableColumns && Object.keys(tableColumns).length > 0) { -%>
60-
Then.onThe<%- startLR %>.onTable().iCheckColumns(<%- Object.keys(tableColumns).length %>, <%- JSON.stringify(tableColumns) %>);
61+
Then.onThe<%- startLR %>.onTable().iCheckColumns(undefined, <%- JSON.stringify(tableColumns) %>);
6162
<%_ } %>
6263
});
64+
<%_ } %>
6365

6466
<% if (startLR) { %>
6567
opaTest("Navigate to ObjectPage", function (Given, When, Then) {
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"name": "project3",
3+
"version": "0.0.1",
4+
"description": "An SAP Fiori application.",
5+
"keywords": [
6+
"ui5",
7+
"openui5",
8+
"sapui5"
9+
],
10+
"main": "webapp/index.html",
11+
"dependencies": {},
12+
"devDependencies": {
13+
"@ui5/cli": "^4.0.33",
14+
"@sap/ux-ui5-tooling": "1",
15+
"@sap-ux/eslint-plugin-fiori-tools": "^9.0.0",
16+
"eslint": "^9",
17+
"@sap-ux/ui5-middleware-fe-mockserver": "2"
18+
},
19+
"scripts": {
20+
"start": "fiori run --open \"test/flp.html#app-preview\"",
21+
"start-local": "fiori run --config ./ui5-local.yaml --open \"test/flp.html#app-preview\"",
22+
"build": "ui5 build --config=ui5.yaml --clean-dest --dest dist",
23+
"lint": "eslint ./",
24+
"start-mock": "fiori run --config ./ui5-mock.yaml --open \"test/flp.html#app-preview\"",
25+
"deploy": "fiori verify",
26+
"deploy-config": "fiori add deploy-config",
27+
"start-noflp": "fiori run --open \"/index.html?sap-ui-xx-viewCache=false\"",
28+
"start-variants-management": "fiori run --open \"/preview.html#app-preview\""
29+
},
30+
"sapuxLayer": "VENDOR",
31+
"sapux": true
32+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# yaml-language-server: $schema=https://sap.github.io/ui5-tooling/schema/ui5.yaml.json
2+
3+
specVersion: "4.0"
4+
metadata:
5+
name: project3
6+
type: application
7+
framework:
8+
name: SAPUI5
9+
version: 1.146.0
10+
libraries:
11+
- name: sap.m
12+
- name: sap.ui.core
13+
- name: sap.fe.templates
14+
- name: sap.ushell
15+
- name: themelib_sap_horizon
16+
server:
17+
customMiddleware:
18+
- name: fiori-tools-appreload
19+
afterMiddleware: compression
20+
configuration:
21+
port: 35729
22+
path: webapp
23+
delay: 300
24+
- name: fiori-tools-preview
25+
afterMiddleware: fiori-tools-appreload
26+
configuration:
27+
flp:
28+
theme: sap_horizon
29+
path: test/flp.html
30+
- name: fiori-tools-proxy
31+
afterMiddleware: compression
32+
configuration:
33+
ignoreCertErrors: false # If set to true, certificate errors will be ignored. E.g. self-signed certificates will be accepted
34+
backend:
35+
- path: /sap
36+
url: https://sap-ux-mock-services-v4-lrop.cfapps.us10.hana.ondemand.com
37+
- name: sap-fe-mockserver
38+
beforeMiddleware: csp
39+
configuration:
40+
mountPath: /
41+
services:
42+
- urlPath: /sap/opu/odata4/dmo/sb_travel_mdsk_o4/srvd/dmo/sd_travel_mdsk/0001
43+
metadataPath: ./webapp/localService/mainService/metadata.xml
44+
mockdataPath: ./webapp/localService/mainService/data
45+
generateMockData: true
46+
annotations: []
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# yaml-language-server: $schema=https://sap.github.io/ui5-tooling/schema/ui5.yaml.json
2+
3+
specVersion: "4.0"
4+
metadata:
5+
name: project3
6+
type: application
7+
server:
8+
customMiddleware:
9+
- name: fiori-tools-proxy
10+
afterMiddleware: compression
11+
configuration:
12+
ignoreCertErrors: false # If set to true, certificate errors will be ignored. E.g. self-signed certificates will be accepted
13+
ui5:
14+
path:
15+
- /resources
16+
- /test-resources
17+
url: https://ui5.sap.com
18+
backend:
19+
- path: /sap
20+
url: https://sap-ux-mock-services-v4-lrop.cfapps.us10.hana.ondemand.com
21+
- name: fiori-tools-appreload
22+
afterMiddleware: compression
23+
configuration:
24+
port: 35729
25+
path: webapp
26+
delay: 300
27+
- name: fiori-tools-preview
28+
afterMiddleware: fiori-tools-appreload
29+
configuration:
30+
flp:
31+
theme: sap_horizon
32+
path: test/flp.html
33+
test:
34+
- framework: OPA5
35+
path: /test/integration/opaTests.qunit.html
36+
- framework: Testsuite
37+
- name: sap-fe-mockserver
38+
beforeMiddleware: csp
39+
configuration:
40+
mountPath: /
41+
services:
42+
- urlPath: /sap/opu/odata4/dmo/sb_travel_mdsk_o4/srvd/dmo/sd_travel_mdsk/0001
43+
metadataPath: ./webapp/localService/mainService/metadata.xml
44+
mockdataPath: ./webapp/localService/mainService/data
45+
generateMockData: true
46+
annotations: []
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# yaml-language-server: $schema=https://sap.github.io/ui5-tooling/schema/ui5.yaml.json
2+
3+
specVersion: "4.0"
4+
metadata:
5+
name: project3
6+
type: application
7+
server:
8+
customMiddleware:
9+
- name: fiori-tools-proxy
10+
afterMiddleware: compression
11+
configuration:
12+
ignoreCertErrors: false # If set to true, certificate errors will be ignored. E.g. self-signed certificates will be accepted
13+
ui5:
14+
path:
15+
- /resources
16+
- /test-resources
17+
url: https://ui5.sap.com
18+
backend:
19+
- path: /sap
20+
url: https://odataserviceurl
21+
- name: fiori-tools-appreload
22+
afterMiddleware: compression
23+
configuration:
24+
port: 35729
25+
path: webapp
26+
delay: 300
27+
- name: fiori-tools-preview
28+
afterMiddleware: fiori-tools-appreload
29+
configuration:
30+
flp:
31+
theme: sap_horizon
32+
path: test/flp.html
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
sap.ui.define(
2+
["sap/fe/core/AppComponent"],
3+
function (Component) {
4+
"use strict";
5+
6+
return Component.extend("project3.Component", {
7+
metadata: {
8+
manifest: "json"
9+
}
10+
});
11+
}
12+
);
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<edmx:Edmx xmlns:edmx="http://docs.oasis-open.org/odata/ns/edmx" Version="4.0">
2+
<edmx:Reference Uri="https://sap.github.io/odata-vocabularies/vocabularies/Common.xml">
3+
<edmx:Include Namespace="com.sap.vocabularies.Common.v1" Alias="Common"/>
4+
</edmx:Reference>
5+
<edmx:Reference Uri="https://sap.github.io/odata-vocabularies/vocabularies/UI.xml">
6+
<edmx:Include Namespace="com.sap.vocabularies.UI.v1" Alias="UI"/>
7+
</edmx:Reference>
8+
<edmx:Reference Uri="https://sap.github.io/odata-vocabularies/vocabularies/Communication.xml">
9+
<edmx:Include Namespace="com.sap.vocabularies.Communication.v1" Alias="Communication"/>
10+
</edmx:Reference>
11+
<edmx:Reference Uri="/sap/opu/odata4/dmo/sb_travel_mdsk_o4/srvd/dmo/sd_travel_mdsk/0001/$metadata">
12+
<edmx:Include Namespace="com.sap.gateway.srvd.dmo.sd_travel_mdsk.v0001" Alias="SAP__self"/>
13+
</edmx:Reference>
14+
<edmx:DataServices>
15+
<Schema xmlns="http://docs.oasis-open.org/odata/ns/edm" Namespace="local">
16+
</Schema>
17+
</edmx:DataServices>
18+
</edmx:Edmx>

0 commit comments

Comments
 (0)