Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

move Freestyle OPA templates to ui5-test-writer #2928

Open
wants to merge 48 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 41 commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
445fdda
adding simple handlebar templates
kjose90 Feb 7, 2025
08b3623
progress
kjose90 Feb 11, 2025
81204cb
clean up
kjose90 Feb 11, 2025
373b3ec
progress
kjose90 Feb 11, 2025
e971819
testing with templates
kjose90 Feb 12, 2025
96fdd0c
added OPA generate FF
kjose90 Feb 14, 2025
9e2a636
add ejs templates
kjose90 Feb 14, 2025
285aacf
clean code
kjose90 Feb 17, 2025
76f172a
revert shared gen util
kjose90 Feb 17, 2025
5362388
removing namespace use for freestyle tests
kjose90 Feb 18, 2025
79398f5
add logger to package json
kjose90 Feb 18, 2025
0953833
pnpm recursive install
kjose90 Feb 18, 2025
50021a0
Linting auto fix commit
github-actions[bot] Feb 18, 2025
06cd7fe
remove namespace reference and improvise code
kjose90 Feb 18, 2025
00fa2ce
Merge branch 'freestyle-test-templates' of https://github.com/SAP/ope…
kjose90 Feb 18, 2025
c1af110
remove unwanted type
kjose90 Feb 18, 2025
cfebc57
Linting auto fix commit
github-actions[bot] Feb 18, 2025
a146d30
add tests for freestyle templates
kjose90 Feb 19, 2025
0922a98
update fiori elements tests
kjose90 Feb 19, 2025
787ff1b
Merge branch 'freestyle-test-templates' of https://github.com/SAP/ope…
kjose90 Feb 19, 2025
2882a45
add correct path to fe integration test
kjose90 Feb 19, 2025
8c4575f
update ff snapshots
kjose90 Feb 19, 2025
d52877a
update snapshots for ff and fe writers
kjose90 Feb 19, 2025
bdf4248
sonar issues
kjose90 Feb 19, 2025
039b191
get app id slash logic
kjose90 Feb 20, 2025
d188059
change in test order in package scripts
kjose90 Feb 20, 2025
a955637
updating int test scripts
kjose90 Feb 20, 2025
0b90e95
removing use of flp sandbox and int flp sandbox
kjose90 Feb 20, 2025
af28e13
removing console log
kjose90 Feb 20, 2025
9bbd30f
lint issues
kjose90 Feb 20, 2025
0827a86
Merge branch 'main' into freestyle-test-templates
kjose90 Feb 20, 2025
a648ebe
add changeset
kjose90 Feb 20, 2025
c0fdcae
Merge branch 'freestyle-test-templates' of https://github.com/SAP/ope…
kjose90 Feb 20, 2025
31f4c16
refactoring
kjose90 Feb 20, 2025
eea7857
use project acces utils
kjose90 Feb 20, 2025
0934e34
Following the FE templates
kjose90 Feb 21, 2025
50b1f59
change index test names to fiori elements
kjose90 Feb 21, 2025
7846812
changeset
kjose90 Feb 21, 2025
2c98195
changeset
kjose90 Feb 21, 2025
a41d571
sonar issue fix
kjose90 Feb 21, 2025
f39778e
Merge branch 'main' into freestyle-test-templates
kjose90 Feb 21, 2025
e1356c1
split templates based on ui5 versions
kjose90 Feb 21, 2025
5561013
Merge branch 'freestyle-test-templates' of https://github.com/SAP/ope…
kjose90 Feb 21, 2025
1a3b739
sonar issue
kjose90 Feb 21, 2025
43d4c7f
add generateOPATests
kjose90 Feb 21, 2025
b3c74b8
add generateOPATests
kjose90 Feb 21, 2025
ed182a9
add viewpath to manifest template
kjose90 Feb 21, 2025
f814276
add tests to fiori freestyle
kjose90 Feb 21, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/shaggy-houses-pretend.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@sap-ux/fiori-freestyle-writer': minor
'@sap-ux/fiori-generator-shared': minor
'@sap-ux/ui5-test-writer': minor
---

Add Freestyle OPA templates to ui5-test-writer
2 changes: 2 additions & 0 deletions packages/fiori-freestyle-writer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
"@sap-ux/ui5-config": "workspace:*",
"@sap-ux/fiori-generator-shared": "workspace:*",
"@sap-ux/cap-config-writer": "workspace:*",
"@sap-ux/ui5-test-writer": "workspace:*",
"@sap-ux/logger": "workspace:*",
"ejs": "3.1.10",
"i18next": "20.6.1",
"lodash": "4.17.21",
Expand Down
41 changes: 38 additions & 3 deletions packages/fiori-freestyle-writer/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,34 @@ import { initI18n } from './i18n';
import { getBootstrapResourceUrls, getPackageScripts } from '@sap-ux/fiori-generator-shared';
import { getTemplateVersionPath, processDestinationPath } from './utils';
import { applyCAPUpdates, type CapProjectSettings } from '@sap-ux/cap-config-writer';
import type { Logger } from '@sap-ux/logger';
import { generateFreestyleOPAFiles } from '@sap-ux/ui5-test-writer';

/**
* Adds test scripts to the package.json object.
*
* @param {Package} packageJson - The package.json object to update.
* @param {boolean} addMock - Whether to include the UI5 mock YAML configuration.
*/
function addTestScripts(packageJson: Package, addMock: boolean): void {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please consider moving this to another function in another file along with all the test related code.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

moved to packages/fiori-freestyle-writer/src/generateOPATests.ts

// Note: 'ui5MockYamlScript' is empty when no data source is selected.
const ui5MockYamlScript = addMock ? '--config ./ui5-mock.yaml ' : '';
packageJson.scripts = {
...packageJson.scripts,
'unit-test': `fiori run ${ui5MockYamlScript}--open 'test/unit/unitTests.qunit.html'`,
'int-test': `fiori run ${ui5MockYamlScript}--open 'test/integration/opaTests.qunit.html'`
};
}
/**
* Generate a UI5 application based on the specified Fiori Freestyle floorplan template.
*
* @param basePath - the absolute target path where the application will be generated
* @param data - configuration to generate the freestyle application
* @param fs - an optional reference to a mem-fs editor
* @param log - optional logger
* @returns Reference to a mem-fs-editor
*/
async function generate<T>(basePath: string, data: FreestyleApp<T>, fs?: Editor): Promise<Editor> {
async function generate<T>(basePath: string, data: FreestyleApp<T>, fs?: Editor, log?: Logger): Promise<Editor> {
// Load i18n translations asynchronously to ensure proper initialization.
// This addresses occasional issues where i18n is not initialized in time, causing tests to fail.
await initI18n();
Expand Down Expand Up @@ -133,21 +151,38 @@ async function generate<T>(basePath: string, data: FreestyleApp<T>, fs?: Editor)
JSON.parse(render(fs.read(join(tmplPath, 'common', 'extend', 'package.json')), ffApp, {}))
);

const addTests = ffApp.appOptions?.addTests;
const packageJson: Package = JSON.parse(fs.read(packagePath));

if (isEdmxProjectType) {
const addMock = !!ffApp.service?.metadata;
// Add scripts for non-CAP applications
packageJson.scripts = {
...packageJson.scripts,
...getPackageScripts({
localOnly: !!ffApp.service && !ffApp.service?.url,
addMock: !!ffApp.service?.metadata,
addMock,
sapClient: ffApp.service?.client,
flpAppId: ffApp.app.flpAppId,
startFile: data?.app?.startFile,
localStartFile: data?.app?.localStartFile,
generateIndex: ffApp.appOptions?.generateIndex
generateIndex: ffApp.appOptions?.generateIndex,
addTest: addTests
})
};
if (addTests) {
addTestScripts(packageJson, addMock);
const config = {
appId: ffApp.app.id,
applicationDescription: ffApp.app.description,
applicationTitle: ffApp.app.title,
viewName: (ffApp.template.settings as BasicAppSettings).viewName,
ui5Theme: ffApp.ui5?.ui5Theme,
ui5Version: ffApp.ui5?.version,
enableTypeScript: ffApp.appOptions?.typescript
};
await generateFreestyleOPAFiles(basePath, config, fs, log);
}
} else {
// Add deploy-config for CAP applications
packageJson.scripts = {
Expand Down
9 changes: 8 additions & 1 deletion packages/fiori-freestyle-writer/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Ui5App, App } from '@sap-ux/ui5-application-writer';
import type { Ui5App, App, AppOptions } from '@sap-ux/ui5-application-writer';
import type { OdataService } from '@sap-ux/odata-service-writer';
import type { CapServiceCdsInfo } from '@sap-ux/cap-config-writer';

Expand Down Expand Up @@ -43,6 +43,13 @@ export interface FreestyleApp<T> extends Ui5App {
capService?: CapServiceCdsInfo;
};
app: FioriApp;
appOptions?: Partial<AppOptions> & {
/**
* Generate OPA based tests, for Simple template.
* This will eventually move up to {@link Ui5App.appOptions}
*/
addTests?: boolean;
};
}

// We need this for the service version
Expand Down
6 changes: 6 additions & 0 deletions packages/fiori-freestyle-writer/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
{
"path": "../fiori-generator-shared"
},
{
"path": "../logger"
},
{
"path": "../odata-service-writer"
},
Expand All @@ -27,6 +30,9 @@
},
{
"path": "../ui5-config"
},
{
"path": "../ui5-test-writer"
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ export interface PackageJsonScripts {
'start-noflp'?: string;
/** Optional command to start the application with a mock server configuration. */
'start-mock'?: string;
/** Optional command to run unit tests. */
'unit-test'?: string;
/** Optional command to run tests. */
'int-test'?: string;
/** Optional command to add the variants management script. */
Expand Down
4 changes: 3 additions & 1 deletion packages/ui5-test-writer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@
"ejs": "3.1.10",
"i18next": "20.6.1",
"mem-fs": "2.1.0",
"mem-fs-editor": "9.4.0"
"mem-fs-editor": "9.4.0",
"@sap-ux/ui5-application-writer": "workspace:*",
"@sap-ux/logger": "workspace:*"
},
"devDependencies": {
"@sap-ux/project-access": "workspace:*",
Expand Down
Loading