Skip to content

Commit

Permalink
move Freestyle OPA templates to ui5-test-writer (#2928)
Browse files Browse the repository at this point in the history
* adding simple handlebar templates

* progress

* clean up

* progress

* testing with templates

* added OPA generate FF

* add ejs templates

* clean code

* revert shared gen util

* removing namespace use for freestyle tests

* add logger to package json

* pnpm recursive install

* Linting auto fix commit

* remove namespace reference and improvise code

* remove unwanted type

* Linting auto fix commit

* add tests for freestyle templates

* update fiori elements tests

* add correct path to fe integration test

* update ff snapshots

* update snapshots for ff and fe writers

* sonar issues

* get app id slash logic

* change in test order in package scripts

* updating int test scripts

* removing use of flp sandbox and int flp sandbox

* removing console log

* lint issues

* add changeset

* refactoring

* use project acces utils

* Following the FE templates

* change index test names to fiori elements

* changeset

* changeset

* sonar issue fix

* split templates based on ui5 versions

* sonar issue

* add generateOPATests

* add generateOPATests

* add viewpath to manifest template

* add tests to fiori freestyle

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Austin Devine <[email protected]>
  • Loading branch information
3 people authored Feb 24, 2025
1 parent eaef48a commit fffc3a7
Show file tree
Hide file tree
Showing 60 changed files with 2,699 additions and 436 deletions.
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
53 changes: 53 additions & 0 deletions packages/fiori-freestyle-writer/src/generateOPATests.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { generateFreestyleOPAFiles } from '@sap-ux/ui5-test-writer';
import type { Package } from '@sap-ux/ui5-application-writer';
import type { FreestyleApp, BasicAppSettings } from './types';
import type { Logger } from '@sap-ux/logger';
import type { Editor } from 'mem-fs-editor';

/**
* 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 {
// 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'`
};
}

/**
* Generates OPA tests for a freestyle application.
*
* @param {string} basePath - The base directory path.
* @param {FreestyleApp} ffApp - The freestyle application configuration.
* @param {boolean} addMock - Whether to include the UI5 mock YAML configuration.
* @param {Package} packageJson - The package.json object to update.
* @param {Editor} [fs] - Optional file system editor instance.
* @param {Logger} [log] - Optional logger instance.
* @returns {Promise<Editor>} - The modified file system editor.
*/
export async function generateOPATests<T>(
basePath: string,
ffApp: FreestyleApp<T>,
addMock: boolean,
packageJson: Package,
fs?: Editor,
log?: Logger
): Promise<void> {
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);
}
16 changes: 13 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,19 @@ 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 { generateOPATests } from './generateOPATests';

/**
* 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 +136,28 @@ 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) {
await generateOPATests(basePath, ffApp, addMock, packageJson, 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
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"rootView": {
"viewName": "<%- app.id %>.view.App",
"type": "XML",
"id": "App"
"id": "App",
"async": true
},
"resources": {
"css": [
Expand All @@ -20,7 +21,9 @@
"transition": "slide",
"type": "View",
"viewType": "XML",
"path": "<%- app.id %>.view"
"path": "<%- app.id %>.view",
"async": true,
"viewPath": "<%- app.id %>.view"
},
"routes": [
{
Expand Down
Loading

0 comments on commit fffc3a7

Please sign in to comment.