From ddc2d842581a430310ac88e8229e473ab8541f5e Mon Sep 17 00:00:00 2001 From: Andis Redmans <90789422+815are@users.noreply.github.com> Date: Mon, 16 Sep 2024 09:08:15 +0300 Subject: [PATCH] feat(fe-fpm-writer): reuse 'async getManifest' function and make API methods async (#2367) * feat: reuse get manifest function and make api methods async reuse get manifest function and make api methods async * fix: additional missed place additional missed place * test: adjust integration tests adjust integration tests * test: adjust consumer code adjust consumer code * changelog changelog * fix: lint lint * fix: missed todo missed todo * fix: lint lint --- .changeset/short-brooms-clean.md | 5 ++ .changeset/warm-days-admire.md | 5 ++ packages/fe-fpm-writer/src/action/index.ts | 7 +- packages/fe-fpm-writer/src/app/index.ts | 10 +-- .../fe-fpm-writer/src/building-block/index.ts | 30 +------ packages/fe-fpm-writer/src/column/index.ts | 12 ++- packages/fe-fpm-writer/src/common/types.ts | 14 +++ packages/fe-fpm-writer/src/common/utils.ts | 33 ++++++- .../src/controller-extension/index.ts | 11 ++- packages/fe-fpm-writer/src/filter/index.ts | 6 +- packages/fe-fpm-writer/src/page/common.ts | 18 ++-- packages/fe-fpm-writer/src/page/custom.ts | 8 +- packages/fe-fpm-writer/src/page/list.ts | 2 +- packages/fe-fpm-writer/src/page/object.ts | 2 +- packages/fe-fpm-writer/src/section/index.ts | 33 ++++--- packages/fe-fpm-writer/src/view/index.ts | 6 +- .../test/integration/basic-lrop-app.test.ts | 60 ++++++------- .../fe-fpm-writer/test/unit/action.test.ts | 70 +++++++-------- packages/fe-fpm-writer/test/unit/app.test.ts | 22 ++--- .../fe-fpm-writer/test/unit/column.test.ts | 66 +++++++------- .../test/unit/controller-extension.test.ts | 40 ++++----- .../fe-fpm-writer/test/unit/filter.test.ts | 65 +++++++------- .../test/unit/header-section.test.ts | 28 +++--- .../test/unit/page/common.test.ts | 16 ++-- .../test/unit/page/custom.test.ts | 86 ++++++++++--------- .../fe-fpm-writer/test/unit/page/list.test.ts | 26 +++--- .../test/unit/page/object.test.ts | 38 ++++---- .../fe-fpm-writer/test/unit/section.test.ts | 82 +++++++++--------- .../test/unit/subsection.test.ts | 12 +-- packages/fe-fpm-writer/test/unit/view.test.ts | 66 +++++++------- .../fiori-elements-writer/src/fpmConfig.ts | 2 +- 31 files changed, 463 insertions(+), 418 deletions(-) create mode 100644 .changeset/short-brooms-clean.md create mode 100644 .changeset/warm-days-admire.md diff --git a/.changeset/short-brooms-clean.md b/.changeset/short-brooms-clean.md new file mode 100644 index 0000000000..5ca542d487 --- /dev/null +++ b/.changeset/short-brooms-clean.md @@ -0,0 +1,5 @@ +--- +'@sap-ux/fe-fpm-writer': minor +--- + +The API methods `generateCustomAction`, `generateCustomColumn`, `generateControllerExtension`, `generateCustomFilter`, `generateCustomHeaderSection`, `generateCustomSection`, `generateCustomSubSection`, `generateCustomPage`, `generateObjectPage`, `generateListReport`, `enableFPM` changed from synchronous to asynchronous. diff --git a/.changeset/warm-days-admire.md b/.changeset/warm-days-admire.md new file mode 100644 index 0000000000..855477f4ab --- /dev/null +++ b/.changeset/warm-days-admire.md @@ -0,0 +1,5 @@ +--- +'@sap-ux/fiori-elements-writer': patch +--- + +call 'generateCustomPage' from 'fe-fpm-writer' as async function diff --git a/packages/fe-fpm-writer/src/action/index.ts b/packages/fe-fpm-writer/src/action/index.ts index 848314b604..67e0d678a7 100644 --- a/packages/fe-fpm-writer/src/action/index.ts +++ b/packages/fe-fpm-writer/src/action/index.ts @@ -3,7 +3,6 @@ import type { Editor } from 'mem-fs-editor'; import { create } from 'mem-fs-editor'; import type { CustomAction, CustomActionTarget, InternalCustomAction } from './types'; import { TargetControl } from './types'; -import { join } from 'path'; import { render } from 'ejs'; import { validateVersion, validateBasePath } from '../common/validate'; import type { Manifest } from '../common/types'; @@ -11,6 +10,7 @@ import { setCommonDefaults } from '../common/defaults'; import { applyEventHandlerConfiguration, contextParameter } from '../common/event-handler'; import { getTemplatePath } from '../templates'; import { getJsonSpace } from '../common/file'; +import { getManifest } from '../common/utils'; /** * Enhances the provided custom action configuration with default data. @@ -88,15 +88,14 @@ export function enhanceManifestAndGetActionsElementReference(manifest: any, targ * @param {Editor} [fs] - the memfs editor instance * @returns {Promise} the updated memfs editor instance */ -export function generateCustomAction(basePath: string, actionConfig: CustomAction, fs?: Editor): Editor { +export async function generateCustomAction(basePath: string, actionConfig: CustomAction, fs?: Editor): Promise { validateVersion(actionConfig.minUI5Version); if (!fs) { fs = create(createStorage()); } validateBasePath(basePath, fs); - const manifestPath = join(basePath, 'webapp/manifest.json'); - const manifest = fs.readJSON(manifestPath) as Manifest; + const { path: manifestPath, content: manifest } = await getManifest(basePath, fs); const config = enhanceConfig(actionConfig, manifestPath, manifest); diff --git a/packages/fe-fpm-writer/src/app/index.ts b/packages/fe-fpm-writer/src/app/index.ts index e13fa36ae7..184be6262c 100644 --- a/packages/fe-fpm-writer/src/app/index.ts +++ b/packages/fe-fpm-writer/src/app/index.ts @@ -6,7 +6,7 @@ import { lt, valid } from 'semver'; import { getMinUI5VersionAsArray, getMinimumUI5Version, type Manifest } from '@sap-ux/project-access'; import { FCL_ROUTER } from '../common/defaults'; import { getTemplatePath } from '../templates'; -import { addExtensionTypes } from '../common/utils'; +import { addExtensionTypes, getManifest } from '../common/utils'; /** * Configurable options when enabling the Flexible Programming Model in a UI5 application. @@ -79,16 +79,12 @@ function adaptMinUI5Version(manifest: Manifest, fs: Editor, manifestPath: string * @param {Editor} [fs] - the mem-fs editor instance * @returns {Promise} the updated mem-fs editor instance */ -export function enableFPM(basePath: string, config: FPMConfig = {}, fs?: Editor): Editor { +export async function enableFPM(basePath: string, config: FPMConfig = {}, fs?: Editor): Promise { if (!fs) { fs = create(createStorage()); } - const manifestPath = join(basePath, 'webapp/manifest.json'); - if (!fs.exists(manifestPath)) { - throw new Error(`Invalid project folder. Cannot find required file ${manifestPath}`); - } - const manifest = fs.readJSON(manifestPath) as any as Manifest; + const { path: manifestPath, content: manifest } = await getManifest(basePath, fs); // add FE libs is not yet added if (!manifest['sap.ui5']?.dependencies?.libs?.['sap.fe.templates']) { diff --git a/packages/fe-fpm-writer/src/building-block/index.ts b/packages/fe-fpm-writer/src/building-block/index.ts index c97e0017ac..aabb2a2025 100644 --- a/packages/fe-fpm-writer/src/building-block/index.ts +++ b/packages/fe-fpm-writer/src/building-block/index.ts @@ -12,8 +12,9 @@ import { getTemplatePath } from '../templates'; import { CodeSnippetLanguage, type FilePathProps, type CodeSnippet } from '../prompts/types'; import { coerce, lt } from 'semver'; import type { Manifest } from '../common/types'; -import { getMinimumUI5Version, getWebappPath } from '@sap-ux/project-access'; +import { getMinimumUI5Version } from '@sap-ux/project-access'; import { detectTabSpacing, extendJSON } from '../common/file'; +import { getManifest, getManifestPath } from '../common/utils'; const PLACEHOLDERS = { 'id': 'REPLACE_WITH_BUILDING_BLOCK_ID', @@ -26,29 +27,6 @@ interface MetadataPath { metaPath: string; } -/** - * Gets manifest path. - * - * @param {string} basePath the base path - * @param {Editor} fs the memfs editor instance - * @returns {Manifest | undefined} path to manifest file - */ -async function getManifestPath(basePath: string, fs: Editor): Promise { - return join(await getWebappPath(basePath, fs), 'manifest.json'); -} - -/** - * Gets manifest content. - * - * @param {string} basePath the base path - * @param {Editor} fs the memfs editor instance - * @returns {Manifest | undefined} the manifest content - */ -async function getManifest(basePath: string, fs: Editor): Promise { - const manifestPath = await getManifestPath(basePath, fs); - return fs.readJSON(manifestPath) as Manifest; -} - /** * Generates a building block into the provided xml view file. * @@ -74,7 +52,7 @@ export async function generateBuildingBlock( // Read the view xml and template files and update contents of the view xml file const xmlDocument = getUI5XmlDocument(basePath, config.viewOrFragmentPath, fs); - const manifest = await getManifest(basePath, fs); + const { content: manifest } = await getManifest(basePath, fs); const templateDocument = getTemplateDocument(config.buildingBlockData, xmlDocument, fs, manifest); fs = updateViewFile(basePath, config.viewOrFragmentPath, config.aggregationPath, xmlDocument, templateDocument, fs); @@ -352,7 +330,7 @@ export async function getSerializedFileContent( const xmlDocument = config.viewOrFragmentPath ? getUI5XmlDocument(basePath, config.viewOrFragmentPath, fs) : undefined; - const manifest = await getManifest(basePath, fs); + const { content: manifest } = await getManifest(basePath, fs, false); const content = getTemplateContent(config.buildingBlockData, xmlDocument, manifest, fs, true); const filePathProps = getFilePathProps(basePath, config.viewOrFragmentPath); return { diff --git a/packages/fe-fpm-writer/src/column/index.ts b/packages/fe-fpm-writer/src/column/index.ts index 79ac8002cb..0ce7848140 100644 --- a/packages/fe-fpm-writer/src/column/index.ts +++ b/packages/fe-fpm-writer/src/column/index.ts @@ -11,6 +11,7 @@ import { applyEventHandlerConfiguration } from '../common/event-handler'; import { extendJSON } from '../common/file'; import { getTemplatePath } from '../templates'; import { coerce, gte } from 'semver'; +import { getManifest } from '../common/utils'; /** * Get the template folder for the given UI5 version. @@ -72,17 +73,20 @@ function enhanceConfig( * @returns {Promise} the updated mem-fs editor instance * @param {string} basePath - the base path * @param {CustomTableColumn} customColumn - the custom column configuration - * @param {Editor} [fs] - the mem-fs editor instance + * @param {Promise} [fs] - the mem-fs editor instance */ -export function generateCustomColumn(basePath: string, customColumn: CustomTableColumn, fs?: Editor): Editor { +export async function generateCustomColumn( + basePath: string, + customColumn: CustomTableColumn, + fs?: Editor +): Promise { validateVersion(customColumn.minUI5Version); if (!fs) { fs = create(createStorage()); } validateBasePath(basePath, fs); - const manifestPath = join(basePath, 'webapp/manifest.json'); - const manifest = fs.readJSON(manifestPath) as Manifest; + const { path: manifestPath, content: manifest } = await getManifest(basePath, fs); // merge with defaults const completeColumn = enhanceConfig(fs, customColumn, manifestPath, manifest); diff --git a/packages/fe-fpm-writer/src/common/types.ts b/packages/fe-fpm-writer/src/common/types.ts index 21a858a9ba..a9702a8fb5 100644 --- a/packages/fe-fpm-writer/src/common/types.ts +++ b/packages/fe-fpm-writer/src/common/types.ts @@ -194,3 +194,17 @@ export interface FragmentContentData { content: string; requireAttribute?: string; } + +/** + * Interface contain information about application manifest. + */ +export interface ManifestData { + /** + * Path to manifest.json file. + */ + path: string; + /** + * Parsed content of manifest.json file. + */ + content: Manifest; +} diff --git a/packages/fe-fpm-writer/src/common/utils.ts b/packages/fe-fpm-writer/src/common/utils.ts index 87dd6e10c8..191fbc6ee9 100644 --- a/packages/fe-fpm-writer/src/common/utils.ts +++ b/packages/fe-fpm-writer/src/common/utils.ts @@ -2,8 +2,9 @@ import type { Editor } from 'mem-fs-editor'; import os from 'os'; import { join } from 'path'; import { coerce, minor } from 'semver'; +import { getWebappPath } from '@sap-ux/project-access'; import { getTemplatePath } from '../templates'; -import type { FileContentPosition } from '../common/types'; +import type { FileContentPosition, Manifest, ManifestData } from './types'; /** * Method inserts passed text into content by char index position. @@ -68,3 +69,33 @@ export function addExtensionTypes(basePath: string, minUI5Version: string | unde fs.copyTpl(getTemplatePath('common/sap.fe.d.ts'), path, { version }); } } + +/** + * Gets manifest path. + * + * @param {string} basePath the base path + * @param {Editor} fs the memfs editor instance + * @returns {Manifest | undefined} path to manifest file + */ +export async function getManifestPath(basePath: string, fs: Editor): Promise { + return join(await getWebappPath(basePath, fs), 'manifest.json'); +} + +/** + * Gets content and path of the manifest. + * + * @param {string} basePath the base path + * @param {Editor} fs the memfs editor instance + * @param {boolean} [validate] validate if 'manifest.json' file exists - throw error if file does not exist + * @returns {Manifest | undefined} The content and path of the manifest + */ +export async function getManifest(basePath: string, fs: Editor, validate = true): Promise { + const path = await getManifestPath(basePath, fs); + if (validate && !fs.exists(path)) { + throw new Error(`Invalid project folder. Cannot find required file ${path}`); + } + return { + path, + content: fs.readJSON(path) as Manifest + }; +} diff --git a/packages/fe-fpm-writer/src/controller-extension/index.ts b/packages/fe-fpm-writer/src/controller-extension/index.ts index db1289b652..5d22de84d7 100644 --- a/packages/fe-fpm-writer/src/controller-extension/index.ts +++ b/packages/fe-fpm-writer/src/controller-extension/index.ts @@ -14,7 +14,7 @@ import { validateBasePath } from '../common/validate'; import type { Manifest } from '../common/types'; import { setCommonDefaults } from '../common/defaults'; import { getTemplatePath } from '../templates'; -import { addExtensionTypes } from '../common/utils'; +import { addExtensionTypes, getManifest } from '../common/utils'; import { extendJSON } from '../common/file'; export const UI5_CONTROLLER_EXTENSION_LIST_REPORT = 'sap.fe.templates.ListReport.ListReportController'; @@ -206,21 +206,20 @@ function getManifestReplacer( * @param {string} basePath - the base path * @param {ControllerExtension} controllerConfig - the controller extension configuration * @param {Editor} [fs] - the memfs editor instance - * @returns {Editor} the updated memfs editor instance + * @returns {Promise} the updated memfs editor instance */ -export function generateControllerExtension( +export async function generateControllerExtension( basePath: string, controllerConfig: ControllerExtension, fs?: Editor -): Editor { +): Promise { // Validate the base and view paths if (!fs) { fs = create(createStorage()); } validateBasePath(basePath, fs); - const manifestPath = join(basePath, 'webapp/manifest.json'); - const manifest = fs.readJSON(manifestPath) as Manifest; + const { path: manifestPath, content: manifest } = await getManifest(basePath, fs); // merge with defaults const internalConfig = enhanceConfig(controllerConfig, manifestPath, manifest); diff --git a/packages/fe-fpm-writer/src/filter/index.ts b/packages/fe-fpm-writer/src/filter/index.ts index 6eb0d0d26f..3500d19d6c 100644 --- a/packages/fe-fpm-writer/src/filter/index.ts +++ b/packages/fe-fpm-writer/src/filter/index.ts @@ -12,6 +12,7 @@ import { getJsonSpace } from '../common/file'; import { applyEventHandlerConfiguration, contextParameter } from '../common/event-handler'; import type { FilterField } from '../building-block/types'; import type { ManifestNamespace } from '@sap-ux/project-access'; +import { getManifest } from '../common/utils'; /** * Enhances the provided custom filter configuration with default data. @@ -49,14 +50,13 @@ function enhanceConfig(data: CustomFilter, manifestPath: string, manifest: Manif * @param {Editor} [fs] - the memfs editor instance * @returns {Promise} the updated memfs editor instance */ -export function generateCustomFilter(basePath: string, filterConfig: CustomFilter, fs?: Editor): Editor { +export async function generateCustomFilter(basePath: string, filterConfig: CustomFilter, fs?: Editor): Promise { if (!fs) { fs = create(createStorage()); } validateBasePath(basePath, fs); - const manifestPath = join(basePath, 'webapp/manifest.json'); - const manifest = fs.readJSON(manifestPath) as Manifest; + const { path: manifestPath, content: manifest } = await getManifest(basePath, fs); const config = enhanceConfig(filterConfig, manifestPath, manifest); // Apply event handler diff --git a/packages/fe-fpm-writer/src/page/common.ts b/packages/fe-fpm-writer/src/page/common.ts index 0813d1e9b7..5e5401e6b6 100644 --- a/packages/fe-fpm-writer/src/page/common.ts +++ b/packages/fe-fpm-writer/src/page/common.ts @@ -1,7 +1,6 @@ import type { Editor } from 'mem-fs-editor'; import { create as createStorage } from 'mem-fs'; import { create } from 'mem-fs-editor'; -import { join } from 'path'; import { render } from 'ejs'; import type { ManifestNamespace } from '@sap-ux/project-access'; import { validateBasePath } from '../common/validate'; @@ -23,6 +22,7 @@ import { FCL_ROUTER } from '../common/defaults'; import { extendJSON } from '../common/file'; import { getTemplatePath } from '../templates'; import { coerce, gte } from 'semver'; +import { getManifest } from '../common/utils'; type EnhancePageConfigFunction = ( data: ObjectPage | ListReport, @@ -212,19 +212,20 @@ export function initializeTargetSettings( * @param dependencies - expected dependencies * @returns the updated memfs editor instance */ -export function validatePageConfig( +export async function validatePageConfig( basePath: string, config: CustomPage | ObjectPage, fs: Editor, dependencies = [] -): Editor { +): Promise { // common validators validateBasePath(basePath, fs, dependencies); // validate config against the manifest if (config.navigation?.sourcePage) { - const manifest = fs.readJSON(join(basePath, 'webapp/manifest.json')) as Manifest; + const { content: manifest } = await getManifest(basePath, fs); + if (!manifest['sap.ui5']?.routing?.targets?.[config.navigation.sourcePage]) { throw new Error(`Could not find navigation source ${config.navigation.sourcePage}!`); } @@ -257,20 +258,19 @@ export function validatePageConfig( * @param fs - the memfs editor instance * @returns the updated memfs editor instance */ -export function extendPageJSON( +export async function extendPageJSON( basePath: string, data: ObjectPage, enhanceDataFn: EnhancePageConfigFunction, templatePath: string, fs?: Editor -): Editor { +): Promise { if (!fs) { fs = create(createStorage()); } - validatePageConfig(basePath, data, fs); + await validatePageConfig(basePath, data, fs); - const manifestPath = join(basePath, 'webapp/manifest.json'); - const manifest = fs.readJSON(manifestPath) as Manifest; + const { path: manifestPath, content: manifest } = await getManifest(basePath, fs); const config = enhanceDataFn(data, manifest); diff --git a/packages/fe-fpm-writer/src/page/custom.ts b/packages/fe-fpm-writer/src/page/custom.ts index ec592b6ed2..a08cfbc861 100644 --- a/packages/fe-fpm-writer/src/page/custom.ts +++ b/packages/fe-fpm-writer/src/page/custom.ts @@ -17,7 +17,7 @@ import type { Manifest } from '../common/types'; import { validateVersion } from '../common/validate'; import { getTemplatePath } from '../templates'; import { coerce, gte } from 'semver'; -import { addExtensionTypes } from '../common/utils'; +import { addExtensionTypes, getManifestPath } from '../common/utils'; import { extendJSON } from '../common/file'; /** @@ -74,14 +74,14 @@ export function getTemplateRoot(ui5Version?: string): string { * @param {Editor} [fs] - the memfs editor instance * @returns {Promise} the updated memfs editor instance */ -export function generate(basePath: string, data: CustomPage, fs?: Editor): Editor { +export async function generate(basePath: string, data: CustomPage, fs?: Editor): Promise { if (!fs) { fs = create(createStorage()); } validateVersion(data.minUI5Version); - validatePageConfig(basePath, data, fs, []); + await validatePageConfig(basePath, data, fs, []); - const manifestPath = join(basePath, 'webapp/manifest.json'); + const manifestPath = await getManifestPath(basePath, fs); const config = enhanceData(data, manifestPath, fs); diff --git a/packages/fe-fpm-writer/src/page/list.ts b/packages/fe-fpm-writer/src/page/list.ts index f88c6130c8..b92083fb5c 100644 --- a/packages/fe-fpm-writer/src/page/list.ts +++ b/packages/fe-fpm-writer/src/page/list.ts @@ -45,6 +45,6 @@ function enhanceData(data: ListReport, manifest: Manifest): InternalListReport { * @param fs - the memfs editor instance * @returns the updated memfs editor instance */ -export function generate(basePath: string, data: ListReport, fs?: Editor): Editor { +export async function generate(basePath: string, data: ListReport, fs?: Editor): Promise { return extendPageJSON(basePath, data, enhanceData, 'page/list/manifest.json', fs); } diff --git a/packages/fe-fpm-writer/src/page/object.ts b/packages/fe-fpm-writer/src/page/object.ts index 57712c2ffc..69c0ec046d 100644 --- a/packages/fe-fpm-writer/src/page/object.ts +++ b/packages/fe-fpm-writer/src/page/object.ts @@ -37,6 +37,6 @@ function enhanceData(data: ObjectPage, manifest: Manifest): InternalObjectPage { * @param fs - the memfs editor instance * @returns the updated memfs editor instance */ -export function generate(basePath: string, data: ObjectPage, fs?: Editor): Editor { +export async function generate(basePath: string, data: ObjectPage, fs?: Editor): Promise { return extendPageJSON(basePath, data, enhanceData, '/page/object/manifest.json', fs); } diff --git a/packages/fe-fpm-writer/src/section/index.ts b/packages/fe-fpm-writer/src/section/index.ts index 5423fe3811..99f02e138c 100644 --- a/packages/fe-fpm-writer/src/section/index.ts +++ b/packages/fe-fpm-writer/src/section/index.ts @@ -11,6 +11,7 @@ import { applyEventHandlerConfiguration } from '../common/event-handler'; import { extendJSON } from '../common/file'; import { getTemplatePath } from '../templates'; import { coerce, gte } from 'semver'; +import { getManifest } from '../common/utils'; type CustomSectionUnion = CustomHeaderSection | CustomSection | CustomSubSection; @@ -91,20 +92,19 @@ function enhanceConfig( * @param {Editor} [fs] - the mem-fs editor instance * @returns {Promise} the updated mem-fs editor instance */ -function generate( +async function generate( basePath: string, customSection: CustomSectionUnion, manifestTemplateRoot: string, fs?: Editor -): { editor: Editor; section: InternalCustomSection } { +): Promise<{ editor: Editor; section: InternalCustomSection }> { validateVersion(customSection.minUI5Version); if (!fs) { fs = create(createStorage()); } validateBasePath(basePath, fs); - const manifestPath = join(basePath, 'webapp/manifest.json'); - const manifest = fs.readJSON(manifestPath) as Manifest; + const { path: manifestPath, content: manifest } = await getManifest(basePath, fs); // merge with defaults const completeSection = enhanceConfig(fs, customSection, manifestPath, manifest); @@ -134,11 +134,11 @@ function generate( * @param {Editor} [fs] - the mem-fs editor instance * @returns {Promise} the updated mem-fs editor instance */ -export function generateCustomHeaderSection( +export async function generateCustomHeaderSection( basePath: string, customHeaderSection: CustomHeaderSection, fs?: Editor -): Editor { +): Promise { if (!fs) { fs = create(createStorage()); } @@ -148,13 +148,12 @@ export function generateCustomHeaderSection( // Prepare 'templateEdit' - apply namespace and folder path resolution if (customHeaderSection.edit && (!minVersion || gte(minVersion, '1.86.0'))) { editSection = customHeaderSection.edit; - const manifestPath = join(basePath, 'webapp/manifest.json'); - const manifest = fs.readJSON(manifestPath) as Manifest; + const { path: manifestPath, content: manifest } = await getManifest(basePath, fs); // Set folder, ns and path for edit fragment setCommonDefaults(editSection, manifestPath, manifest); } // Call standard custom section generation - const { editor, section } = generate(basePath, customHeaderSection, manifestRoot, fs); + const { editor, section } = await generate(basePath, customHeaderSection, manifestRoot, fs); // Handle 'templateEdit' - edit fragment details if (editSection) { // Apply event handler for edit fragment @@ -192,9 +191,13 @@ export function generateCustomHeaderSection( * @param {Editor} [fs] - the mem-fs editor instance * @returns {Promise} the updated mem-fs editor instance */ -export function generateCustomSection(basePath: string, customSection: CustomSection, fs?: Editor): Editor { +export async function generateCustomSection( + basePath: string, + customSection: CustomSection, + fs?: Editor +): Promise { const manifestRoot = getManifestRoot('section', customSection.minUI5Version); - return generate(basePath, customSection, manifestRoot, fs).editor; + return (await generate(basePath, customSection, manifestRoot, fs)).editor; } /** @@ -205,7 +208,11 @@ export function generateCustomSection(basePath: string, customSection: CustomSec * @param {Editor} [fs] - the mem-fs editor instance * @returns {Promise} the updated mem-fs editor instance */ -export function generateCustomSubSection(basePath: string, customSubSection: CustomSubSection, fs?: Editor): Editor { +export async function generateCustomSubSection( + basePath: string, + customSubSection: CustomSubSection, + fs?: Editor +): Promise { const manifestRoot = getManifestRoot('subsection', customSubSection.minUI5Version); - return generate(basePath, customSubSection, manifestRoot, fs).editor; + return (await generate(basePath, customSubSection, manifestRoot, fs)).editor; } diff --git a/packages/fe-fpm-writer/src/view/index.ts b/packages/fe-fpm-writer/src/view/index.ts index d0004e37ab..7ab904a49a 100644 --- a/packages/fe-fpm-writer/src/view/index.ts +++ b/packages/fe-fpm-writer/src/view/index.ts @@ -10,6 +10,7 @@ import { setCommonDefaults, getDefaultFragmentContent } from '../common/defaults import { applyEventHandlerConfiguration } from '../common/event-handler'; import { extendJSON } from '../common/file'; import { getTemplatePath } from '../templates'; +import { getManifest } from '../common/utils'; /** * Merge the new view into the list of existing views (if any). @@ -85,15 +86,14 @@ function enhanceConfig(fs: Editor, data: CustomView, manifestPath: string, manif * @param {Editor} [fs] - the mem-fs editor instance * @returns {Promise} the updated mem-fs editor instance */ -export function generateCustomView(basePath: string, customView: CustomView, fs?: Editor): Editor { +export async function generateCustomView(basePath: string, customView: CustomView, fs?: Editor): Promise { validateVersion(customView.minUI5Version); if (!fs) { fs = create(createStorage()); } validateBasePath(basePath, fs); - const manifestPath = join(basePath, 'webapp/manifest.json'); - const manifest = fs.readJSON(manifestPath) as Manifest; + const { path: manifestPath, content: manifest } = await getManifest(basePath, fs); // merge with defaults const completeView = enhanceConfig(fs, customView, manifestPath, manifest); diff --git a/packages/fe-fpm-writer/test/integration/basic-lrop-app.test.ts b/packages/fe-fpm-writer/test/integration/basic-lrop-app.test.ts index b92b2f4513..29eaa2d2e8 100644 --- a/packages/fe-fpm-writer/test/integration/basic-lrop-app.test.ts +++ b/packages/fe-fpm-writer/test/integration/basic-lrop-app.test.ts @@ -55,16 +55,16 @@ describe('use FPM with existing apps', () => { fs.copy(join(testInput, 'ts'), tsConfig.path, { globOptions: { dot: true } }); }); - test.each(configs)('enableFpm', (config) => { - enableFPM(config.path, config.settings, fs); + test.each(configs)('enableFpm', async (config) => { + await enableFPM(config.path, config.settings, fs); }); - test.each(configs)('generateListReport', (config) => { - generateListReport(config.path, { entity: mainEntity, ...config.settings }, fs); + test.each(configs)('generateListReport', async (config) => { + await generateListReport(config.path, { entity: mainEntity, ...config.settings }, fs); }); - test.each(configs)('generateObjectPage with navigation from ListReport', (config) => { - generateObjectPage( + test.each(configs)('generateObjectPage with navigation from ListReport', async (config) => { + await generateObjectPage( config.path, { entity: mainEntity, @@ -79,8 +79,8 @@ describe('use FPM with existing apps', () => { ); }); - test.each(configs)('generateCustomPage with navigation from ObjectPage', (config) => { - generateCustomPage( + test.each(configs)('generateCustomPage with navigation from ObjectPage', async (config) => { + await generateCustomPage( config.path, { name: 'MyCustomPage', @@ -95,8 +95,8 @@ describe('use FPM with existing apps', () => { ); }); - test.each(configs)('generateCustomColumn in ListReport', (config) => { - generateCustomColumn( + test.each(configs)('generateCustomColumn in ListReport', async (config) => { + await generateCustomColumn( config.path, { target: 'TravelListReport', @@ -115,7 +115,7 @@ describe('use FPM with existing apps', () => { ); }); - test.each(configs)('generateCustomView in ListReport', (config) => { + test.each(configs)('generateCustomView in ListReport', async (config) => { //pre-requisite is at least one view based on annotations fs.extendJSON(join(config.path, 'webapp/manifest.json'), { 'sap.ui5': { @@ -139,7 +139,7 @@ describe('use FPM with existing apps', () => { } } }); - generateCustomView( + await generateCustomView( config.path, { target: 'TravelListReport', @@ -153,8 +153,8 @@ describe('use FPM with existing apps', () => { ); }); - test.each(configs)('generateCustomView in ListReport, custom view to be overwritten', (config) => { - generateCustomView( + test.each(configs)('generateCustomView in ListReport, custom view to be overwritten', async (config) => { + await generateCustomView( config.path, { target: 'TravelListReport', @@ -169,8 +169,8 @@ describe('use FPM with existing apps', () => { ); }); - test.each(configs)('generateCustomView in ListReport, second custom view', (config) => { - generateCustomView( + test.each(configs)('generateCustomView in ListReport, second custom view', async (config) => { + await generateCustomView( config.path, { target: 'TravelListReport', @@ -184,8 +184,8 @@ describe('use FPM with existing apps', () => { ); }); - test.each(configs)('generateCustomAction in ListReport and ObjectPage', (config) => { - generateCustomAction( + test.each(configs)('generateCustomAction in ListReport and ObjectPage', async (config) => { + await generateCustomAction( config.path, { name: 'MyCustomAction', @@ -201,7 +201,7 @@ describe('use FPM with existing apps', () => { }, fs ); - generateCustomAction( + await generateCustomAction( config.path, { name: 'AnotherCustomAction', @@ -222,7 +222,7 @@ describe('use FPM with existing apps', () => { ? `\nexport function onAppended() {\n\twindow.location.href += '/_Booking';\n}` : `,\n onAppended: function() {\n window.location.href += '/_Booking';\n }`; const position = config.settings.typescript ? { line: 13, character: 9 } : { line: 8, character: 9 }; - generateCustomAction( + await generateCustomAction( config.path, { name: 'AppendedAction', @@ -248,8 +248,8 @@ describe('use FPM with existing apps', () => { ); }); - test.each(configs)('generateCustomSection in ObjectPage', (config) => { - generateCustomSection( + test.each(configs)('generateCustomSection in ObjectPage', async (config) => { + await generateCustomSection( config.path, { name: 'MyCustomSection', @@ -266,8 +266,8 @@ describe('use FPM with existing apps', () => { ); }); - test.each(configs)('generateCustomFilter in ListReportPage', (config) => { - generateCustomFilter( + test.each(configs)('generateCustomFilter in ListReportPage', async (config) => { + await generateCustomFilter( config.path, { name: 'NewCustomFilter', @@ -285,8 +285,8 @@ describe('use FPM with existing apps', () => { ); }); - test.each(configs)('generateControllerExtension in ObjectPage', (config) => { - generateControllerExtension( + test.each(configs)('generateControllerExtension in ObjectPage', async (config) => { + await generateControllerExtension( config.path, { name: 'MyControllerExtension', @@ -299,8 +299,8 @@ describe('use FPM with existing apps', () => { ); }); - test.each(configs)('generateCustomSubSection in ObjectPage', (config) => { - generateCustomSubSection( + test.each(configs)('generateCustomSubSection in ObjectPage', async (config) => { + await generateCustomSubSection( config.path, { name: 'MyCustomSubSection', @@ -318,8 +318,8 @@ describe('use FPM with existing apps', () => { ); }); - test.each(configs)('generateCustomHeaderSection in ObjectPage', (config) => { - generateCustomHeaderSection( + test.each(configs)('generateCustomHeaderSection in ObjectPage', async (config) => { + await generateCustomHeaderSection( config.path, { name: 'MyCustomHeaderSection', diff --git a/packages/fe-fpm-writer/test/unit/action.test.ts b/packages/fe-fpm-writer/test/unit/action.test.ts index 8e985f2a44..4cc13e2486 100644 --- a/packages/fe-fpm-writer/test/unit/action.test.ts +++ b/packages/fe-fpm-writer/test/unit/action.test.ts @@ -69,14 +69,14 @@ describe('CustomAction', () => { fs.write(join(testDir, 'webapp/manifest.json'), testAppManifest); }); - test('minimal settings (no eventhandler)', () => { - generateCustomAction(testDir, { name, target, settings }, fs); + test('minimal settings (no eventhandler)', async () => { + await generateCustomAction(testDir, { name, target, settings }, fs); expect(fs.readJSON(join(testDir, 'webapp/manifest.json'))).toMatchSnapshot(); expect(fs.exists(join(testDir, 'webapp/ext/myCustomAction/MyCustomAction.js'))).toBeFalsy(); }); - test('with new event handler as string', () => { - generateCustomAction( + test('with new event handler as string', async () => { + await generateCustomAction( testDir, { name, @@ -91,10 +91,10 @@ describe('CustomAction', () => { expect(fs.readJSON(join(testDir, 'webapp/manifest.json'))).toMatchSnapshot(); }); - test('with existing event handler as string', () => { + test('with existing event handler as string', async () => { const controllerPath = 'my.test.App.ext.ExistingHandler.onCustomAction'; fs.write(controllerPath, 'dummyContent'); - generateCustomAction( + await generateCustomAction( testDir, { name, @@ -111,8 +111,8 @@ describe('CustomAction', () => { expect(fs.read(controllerPath)).toEqual('dummyContent'); }); - test('specific target folder, event handler as boolean', () => { - generateCustomAction( + test('specific target folder, event handler as boolean', async () => { + await generateCustomAction( testDir, { name, @@ -129,8 +129,8 @@ describe('CustomAction', () => { expect(fs.read(join(testDir, 'webapp/ext/MyCustomAction.js'))).toMatchSnapshot(); }); - test('specific control as target', () => { - generateCustomAction( + test('specific control as target', async () => { + await generateCustomAction( testDir, { name, @@ -148,8 +148,8 @@ describe('CustomAction', () => { expect(fs.exists(join(testDir, 'webapp/ext/myCustomAction/MyCustomAction.js'))).toBeFalsy(); }); - test('custom section as target', () => { - generateCustomAction( + test('custom section as target', async () => { + await generateCustomAction( testDir, { name, @@ -186,8 +186,8 @@ describe('CustomAction', () => { } ]; positionTests.forEach((testCase) => { - test(`Test 'position' property. ${testCase.name}`, () => { - generateCustomAction( + test(`Test 'position' property. ${testCase.name}`, async () => { + await generateCustomAction( testDir, { name, @@ -206,8 +206,8 @@ describe('CustomAction', () => { const requiresSelectionValues = [undefined, true, false]; requiresSelectionValues.forEach((value?: boolean) => { - test(`Test property "requiresSelection" with value "${value}"`, () => { - generateCustomAction( + test(`Test property "requiresSelection" with value "${value}"`, async () => { + await generateCustomAction( testDir, { name, @@ -231,12 +231,12 @@ describe('CustomAction', () => { }); describe('Test property "eventHandler"', () => { - const generateCustomActionWithEventHandler = ( + const generateCustomActionWithEventHandler = async ( actionId: string, eventHandler: string | EventHandlerConfiguration, folder?: string ) => { - generateCustomAction( + await generateCustomAction( testDir, { name: actionId, @@ -258,8 +258,8 @@ describe('CustomAction', () => { return settings['content']['header']['actions'][actionId]; }; - test('"eventHandler" is empty "object" - create new file with default function name', () => { - generateCustomActionWithEventHandler(name, {}); + test('"eventHandler" is empty "object" - create new file with default function name', async () => { + await generateCustomActionWithEventHandler(name, {}); const manifest = fs.readJSON(join(testDir, 'webapp/manifest.json')) as Manifest; const action = getActionByName(manifest, name); @@ -269,13 +269,13 @@ describe('CustomAction', () => { ).toMatchSnapshot(); }); - test('"eventHandler" is "object" - create new file with custom file and function names', () => { + test('"eventHandler" is "object" - create new file with custom file and function names', async () => { const extension = { fnName: 'DummyOnAction', fileName: 'dummyAction' }; const folder = join('ext', 'custom'); - generateCustomActionWithEventHandler(name, extension, folder); + await generateCustomActionWithEventHandler(name, extension, folder); const manifest = fs.readJSON(join(testDir, 'webapp/manifest.json')) as Manifest; const action = getActionByName(manifest, name); @@ -283,8 +283,8 @@ describe('CustomAction', () => { expect(fs.read(join(testDir, 'webapp', 'ext', 'custom', `${extension.fileName}.js`))).toMatchSnapshot(); }); - test('"eventHandler" is "object" - create new file with custom function name', () => { - generateCustomActionWithEventHandler(name, { + test('"eventHandler" is "object" - create new file with custom function name', async () => { + await generateCustomActionWithEventHandler(name, { fnName: 'DummyOnAction' }); @@ -296,8 +296,8 @@ describe('CustomAction', () => { ).toMatchSnapshot(); }); - test('"eventHandler" is "object", action with lowercase first letter', () => { - generateCustomActionWithEventHandler(name, { + test('"eventHandler" is "object", action with lowercase first letter', async () => { + await generateCustomActionWithEventHandler(name, { fnName: 'dummyOnAction' }); @@ -307,8 +307,8 @@ describe('CustomAction', () => { expect(fs.exists(join(testDir, 'webapp', 'ext', 'myCustomAction', 'MyCustomAction.js'))).toBeTruthy(); }); - test(`"eventHandler" is String - no changes to handler file`, () => { - generateCustomActionWithEventHandler(name, 'my.test.App.ext.ExistingHandler.onCustomAction'); + test(`"eventHandler" is String - no changes to handler file`, async () => { + await generateCustomActionWithEventHandler(name, 'my.test.App.ext.ExistingHandler.onCustomAction'); const manifest = fs.readJSON(join(testDir, 'webapp', 'manifest.json')) as Manifest; const action = getActionByName(manifest, name); expect(action['press']).toEqual('my.test.App.ext.ExistingHandler.onCustomAction'); @@ -328,7 +328,7 @@ describe('CustomAction', () => { ['absolute position', 196, 8] ])( '"eventHandler" is object. Append new function to existing js file with %s', - (_desc: string, position: number | FileContentPosition, appendLines?: number) => { + async (_desc: string, position: number | FileContentPosition, appendLines?: number) => { const fileName = 'MyExistingAction'; // Create existing file with existing actions const folder = join('ext', 'fragments'); @@ -344,7 +344,7 @@ describe('CustomAction', () => { // Create third action - append existing js file const actionName = 'CustomAction2'; const fnName = 'onHandleSecondAction'; - generateCustomActionWithEventHandler( + await generateCustomActionWithEventHandler( actionName, { fnName, @@ -366,7 +366,7 @@ describe('CustomAction', () => { } ); - test('"eventHandler" is "object", append new function to controller extension', () => { + test('"eventHandler" is "object", append new function to controller extension', async () => { const expectedFileName = 'MyExistingAction'; const fileName = `${expectedFileName}.controller`; // Create existing file with existing actions @@ -381,7 +381,7 @@ describe('CustomAction', () => { const fnName = 'onHandleSecondAction'; const controllerPrefix = '.extension'; // use controller prefix to make sure it is controller extension - generateCustomActionWithEventHandler( + await generateCustomActionWithEventHandler( actionName, { fnName, @@ -410,13 +410,13 @@ describe('CustomAction', () => { }); describe('Test property custom "tabSizing"', () => { - test.each(tabSizingTestCases)('$name', ({ tabInfo, expectedAfterSave }) => { - generateCustomAction(testDir, { name, target, settings, tabInfo }, fs); + test.each(tabSizingTestCases)('$name', async ({ tabInfo, expectedAfterSave }) => { + await generateCustomAction(testDir, { name, target, settings, tabInfo }, fs); let updatedManifest = fs.read(join(testDir, 'webapp/manifest.json')); let result = detectTabSpacing(updatedManifest); expect(result).toEqual(expectedAfterSave); // Generate another action and check if new tab sizing recalculated correctly without passing tab size info - generateCustomAction(testDir, { name: 'Second', target, settings }, fs); + await generateCustomAction(testDir, { name: 'Second', target, settings }, fs); updatedManifest = fs.read(join(testDir, 'webapp/manifest.json')); result = detectTabSpacing(updatedManifest); expect(result).toEqual(expectedAfterSave); diff --git a/packages/fe-fpm-writer/test/unit/app.test.ts b/packages/fe-fpm-writer/test/unit/app.test.ts index dc36f3d04a..83f11b92c6 100644 --- a/packages/fe-fpm-writer/test/unit/app.test.ts +++ b/packages/fe-fpm-writer/test/unit/app.test.ts @@ -49,7 +49,7 @@ describe('CustomApp', () => { test('invalid base path', async () => { const target = join(testDir, 'does-not-exist'); try { - enableFPM(target, {}); + await enableFPM(target, {}); fail('the call should have failed with an error.'); } catch (error) { expect(error).toBeDefined(); @@ -59,14 +59,14 @@ describe('CustomApp', () => { test('valid app with no minimum version', async () => { const target = join(testDir, 'minimal-input'); fs.writeJSON(join(target, 'webapp/manifest.json'), getTestManifest()); - enableFPM(target, {}, fs); + await enableFPM(target, {}, fs); expect(fs.readJSON(join(target, 'webapp/manifest.json'))).toMatchSnapshot(); }); test('valid app with a too low minimum version', async () => { const target = join(testDir, 'minimal-input-low-version'); fs.writeJSON(join(target, 'webapp/manifest.json'), getTestManifest({ minVersion: '1.23.4' })); - enableFPM(target, {}, fs); + await enableFPM(target, {}, fs); const manifest = fs.readJSON(join(target, 'webapp/manifest.json')) as Manifest; expect(manifest['sap.ui5']?.dependencies?.minUI5Version).toBe(MIN_VERSION); }); @@ -74,7 +74,7 @@ describe('CustomApp', () => { test('valid app with array of minimum versions', async () => { const target = join(testDir, 'minimal-input-low-version'); fs.writeJSON(join(target, 'webapp/manifest.json'), getTestManifest({ minVersion: ['1.120.4', '2.0.0'] })); - enableFPM(target, {}, fs); + await enableFPM(target, {}, fs); const manifest = fs.readJSON(join(target, 'webapp/manifest.json')) as Manifest; expect(manifest['sap.ui5']?.dependencies?.minUI5Version).toStrictEqual(['1.120.4', '2.0.0']); }); @@ -82,7 +82,7 @@ describe('CustomApp', () => { test('valid app with array of one version, too low minimum versions', async () => { const target = join(testDir, 'minimal-input-low-version'); fs.writeJSON(join(target, 'webapp/manifest.json'), getTestManifest({ minVersion: ['1.23.4'] })); - enableFPM(target, {}, fs); + await enableFPM(target, {}, fs); const manifest = fs.readJSON(join(target, 'webapp/manifest.json')) as Manifest; expect(manifest['sap.ui5']?.dependencies?.minUI5Version).toStrictEqual(MIN_VERSION); }); @@ -90,7 +90,7 @@ describe('CustomApp', () => { test('valid app with array of two versions, too low minimum versions', async () => { const target = join(testDir, 'minimal-input-low-version'); fs.writeJSON(join(target, 'webapp/manifest.json'), getTestManifest({ minVersion: ['1.23.4', '2.0.0'] })); - enableFPM(target, {}, fs); + await enableFPM(target, {}, fs); const manifest = fs.readJSON(join(target, 'webapp/manifest.json')) as Manifest; expect(manifest['sap.ui5']?.dependencies?.minUI5Version).toStrictEqual([MIN_VERSION, '2.0.0']); }); @@ -98,7 +98,7 @@ describe('CustomApp', () => { test('enable FCL', async () => { const target = join(testDir, 'fcl-enabled'); fs.writeJSON(join(target, 'webapp/manifest.json'), getTestManifest()); - enableFPM(target, { fcl: true }, fs); + await enableFPM(target, { fcl: true }, fs); expect(fs.readJSON(join(target, 'webapp/manifest.json'))).toMatchSnapshot(); }); @@ -108,10 +108,10 @@ describe('CustomApp', () => { const component = '// Empty'; fs.write(join(target, 'webapp/Component.js'), component); - enableFPM(target, {}, fs); + await enableFPM(target, {}, fs); expect(fs.read(join(target, 'webapp/Component.js'))).toBe(component); - enableFPM(target, { replaceAppComponent: true }, fs); + await enableFPM(target, { replaceAppComponent: true }, fs); expect(fs.read(join(target, 'webapp/Component.js'))).not.toBe(component); }); @@ -119,7 +119,7 @@ describe('CustomApp', () => { const unknownVersion = '${sap.ui5.dist.version}'; const target = join(testDir, 'unknown-version'); fs.writeJSON(join(target, 'webapp/manifest.json'), getTestManifest({ minVersion: unknownVersion })); - enableFPM(target, {}, fs); + await enableFPM(target, {}, fs); const manifest = fs.readJSON(join(target, 'webapp/manifest.json')) as Manifest; expect(manifest['sap.ui5']?.dependencies?.minUI5Version).toBe(unknownVersion); }); @@ -133,7 +133,7 @@ describe('CustomApp', () => { const tempManifest = getTestManifest(); tempManifest['sap.ui5'] = value; fs.writeJSON(join(target, 'webapp/manifest.json'), tempManifest); - enableFPM(target, {}, fs); + await enableFPM(target, {}, fs); const manifest = fs.readJSON(join(target, 'webapp/manifest.json')) as Manifest; expect(manifest['sap.ui5']?.dependencies?.minUI5Version).toBe(undefined); }); diff --git a/packages/fe-fpm-writer/test/unit/column.test.ts b/packages/fe-fpm-writer/test/unit/column.test.ts index b3b25d6814..fb589086b4 100644 --- a/packages/fe-fpm-writer/test/unit/column.test.ts +++ b/packages/fe-fpm-writer/test/unit/column.test.ts @@ -56,9 +56,9 @@ describe('CustomAction', () => { fs.write(join(testDir, 'webapp/manifest.json'), JSON.stringify(manifest)); }); - test.each(testVersions)('only mandatory properties', (minUI5Version) => { + test.each(testVersions)('only mandatory properties', async (minUI5Version) => { //sut - generateCustomColumn(testDir, { ...customColumn, minUI5Version }, fs); + await generateCustomColumn(testDir, { ...customColumn, minUI5Version }, fs); const updatedManifest = fs.readJSON(join(testDir, 'webapp/manifest.json')) as Manifest; const settings = ( updatedManifest['sap.ui5']?.['routing']?.['targets']?.['sample']?.['options'] as Record @@ -68,7 +68,7 @@ describe('CustomAction', () => { expect(fs.read(expectedFragmentPath)).toMatchSnapshot(); }); - test('version 1.86, with fragmentFile', () => { + test('version 1.86, with fragmentFile', async () => { const testCustomColumn: CustomTableColumn = { ...customColumn, fragmentFile: 'NewCustomColumnFragment' @@ -77,7 +77,7 @@ describe('CustomAction', () => { testDir, `webapp/${customColumn.folder}/${testCustomColumn.fragmentFile}.fragment.xml` ); - generateCustomColumn(testDir, { ...testCustomColumn, minUI5Version: '1.86' }, fs); + await generateCustomColumn(testDir, { ...testCustomColumn, minUI5Version: '1.86' }, fs); const updatedManifest = fs.readJSON(join(testDir, 'webapp/manifest.json')) as Manifest; const settings = ( updatedManifest['sap.ui5']?.['routing']?.['targets']?.['sample']?.['options'] as Record @@ -86,7 +86,7 @@ describe('CustomAction', () => { expect(fs.read(expectedSectionFragmentPath)).toMatchSnapshot(); }); - test('version 1.86, with new handler, all properties', () => { + test('version 1.86, with new handler, all properties', async () => { const testCustomColumn: CustomTableColumn = { ...customColumn, eventHandler: true, @@ -95,7 +95,7 @@ describe('CustomAction', () => { width: '150px', properties: ['ID', 'TotalNetAmount', '_CustomerPaymentTerms/CustomerPaymentTerms'] }; - generateCustomColumn(testDir, { ...testCustomColumn, minUI5Version: '1.86' }, fs); + await generateCustomColumn(testDir, { ...testCustomColumn, minUI5Version: '1.86' }, fs); const updatedManifest = fs.readJSON(join(testDir, 'webapp/manifest.json')) as Manifest; const settings = ( updatedManifest['sap.ui5']?.['routing']?.['targets']?.['sample']?.['options'] as Record @@ -105,14 +105,14 @@ describe('CustomAction', () => { expect(fs.read(expectedFragmentPath)).toMatchSnapshot(); expect(fs.read(expectedFragmentPath.replace('.fragment.xml', '.js'))).toMatchSnapshot(); }); - test('version 1.86, with existing handler', () => { + test('version 1.86, with existing handler', async () => { const controllerPath = 'my.test.App.ext.ExistingHandler.onCustomAction'; fs.write(controllerPath, 'dummyContent'); const testCustomColumn: CustomTableColumn = { ...customColumn, eventHandler: controllerPath }; - generateCustomColumn(testDir, { ...testCustomColumn, minUI5Version: '1.86' }, fs); + await generateCustomColumn(testDir, { ...testCustomColumn, minUI5Version: '1.86' }, fs); const updatedManifest: any = fs.readJSON(join(testDir, 'webapp/manifest.json')); const settings = updatedManifest['sap.ui5']['routing']['targets']['sample']['options']['settings']; @@ -121,7 +121,7 @@ describe('CustomAction', () => { expect(fs.exists(controllerPath)).toBe(true); expect(fs.read(controllerPath)).toEqual('dummyContent'); }); - test('version 1.85, no handler, all properties', () => { + test('version 1.85, no handler, all properties', async () => { const testCustomColumn: CustomTableColumn = { ...customColumn, availability: Availability.Adaptation, @@ -129,7 +129,7 @@ describe('CustomAction', () => { width: '150px' }; - generateCustomColumn(testDir, { ...testCustomColumn, minUI5Version: '1.85' }, fs); + await generateCustomColumn(testDir, { ...testCustomColumn, minUI5Version: '1.85' }, fs); const updatedManifest = fs.readJSON(join(testDir, 'webapp/manifest.json')) as Manifest; const settings = ( @@ -139,13 +139,13 @@ describe('CustomAction', () => { expect(fs.read(expectedFragmentPath)).toMatchSnapshot(); }); - test('with custom control passed in interface', () => { + test('with custom control passed in interface', async () => { const testCustomColumn: CustomTableColumn = { ...customColumn, control: '' }; - generateCustomColumn(testDir, testCustomColumn, fs); + await generateCustomColumn(testDir, testCustomColumn, fs); const updatedManifest = fs.readJSON(join(testDir, 'webapp/manifest.json')) as Manifest; const settings = ( @@ -155,7 +155,7 @@ describe('CustomAction', () => { expect(fs.read(expectedFragmentPath)).toMatchSnapshot(); }); - test('version 1.85, no handler, no fs, all properties', () => { + test('version 1.85, no handler, no fs, all properties', async () => { const testCustomColumn: CustomTableColumn = { ...customColumn, availability: Availability.Adaptation, @@ -167,7 +167,7 @@ describe('CustomAction', () => { } }; - const testFS = generateCustomColumn(testDir, { ...testCustomColumn, minUI5Version: '1.85' }); + const testFS = await generateCustomColumn(testDir, { ...testCustomColumn, minUI5Version: '1.85' }); const updatedManifest = testFS.readJSON(join(testDir, 'webapp/manifest.json')) as Manifest; const settings = ( @@ -177,14 +177,14 @@ describe('CustomAction', () => { expect(testFS.read(expectedFragmentPath)).toMatchSnapshot(); }); - test('version 1.102, no handler, filename lowercase', () => { + test('version 1.102, no handler, filename lowercase', async () => { const testCustomColumn: CustomTableColumn = { ...customColumn, name: 'newCustomColumn', folder: 'extensions/custom' }; - const testFS = generateCustomColumn(testDir, { ...testCustomColumn, minUI5Version: '1.102' }); + const testFS = await generateCustomColumn(testDir, { ...testCustomColumn, minUI5Version: '1.102' }); const fragmentPath = join( testDir, `webapp`, @@ -194,14 +194,14 @@ describe('CustomAction', () => { expect(testFS.exists(fragmentPath)).toBeTruthy(); }); - test('version 1.102, no handler, filename lowercase, no folder passed', () => { + test('version 1.102, no handler, filename lowercase, no folder passed', async () => { const testCustomColumn: CustomTableColumn = { ...customColumn, name: 'newCustomColumn', folder: undefined }; - const testFS = generateCustomColumn(testDir, { ...testCustomColumn, minUI5Version: '1.102' }); + const testFS = await generateCustomColumn(testDir, { ...testCustomColumn, minUI5Version: '1.102' }); const fragmentPath = join( testDir, `webapp`, @@ -212,14 +212,14 @@ describe('CustomAction', () => { expect(testFS.exists(fragmentPath)).toBeTruthy(); }); - test('version 1.102, no handler, filename lowercase, folder uppercase', () => { + test('version 1.102, no handler, filename lowercase, folder uppercase', async () => { const testCustomColumn: CustomTableColumn = { ...customColumn, name: 'newCustomColumn', folder: 'extensions/Custom' }; - const testFS = generateCustomColumn(testDir, { ...testCustomColumn, minUI5Version: '1.102' }); + const testFS = await generateCustomColumn(testDir, { ...testCustomColumn, minUI5Version: '1.102' }); const fragmentPath = join( testDir, `webapp`, @@ -230,41 +230,41 @@ describe('CustomAction', () => { }); describe('Test property "eventHandler"', () => { - const generateCustomColumnWithEventHandler = ( + const generateCustomColumnWithEventHandler = async ( columnId: string, eventHandler: string | EventHandlerConfiguration, folder?: string ) => { - generateCustomColumn(testDir, { ...customColumn, name: columnId, folder, eventHandler }, fs); + await generateCustomColumn(testDir, { ...customColumn, name: columnId, folder, eventHandler }, fs); }; - test('"eventHandler" is empty "object" - create new file with default function name', () => { + test('"eventHandler" is empty "object" - create new file with default function name', async () => { const id = customColumn.name; - generateCustomColumnWithEventHandler(id, {}, customColumn.folder); + await generateCustomColumnWithEventHandler(id, {}, customColumn.folder); const xmlPath = join(testDir, `webapp/${customColumn.folder}/${id}.fragment.xml`); expect(fs.read(xmlPath)).toMatchSnapshot(); expect(fs.read(xmlPath.replace('.fragment.xml', '.js'))).toMatchSnapshot(); }); - test('"eventHandler" is "object" - create new file with custom file and function names', () => { + test('"eventHandler" is "object" - create new file with custom file and function names', async () => { const extension = { fnName: 'DummyOnAction', fileName: 'dummyAction' }; const id = customColumn.name; - generateCustomColumnWithEventHandler(id, extension, customColumn.folder); + await generateCustomColumnWithEventHandler(id, extension, customColumn.folder); const fragmentName = `${id}.fragment.xml`; const xmlPath = join(testDir, `webapp/${customColumn.folder}/${fragmentName}`); expect(fs.read(xmlPath)).toMatchSnapshot(); expect(fs.read(xmlPath.replace(fragmentName, `${extension.fileName}.js`))).toMatchSnapshot(); }); - test('"eventHandler" is "object" - create new file with custom function name', () => { + test('"eventHandler" is "object" - create new file with custom function name', async () => { const extension = { fnName: 'DummyOnAction' }; const id = customColumn.name; - generateCustomColumnWithEventHandler(id, extension, customColumn.folder); + await generateCustomColumnWithEventHandler(id, extension, customColumn.folder); const xmlPath = join(testDir, `webapp/${customColumn.folder}/${id}.fragment.xml`); expect(fs.read(xmlPath)).toMatchSnapshot(); expect(fs.read(xmlPath.replace('.fragment.xml', '.js'))).toMatchSnapshot(); @@ -282,7 +282,7 @@ describe('CustomAction', () => { ['absolute position', 196, 8] ])( '"eventHandler" is object. Append new function to existing js file with %s', - (_desc: string, position: number | FileContentPosition, appendLines?: number) => { + async (_desc: string, position: number | FileContentPosition, appendLines?: number) => { const fileName = 'MyExistingAction'; // Create existing file with existing actions const folder = join('extensions', 'custom'); @@ -307,7 +307,7 @@ describe('CustomAction', () => { }; const id = customColumn.name; - generateCustomColumnWithEventHandler(id, extension, folder); + await generateCustomColumnWithEventHandler(id, extension, folder); const xmlPath = join(testDir, 'webapp', folder, `${id}.fragment.xml`); expect(fs.read(xmlPath)).toMatchSnapshot(); // Check update js file content @@ -317,8 +317,8 @@ describe('CustomAction', () => { }); describe('Test property custom "tabSizing"', () => { - test.each(tabSizingTestCases)('$name', ({ tabInfo, expectedAfterSave }) => { - generateCustomColumn( + test.each(tabSizingTestCases)('$name', async ({ tabInfo, expectedAfterSave }) => { + await generateCustomColumn( testDir, { ...customColumn, @@ -330,7 +330,7 @@ describe('CustomAction', () => { let result = detectTabSpacing(updatedManifest); expect(result).toEqual(expectedAfterSave); // Generate another columns and check if new tab sizing recalculated correctly without passing tab size info - generateCustomColumn( + await generateCustomColumn( testDir, { ...customColumn, diff --git a/packages/fe-fpm-writer/test/unit/controller-extension.test.ts b/packages/fe-fpm-writer/test/unit/controller-extension.test.ts index 17fa368063..fd420e6429 100644 --- a/packages/fe-fpm-writer/test/unit/controller-extension.test.ts +++ b/packages/fe-fpm-writer/test/unit/controller-extension.test.ts @@ -66,8 +66,8 @@ describe('ControllerExtension', () => { undefined ]; - test.each(pageTypeTests)('New controller extension - %s', (pageType) => { - generateControllerExtension( + test.each(pageTypeTests)('New controller extension - %s', async (pageType) => { + await generateControllerExtension( testDir, { ...controllerExtension, @@ -82,8 +82,8 @@ describe('ControllerExtension', () => { expect(fs.read(expectedControllerPath)).toMatchSnapshot(); }); - test('New controller extension with page id', () => { - generateControllerExtension( + test('New controller extension with page id', async () => { + await generateControllerExtension( testDir, { ...controllerExtension, @@ -98,8 +98,8 @@ describe('ControllerExtension', () => { expect(fs.read(expectedControllerPath)).toMatchSnapshot(); }); - test(`New controller extension with manual target`, () => { - generateControllerExtension( + test(`New controller extension with manual target`, async () => { + await generateControllerExtension( testDir, { ...controllerExtension, @@ -199,12 +199,12 @@ describe('ControllerExtension', () => { } ]; - test.each(testCases)('$name', ({ controllerConfig }) => { + test.each(testCases)('$name', async ({ controllerConfig }) => { const manifestWithExtensions = getManifest(getExtensions()); fs = create(createStorage()); fs.delete(testDir); fs.write(join(testDir, 'webapp/manifest.json'), manifestWithExtensions); - generateControllerExtension(testDir, controllerConfig, fs); + await generateControllerExtension(testDir, controllerConfig, fs); expect(fs.readJSON(join(testDir, 'webapp/manifest.json'))).toMatchSnapshot(); expect(fs.exists(getControllerPath(controllerConfig))).toBeTruthy(); }); @@ -232,7 +232,7 @@ describe('ControllerExtension', () => { } ]; - test.each(mixStateTestCases)('$name', ({ controllerConfig }) => { + test.each(mixStateTestCases)('$name', async ({ controllerConfig }) => { const extension = getExtensions(); extension['sap.ui.controllerExtensions'][ 'sap.fe.templates.ListReport.ListReportController' @@ -241,7 +241,7 @@ describe('ControllerExtension', () => { fs = create(createStorage()); fs.delete(testDir); fs.write(join(testDir, 'webapp/manifest.json'), manifestWithExtensions); - generateControllerExtension(testDir, controllerConfig, fs); + await generateControllerExtension(testDir, controllerConfig, fs); expect(fs.readJSON(join(testDir, 'webapp/manifest.json'))).toMatchSnapshot(); expect(fs.exists(getControllerPath(controllerConfig))).toBeTruthy(); }); @@ -266,8 +266,8 @@ describe('ControllerExtension', () => { const copyTarget = copySpy.mock.calls[callIndex][1] as string; return copyTarget === target; }; - test.each(pageTypeTests)('New controller extension - %s', (pageType) => { - generateControllerExtension( + test.each(pageTypeTests)('New controller extension - %s', async (pageType) => { + await generateControllerExtension( testDir, { ...controllerExtension, @@ -291,8 +291,8 @@ describe('ControllerExtension', () => { 'my.project.ext.view.Test' ]; - test.each(manualExtensionsTests)('New controller extension with manual target - %s', (extension) => { - generateControllerExtension( + test.each(manualExtensionsTests)('New controller extension with manual target - %s', async (extension) => { + await generateControllerExtension( testDir, { ...controllerExtension, @@ -306,12 +306,12 @@ describe('ControllerExtension', () => { expect(fs.read(expectedTestControllerPath)).toMatchSnapshot(); }); - test('Check "ControllerExtension.d.ts" file', () => { + test('Check "ControllerExtension.d.ts" file', async () => { expect(fs.exists(expectedDeclarationFilePath)).toBeFalsy(); // Spy for copy method to detect how often it is called const copySpy = jest.spyOn(fs, 'copy'); // Create extension controller - generateControllerExtension( + await generateControllerExtension( testDir, { ...controllerExtension, @@ -351,7 +351,7 @@ describe('ControllerExtension', () => { }, typescript: true }; - generateControllerExtension(testDir, secondExtension as ControllerExtension, fs); + await generateControllerExtension(testDir, secondExtension as ControllerExtension, fs); expect(fs.exists(expectedDeclarationFilePath)).toBeTruthy(); // Check how fs.copy method called - copy for 'Controller.ts' only, 'ControllerExtension.d.ts' was created on very first creation expect(copySpy).toBeCalledTimes(1); @@ -372,8 +372,8 @@ describe('ControllerExtension', () => { }); describe('Test property custom "tabSizing"', () => { - test.each(tabSizingTestCases)('$name', ({ tabInfo, expectedAfterSave }) => { - generateControllerExtension( + test.each(tabSizingTestCases)('$name', async ({ tabInfo, expectedAfterSave }) => { + await generateControllerExtension( testDir, { ...controllerExtension, @@ -385,7 +385,7 @@ describe('ControllerExtension', () => { let result = detectTabSpacing(updatedManifest); expect(result).toEqual(expectedAfterSave); // Generate another controller extension and check if new tab sizing recalculated correctly without passing tab size info - generateControllerExtension( + await generateControllerExtension( testDir, { ...controllerExtension, diff --git a/packages/fe-fpm-writer/test/unit/filter.test.ts b/packages/fe-fpm-writer/test/unit/filter.test.ts index 115b72f973..8e0e60bb29 100644 --- a/packages/fe-fpm-writer/test/unit/filter.test.ts +++ b/packages/fe-fpm-writer/test/unit/filter.test.ts @@ -52,30 +52,30 @@ describe('CustomFilter', () => { fs.delete(testDir); fs.write(join(testDir, 'webapp/manifest.json'), testAppManifest); }); - test('New custom filter (no eventhandler)', () => { - generateCustomFilter(testDir, filter, fs); + test('New custom filter (no eventhandler)', async () => { + await generateCustomFilter(testDir, filter, fs); expect(fs.readJSON(join(testDir, 'webapp/manifest.json'))).toMatchSnapshot(); expect(fs.exists(getControllerPath(filter))).toBe(false); expect(fs.read(getExpectedFragmentPath(filter))).toMatchSnapshot(); }); - test('Create several new custom filters', () => { + test('Create several new custom filters', async () => { const secondFilter = { name: 'NewCustomFilter2', label: 'Test Custom Filter 2', controlID: 'testID2', property: 'Testing' }; - generateCustomFilter(testDir, filter, fs); + await generateCustomFilter(testDir, filter, fs); - generateCustomFilter(testDir, secondFilter, fs); + await generateCustomFilter(testDir, secondFilter, fs); expect(fs.readJSON(join(testDir, 'webapp/manifest.json'))).toMatchSnapshot(); expect(fs.exists(getControllerPath(secondFilter))).toBe(false); expect(fs.read(getExpectedFragmentPath(secondFilter))).toMatchSnapshot(); }); - test('with new event handler as string', () => { - generateCustomFilter( + test('with new event handler as string', async () => { + await generateCustomFilter( testDir, { ...filter, @@ -87,10 +87,10 @@ describe('CustomFilter', () => { expect(fs.read(getExpectedFragmentPath(filter))).toMatchSnapshot(); }); - test('with existing event handler as string', () => { + test('with existing event handler as string', async () => { const controllerPath = 'my.test.App.ext.ExistingHandler.onTestFilter'; fs.write(controllerPath, 'dummyContent'); - generateCustomFilter( + await generateCustomFilter( testDir, { ...filter, @@ -103,8 +103,8 @@ describe('CustomFilter', () => { expect(fs.read(controllerPath)).toEqual('dummyContent'); }); - test('specific target folder, event handler as boolean', () => { - generateCustomFilter( + test('specific target folder, event handler as boolean', async () => { + await generateCustomFilter( testDir, { ...filter, @@ -118,12 +118,12 @@ describe('CustomFilter', () => { }); describe('Test property "eventHandler"', () => { - const generateCustomFilterWithEventHandler = ( + const generateCustomFilterWithEventHandler = async ( filterId: string, eventHandler: string | EventHandlerConfiguration, folder?: string ) => { - generateCustomFilter( + await generateCustomFilter( testDir, { ...filter, @@ -134,28 +134,28 @@ describe('CustomFilter', () => { ); }; - test('"eventHandler" is empty "object" - create new file with default function name', () => { - generateCustomFilterWithEventHandler(filter.name, {}); + test('"eventHandler" is empty "object" - create new file with default function name', async () => { + await generateCustomFilterWithEventHandler(filter.name, {}); expect( fs.read(join(testDir, 'webapp', 'ext', 'newCustomFilter', 'NewCustomFilter.js')) ).toMatchSnapshot(); }); - test('"eventHandler" is "object" - create new file with custom file and function names', () => { + test('"eventHandler" is "object" - create new file with custom file and function names', async () => { const extension = { fnName: 'DummyFilterItems', fileName: 'dummyFilter' }; const folder = join('ext', 'custom'); - generateCustomFilterWithEventHandler(filter.name, extension, folder); + await generateCustomFilterWithEventHandler(filter.name, extension, folder); expect(fs.read(join(testDir, 'webapp', 'ext', 'custom', `${extension.fileName}.js`))).toMatchSnapshot(); expect(fs.read(getExpectedFragmentPath({ ...filter, folder: folder }))).toMatchSnapshot(); }); - test('"eventHandler" is "object" - create new file with custom function name', () => { - generateCustomFilterWithEventHandler(filter.name, { + test('"eventHandler" is "object" - create new file with custom function name', async () => { + await generateCustomFilterWithEventHandler(filter.name, { fnName: 'DummyOnAction' }); @@ -164,8 +164,8 @@ describe('CustomFilter', () => { ).toMatchSnapshot(); }); - test('"eventHandler" is "object", action with lowercase first letter', () => { - generateCustomFilterWithEventHandler(filter.name, { + test('"eventHandler" is "object", action with lowercase first letter', async () => { + await generateCustomFilterWithEventHandler(filter.name, { fnName: 'dummyOnAction' }); @@ -174,8 +174,11 @@ describe('CustomFilter', () => { ).toMatchSnapshot(); }); - test(`"eventHandler" is String - no changes to handler file`, () => { - generateCustomFilterWithEventHandler(filter.name, 'my.test.App.ext.ExistingHandler.onCustomAction'); + test(`"eventHandler" is String - no changes to handler file`, async () => { + await generateCustomFilterWithEventHandler( + filter.name, + 'my.test.App.ext.ExistingHandler.onCustomAction' + ); expect(fs.exists(join(testDir, 'webapp', 'ext', 'newCustomFilter', 'NewCustomFilter.js'))).toBeFalsy(); }); @@ -193,7 +196,7 @@ describe('CustomFilter', () => { ['absolute position', 870, 18] ])( '"eventHandler" is object. Append new function to existing js file with %s', - (_desc: string, position: number | FileContentPosition, appendLines?: number) => { + async (_desc: string, position: number | FileContentPosition, appendLines?: number) => { const fileName = 'MyExistingFilter'; // Create existing file with existing filters const folder = join('ext', 'fragments'); @@ -210,7 +213,7 @@ describe('CustomFilter', () => { // Create third action - append existing js file const filterName = 'CustomFilter2'; const fnName = 'onHandleSecondAction'; - generateCustomFilterWithEventHandler( + await generateCustomFilterWithEventHandler( filterName, { fnName, @@ -264,8 +267,8 @@ describe('CustomFilter', () => { } ]; positionTests.forEach((testCase) => { - test(`Test 'position' property. ${testCase.name}`, () => { - generateCustomFilter( + test(`Test 'position' property. ${testCase.name}`, async () => { + await generateCustomFilter( testDir, { ...filter, @@ -288,8 +291,8 @@ describe('CustomFilter', () => { } ]; languages.forEach((languageConfig) => { - test(`Test 'typescript' property. ${languageConfig.name}`, () => { - generateCustomFilter( + test(`Test 'typescript' property. ${languageConfig.name}`, async () => { + await generateCustomFilter( testDir, { ...filter, @@ -303,7 +306,7 @@ describe('CustomFilter', () => { }); }); - test('Avoid overwrite for existing extension files', () => { + test('Avoid overwrite for existing extension files', async () => { const fileName = 'Existing'; const target = join(testDir, 'different-folder'); const folder = join('ext', 'different'); @@ -314,7 +317,7 @@ describe('CustomFilter', () => { fs.write(fragmentPath, 'fragmentContent'); const handlerPath = join(target, `webapp/${folder}/${fileName}.js`); fs.write(handlerPath, 'handlerContent'); - generateCustomFilter( + await generateCustomFilter( target, { ...filter, diff --git a/packages/fe-fpm-writer/test/unit/header-section.test.ts b/packages/fe-fpm-writer/test/unit/header-section.test.ts index 5ef3527d84..ffa777eae6 100644 --- a/packages/fe-fpm-writer/test/unit/header-section.test.ts +++ b/packages/fe-fpm-writer/test/unit/header-section.test.ts @@ -53,7 +53,7 @@ describe('CustomHeaderSection generateCustomHeaderSection', () => { fs.write(join(testDir, 'webapp/manifest.json'), JSON.stringify(manifest)); }); - test(`for version 1.85 (edit mode not supported)`, () => { + test(`for version 1.85 (edit mode not supported)`, async () => { const customHeaderSection = createCustomHeaderSectionWithEditFragment('1.85.0', { name: 'NewCustomHeaderSectionEdit', folder: 'extensions/custom', @@ -69,7 +69,7 @@ describe('CustomHeaderSection generateCustomHeaderSection', () => { `webapp/${customHeaderSection.edit.folder}/${customHeaderSection.edit.name}.fragment.xml` ); } - generateCustomHeaderSection(testDir, { ...customHeaderSection }, fs); + await generateCustomHeaderSection(testDir, { ...customHeaderSection }, fs); const updatedManifest = fs.readJSON(join(testDir, 'webapp/manifest.json')) as Manifest; const settings = ( @@ -87,13 +87,13 @@ describe('CustomHeaderSection generateCustomHeaderSection', () => { } }); - test(`for version 1.86 (edit mode disabled)`, () => { + test(`for version 1.86 (edit mode disabled)`, async () => { const customHeaderSection = createCustomHeaderSectionWithEditFragment('1.86.0', undefined); const expectedFragmentPath = join( testDir, `webapp/${customHeaderSection.folder}/${customHeaderSection.name}.fragment.xml` ); - generateCustomHeaderSection(testDir, { ...customHeaderSection }, fs); + await generateCustomHeaderSection(testDir, { ...customHeaderSection }, fs); const updatedManifest = fs.readJSON(join(testDir, 'webapp/manifest.json')) as Manifest; const settings = ( @@ -111,7 +111,7 @@ describe('CustomHeaderSection generateCustomHeaderSection', () => { } }); - test(`for version 1.86 (eventHandler should not generate)`, () => { + test(`for version 1.86 (eventHandler should not generate)`, async () => { const customHeaderSection = createCustomHeaderSectionWithEditFragment('1.86.0', { name: 'NewCustomHeaderSectionEdit', folder: 'extensions/custom' @@ -126,7 +126,7 @@ describe('CustomHeaderSection generateCustomHeaderSection', () => { `webapp/${customHeaderSection.edit.folder}/${customHeaderSection.edit.name}.fragment.xml` ); } - generateCustomHeaderSection(testDir, { ...customHeaderSection }, fs); + await generateCustomHeaderSection(testDir, { ...customHeaderSection }, fs); const updatedManifest = fs.readJSON(join(testDir, 'webapp/manifest.json')) as Manifest; const settings = ( @@ -145,7 +145,7 @@ describe('CustomHeaderSection generateCustomHeaderSection', () => { }); testVersions.forEach((minUI5Version: string) => { - test(`for version ${minUI5Version}`, () => { + test(`for version ${minUI5Version}`, async () => { const customHeaderSection = createCustomHeaderSectionWithEditFragment(minUI5Version, { name: 'NewCustomHeaderSectionEdit', folder: 'extensions/custom', @@ -161,7 +161,7 @@ describe('CustomHeaderSection generateCustomHeaderSection', () => { `webapp/${customHeaderSection.edit.folder}/${customHeaderSection.edit.name}.fragment.xml` ); } - generateCustomHeaderSection(testDir, { ...customHeaderSection }, fs); + await generateCustomHeaderSection(testDir, { ...customHeaderSection }, fs); const updatedManifest = fs.readJSON(join(testDir, 'webapp/manifest.json')) as Manifest; const settings = ( @@ -176,7 +176,7 @@ describe('CustomHeaderSection generateCustomHeaderSection', () => { }); }); - test('custom control for edit mode', () => { + test('custom control for edit mode', async () => { const customHeaderSection = createCustomHeaderSectionWithEditFragment('1.98', { name: 'NewCustomHeaderSectionEdit', folder: 'extensions/custom', @@ -186,7 +186,7 @@ describe('CustomHeaderSection generateCustomHeaderSection', () => { testDir, `webapp/${customHeaderSection.edit?.folder}/${customHeaderSection.edit?.name}.fragment.xml` ); - generateCustomHeaderSection(testDir, customHeaderSection, fs); + await generateCustomHeaderSection(testDir, customHeaderSection, fs); expect(fs.read(expectedFragmentPath)).toMatchSnapshot(); }); @@ -204,7 +204,7 @@ describe('CustomHeaderSection generateCustomHeaderSection', () => { }); // folder in edit property differs - test(`for version 1.86`, () => { + test(`for version 1.86`, async () => { const customHeaderSection = createCustomHeaderSectionWithEditFragment('1.86.0', { name: 'NewCustomHeaderSectionEdit', folder: 'extensions/custom/different', @@ -220,7 +220,7 @@ describe('CustomHeaderSection generateCustomHeaderSection', () => { `webapp/${customHeaderSection.edit.folder}/${customHeaderSection.edit.name}.fragment.xml` ); } - generateCustomHeaderSection(testDir, { ...customHeaderSection }, fs); + await generateCustomHeaderSection(testDir, { ...customHeaderSection }, fs); const updatedManifest = fs.readJSON(join(testDir, 'webapp/manifest.json')) as Manifest; const settings = ( @@ -277,12 +277,12 @@ describe('CustomHeaderSection generateCustomHeaderSection', () => { } ]; positionTests.forEach((testCase) => { - test(`Test 'position' property. ${testCase.name}`, () => { + test(`Test 'position' property. ${testCase.name}`, async () => { const customHeaderSection = createCustomHeaderSectionWithEditFragment(testCase.minUI5Version, { name: 'NewCustomHeaderSectionEdit', folder: 'extensions/custom' }); - generateCustomHeaderSection( + await generateCustomHeaderSection( testDir, { ...customHeaderSection, diff --git a/packages/fe-fpm-writer/test/unit/page/common.test.ts b/packages/fe-fpm-writer/test/unit/page/common.test.ts index a444bbabd4..11b6cc8a1a 100644 --- a/packages/fe-fpm-writer/test/unit/page/common.test.ts +++ b/packages/fe-fpm-writer/test/unit/page/common.test.ts @@ -180,10 +180,10 @@ describe('common page functionality', () => { const manifest = JSON.parse(testAppManifest) as Manifest; fs.writeJSON(join(testDir, 'webapp/manifest.json'), manifest); - expect(() => validatePageConfig(testDir, config, fs)).not.toThrowError(); + await expect(async () => await validatePageConfig(testDir, config, fs)).not.toThrowError(); }); - test('provided navigation config is not valid for existing manifest', () => { + test('provided navigation config is not valid for existing manifest', async () => { const target = join(testDir, 'invalidateNavigation'); let manifest = JSON.parse(testAppManifest); @@ -191,29 +191,29 @@ describe('common page functionality', () => { manifest['sap.ui5'].routing = manifest['sap.ui5'].routing ?? {}; manifest['sap.ui5'].routing.routes = []; fs.writeJSON(join(target, 'webapp/manifest.json'), manifest); - expect(() => validatePageConfig(target, config, fs)).toThrowError(); + await expect(async () => await validatePageConfig(target, config, fs)).rejects.toThrowError(); delete manifest['sap.ui5']?.routing?.routes; fs.writeJSON(join(target, 'webapp/manifest.json'), manifest); - expect(() => validatePageConfig(target, config, fs)).toThrowError(); + await expect(async () => await validatePageConfig(target, config, fs)).rejects.toThrowError(); manifest = JSON.parse(testAppManifest) as Manifest; delete manifest['sap.ui5']?.routing?.targets?.['TestObjectPage']; fs.writeJSON(join(target, 'webapp/manifest.json'), manifest); - expect(() => validatePageConfig(target, config, fs)).toThrowError(); + await expect(async () => await validatePageConfig(target, config, fs)).rejects.toThrowError(); delete manifest['sap.ui5']?.routing?.targets; fs.writeJSON(join(target, 'webapp/manifest.json'), manifest); - expect(() => validatePageConfig(target, config, fs)).toThrowError(); + await expect(async () => await validatePageConfig(target, config, fs)).rejects.toThrowError(); delete manifest['sap.ui5']?.routing; fs.writeJSON(join(target, 'webapp/manifest.json'), manifest); - expect(() => validatePageConfig(target, config, fs)).toThrowError(); + await expect(async () => await validatePageConfig(target, config, fs)).rejects.toThrowError(); delete manifest['sap.ui5']; fs.writeJSON(join(target, 'webapp/manifest.json'), manifest); - expect(() => validatePageConfig(target, config, fs)).toThrowError(); + await expect(async () => await validatePageConfig(target, config, fs)).rejects.toThrowError(); }); }); diff --git a/packages/fe-fpm-writer/test/unit/page/custom.test.ts b/packages/fe-fpm-writer/test/unit/page/custom.test.ts index 6bee7b8c6b..4fa18248de 100644 --- a/packages/fe-fpm-writer/test/unit/page/custom.test.ts +++ b/packages/fe-fpm-writer/test/unit/page/custom.test.ts @@ -59,13 +59,15 @@ describe('CustomPage', () => { ); }); - test('validateBasePath', () => { + test('validateBasePath', async () => { const target = join(testDir, 'validateBasePath'); fs.write(join(target, 'webapp/manifest.json'), testAppManifest); expect(validateBasePath(target, fs, [])).toBeTruthy(); expect(() => validateBasePath(join(testDir, '' + Date.now()), fs, [])).toThrowError(); - expect(() => generateCustomPage(join(testDir, '' + Date.now()), {} as CustomPage)).toThrowError(); + await expect( + async () => await generateCustomPage(join(testDir, '' + Date.now()), {} as CustomPage) + ).rejects.toThrowError(); const invalidManifest = JSON.parse(testAppManifest); delete invalidManifest['sap.ui5'].dependencies?.libs['sap.fe.templates']; @@ -79,18 +81,18 @@ describe('CustomPage', () => { entity: 'RootEntity' }; - test('latest version with minimal input', () => { + test('latest version with minimal input', async () => { const target = join(testDir, 'minimal-input'); fs.write(join(target, 'webapp/manifest.json'), testAppManifest); //act - generateCustomPage(target, minimalInput, fs); + await generateCustomPage(target, minimalInput, fs); //check expect(fs.readJSON(join(target, 'webapp/manifest.json'))).toMatchSnapshot(); expect(fs.read(join(target, 'webapp/ext/customPage/CustomPage.view.xml'))).toMatchSnapshot(); expect(fs.read(join(target, 'webapp/ext/customPage/CustomPage.controller.js'))).toMatchSnapshot(); }); - test('latest version with minimal input, plus optional page id', () => { + test('latest version with minimal input, plus optional page id', async () => { const target = join(testDir, 'minimal-input'); fs.write(join(target, 'webapp/manifest.json'), testAppManifest); const minInput = { @@ -99,12 +101,12 @@ describe('CustomPage', () => { }; const testApiData = JSON.parse(JSON.stringify(minInput)); //act - generateCustomPage(target, testApiData, fs); + await generateCustomPage(target, testApiData, fs); //check expect(fs.readJSON(join(target, 'webapp/manifest.json'))).toMatchSnapshot(); }); - test('latest version with entitySet and lower UI5 version', () => { + test('latest version with entitySet and lower UI5 version', async () => { const target = join(testDir, 'ui5_1_71'); const localManifest = JSON.parse(testAppManifest); localManifest['sap.ui5'].dependencies.minUI5Version = '1.84.62'; @@ -112,37 +114,37 @@ describe('CustomPage', () => { const testInput = JSON.parse(JSON.stringify(minimalInput)); testInput.minUI5Version = '1.84.62'; //act - generateCustomPage(target, testInput, fs); + await generateCustomPage(target, testInput, fs); //check expect(fs.readJSON(join(target, 'webapp/manifest.json'))).toMatchSnapshot(); expect(fs.read(join(target, 'webapp/ext/customPage/CustomPage.view.xml'))).toMatchSnapshot(); expect(fs.read(join(target, 'webapp/ext/customPage/CustomPage.controller.js'))).toMatchSnapshot(); }); - test('latest version with contextPath', () => { + test('latest version with contextPath', async () => { const localInput = JSON.parse(JSON.stringify(minimalInput)); localInput.contextPath = 'my/path'; localInput.minUI5Version = '1.102'; const target = join(testDir, 'minimal-input'); fs.write(join(target, 'webapp/manifest.json'), testAppManifest); - generateCustomPage(target, localInput, fs); + await generateCustomPage(target, localInput, fs); expect(fs.readJSON(join(target, 'webapp/manifest.json'))).toMatchSnapshot(); expect(fs.read(join(target, 'webapp/ext/customPage/CustomPage.view.xml'))).toMatchSnapshot(); expect(fs.read(join(target, 'webapp/ext/customPage/CustomPage.controller.js'))).toMatchSnapshot(); }); - test('with older but supported UI5 version', () => { + test('with older but supported UI5 version', async () => { const target = join(testDir, 'version-1.84'); fs.write(join(target, 'webapp/manifest.json'), testAppManifest); - generateCustomPage(target, { ...minimalInput, minUI5Version: '1.84' }, fs); + await generateCustomPage(target, { ...minimalInput, minUI5Version: '1.84' }, fs); expect(fs.readJSON(join(target, 'webapp/manifest.json'))).toMatchSnapshot(); expect(fs.read(join(target, 'webapp/ext/customPage/CustomPage.view.xml'))).toMatchSnapshot(); expect(fs.read(join(target, 'webapp/ext/customPage/CustomPage.controller.js'))).toMatchSnapshot(); }); - test('with older but supported UI5 version, plus optional page id', () => { + test('with older but supported UI5 version, plus optional page id', async () => { const target = join(testDir, 'version-1.84'); fs.write(join(target, 'webapp/manifest.json'), testAppManifest); const minInput = { @@ -151,27 +153,29 @@ describe('CustomPage', () => { minUI5Version: '1.84' }; const testApiData = JSON.parse(JSON.stringify(minInput)); - generateCustomPage(target, testApiData, fs); + await generateCustomPage(target, testApiData, fs); expect(fs.readJSON(join(target, 'webapp/manifest.json'))).toMatchSnapshot(); }); - test('with not supported version', () => { + test('with not supported version', async () => { const target = join(testDir, 'version-not-supported'); fs.write(join(target, 'webapp/manifest.json'), testAppManifest); - expect(() => generateCustomPage(target, { ...minimalInput, minUI5Version: '1.83' }, fs)).toThrowError(); + await expect( + async () => await generateCustomPage(target, { ...minimalInput, minUI5Version: '1.83' }, fs) + ).rejects.toThrowError(); }); - test('latest version with minimal input but different target folder', () => { + test('latest version with minimal input but different target folder', async () => { const target = join(testDir, 'different-folder'); const folder = 'ext/different'; fs.write(join(target, 'webapp/manifest.json'), testAppManifest); - generateCustomPage(target, { ...minimalInput, folder }, fs); + await generateCustomPage(target, { ...minimalInput, folder }, fs); expect(fs.readJSON(join(target, 'webapp/manifest.json'))).toMatchSnapshot(); expect(fs.read(join(target, `webapp/${folder}/CustomPage.view.xml`))).toMatchSnapshot(); expect(fs.read(join(target, `webapp/${folder}/CustomPage.controller.js`))).toMatchSnapshot(); }); - test('with existing target files', () => { + test('with existing target files', async () => { const target = join(testDir, 'different-folder'); const folder = 'ext/different'; fs.write(join(target, 'webapp/manifest.json'), testAppManifest); @@ -182,7 +186,7 @@ describe('CustomPage', () => { const i18nPropertiesPath = join(target, 'webapp/i18n/i18n.properties'); fs.write(i18nPropertiesPath, ''); //sut - generateCustomPage(target, { ...minimalInput, folder }, fs); + await generateCustomPage(target, { ...minimalInput, folder }, fs); expect(fs.readJSON(join(target, 'webapp/manifest.json'))).toMatchSnapshot(); expect(fs.exists(controllerPath)).toBe(true); expect(fs.read(controllerPath)).toEqual('controllerContent'); @@ -203,25 +207,25 @@ describe('CustomPage', () => { } }; - test('simple inbound navigation', () => { + test('simple inbound navigation', async () => { const target = join(testDir, 'with-nav'); fs.write(join(target, 'webapp/manifest.json'), testAppManifest); - generateCustomPage(target, inputWithNavigation, fs); + await generateCustomPage(target, inputWithNavigation, fs); expect((fs.readJSON(join(target, 'webapp/manifest.json')) as any)?.['sap.ui5'].routing).toMatchSnapshot(); }); - test('simple inbound navigation, plus optional page id', () => { + test('simple inbound navigation, plus optional page id', async () => { const target = join(testDir, 'with-nav'); fs.write(join(target, 'webapp/manifest.json'), testAppManifest); const minInput = { ...inputWithNavigation, id: 'DummyPage' }; - generateCustomPage(target, minInput, fs); + await generateCustomPage(target, minInput, fs); expect((fs.readJSON(join(target, 'webapp/manifest.json')) as any)?.['sap.ui5'].routing).toMatchSnapshot(); }); - test('inbound navigation defined as array (for FCL)', () => { + test('inbound navigation defined as array (for FCL)', async () => { const testManifestWithArray = JSON.parse(testAppManifest); testManifestWithArray['sap.ui5'].routing.config = { routerClass: FCL_ROUTER @@ -235,11 +239,11 @@ describe('CustomPage', () => { ]; const target = join(testDir, 'target-as-array'); fs.writeJSON(join(target, 'webapp/manifest.json'), testManifestWithArray); - generateCustomPage(target, inputWithNavigation, fs); + await generateCustomPage(target, inputWithNavigation, fs); expect((fs.readJSON(join(target, 'webapp/manifest.json')) as any)?.['sap.ui5'].routing).toMatchSnapshot(); }); - test('inbound navigation defined as array with max nesting for FCL', () => { + test('inbound navigation defined as array with max nesting for FCL', async () => { const testManifestWithArray = JSON.parse(testAppManifest); testManifestWithArray['sap.ui5'].routing.config = { routerClass: FCL_ROUTER @@ -253,7 +257,7 @@ describe('CustomPage', () => { ]; const target = join(testDir, 'target-as-nested-array'); fs.writeJSON(join(target, 'webapp/manifest.json'), testManifestWithArray); - generateCustomPage(target, inputWithNavigation, fs); + await generateCustomPage(target, inputWithNavigation, fs); expect((fs.readJSON(join(target, 'webapp/manifest.json')) as any)?.['sap.ui5'].routing).toMatchSnapshot(); }); }); @@ -266,7 +270,7 @@ describe('CustomPage', () => { const testManifestWithNoRouting = JSON.parse(testAppManifest); delete testManifestWithNoRouting['sap.ui5'].routing; - test('FCL enabled single page app', () => { + test('FCL enabled single page app', async () => { testManifestWithNoRouting['sap.ui5'].routing = { config: { routerClass: 'sap.f.routing.Router' @@ -274,24 +278,24 @@ describe('CustomPage', () => { }; const target = join(testDir, 'single-page-fcl'); fs.writeJSON(join(target, 'webapp/manifest.json'), testManifestWithNoRouting); - generateCustomPage(target, { ...input }, fs); + await generateCustomPage(target, { ...input }, fs); expect((fs.readJSON(join(target, 'webapp/manifest.json')) as any)?.['sap.ui5'].routing).toMatchSnapshot(); }); - test('No FCL single page app', () => { + test('No FCL single page app', async () => { delete testManifestWithNoRouting['sap.ui5'].routing; const target = join(testDir, 'single-page-no-fcl'); fs.writeJSON(join(target, 'webapp/manifest.json'), testManifestWithNoRouting); - generateCustomPage(target, input, fs); + await generateCustomPage(target, input, fs); expect((fs.readJSON(join(target, 'webapp/manifest.json')) as any)?.['sap.ui5'].routing).toMatchSnapshot(); }); }); describe('Test property custom "tabSizing"', () => { - test.each(tabSizingTestCases)('$name', ({ tabInfo, expectedAfterSave }) => { + test.each(tabSizingTestCases)('$name', async ({ tabInfo, expectedAfterSave }) => { const target = join(testDir, 'tab-sizing'); fs.write(join(target, 'webapp/manifest.json'), testAppManifest); - generateCustomPage( + await generateCustomPage( target, { name: 'CustomPage', @@ -309,7 +313,7 @@ describe('CustomPage', () => { expect(updatedI18nProperties).toMatchSnapshot(); // Generate another page and check if new tab sizing recalculated correctly without passing tab size info - generateCustomPage( + await generateCustomPage( target, { name: 'Second', @@ -329,27 +333,27 @@ describe('CustomPage', () => { entity: 'RootEntity', typescript: true }; - test('latest version with minimal input', () => { + test('latest version with minimal input', async () => { const target = join(testDir, 'minimal-input'); fs.write(join(target, 'webapp/manifest.json'), testAppManifest); //act - generateCustomPage(target, minimalInput, fs); + await generateCustomPage(target, minimalInput, fs); //check expect(fs.read(join(target, 'webapp/ext/customPage/CustomPage.controller.ts'))).toMatchSnapshot(); }); - test('lower UI5 version(1.84)', () => { + test('lower UI5 version(1.84)', async () => { const target = join(testDir, 'minimal-input'); fs.write(join(target, 'webapp/manifest.json'), testAppManifest); const testInput = { ...minimalInput, minUI5Version: '1.84.62' }; //act - generateCustomPage(target, testInput, fs); + await generateCustomPage(target, testInput, fs); //check expect(fs.read(join(target, 'webapp/ext/customPage/CustomPage.controller.ts'))).toMatchSnapshot(); }); }); - test('Add library dependency `sap.fe.core`', () => { + test('Add library dependency `sap.fe.core`', async () => { const expandedManifest = JSON.parse(testAppManifest); expandedManifest['sap.ui5'].dependencies.libs = { 'existing.library': {} }; @@ -360,7 +364,7 @@ describe('CustomPage', () => { const target = join(testDir, 'libraryDependency'); fs.write(join(target, 'webapp/manifest.json'), JSON.stringify(expandedManifest)); //act - generateCustomPage(target, minimalInput, fs); + await generateCustomPage(target, minimalInput, fs); //check expect((fs.readJSON(join(target, 'webapp/manifest.json')) as any)?.['sap.ui5'].dependencies).toMatchSnapshot(); }); diff --git a/packages/fe-fpm-writer/test/unit/page/list.test.ts b/packages/fe-fpm-writer/test/unit/page/list.test.ts index 74e3ec6a75..f1ea7cd164 100644 --- a/packages/fe-fpm-writer/test/unit/page/list.test.ts +++ b/packages/fe-fpm-writer/test/unit/page/list.test.ts @@ -42,27 +42,27 @@ describe('ListReport', () => { entity: 'RootEntity' }; - test('minimal input', () => { + test('minimal input', async () => { const target = join(testDir, 'minimal-input'); fs.write(join(target, 'webapp/manifest.json'), testAppManifest); - generate(target, minimalInput, fs); + await generate(target, minimalInput, fs); expect(fs.readJSON(join(target, 'webapp/manifest.json'))).toMatchSnapshot(); }); - test('minimal input, plus minUi5Version and contextPath', () => { + test('minimal input, plus minUi5Version and contextPath', async () => { const target = join(testDir, 'minimal-input'); fs.write(join(target, 'webapp/manifest.json'), testAppManifest); const testApiData = JSON.parse(JSON.stringify(minimalInput)); testApiData.minUI5Version = '1.110'; testApiData.contextPath = '/my/navigation'; //act - generate(target, testApiData, fs); + await generate(target, testApiData, fs); //check expect(fs.readJSON(join(target, 'webapp/manifest.json'))).toMatchSnapshot(); }); - test('minimal input, plus optional page id', () => { + test('minimal input, plus optional page id', async () => { const target = join(testDir, 'minimal-input'); fs.write(join(target, 'webapp/manifest.json'), testAppManifest); const minInput = { @@ -71,15 +71,15 @@ describe('ListReport', () => { }; const testApiData = JSON.parse(JSON.stringify(minInput)); //act - generate(target, testApiData, fs); + await generate(target, testApiData, fs); //check expect(fs.readJSON(join(target, 'webapp/manifest.json'))).toMatchSnapshot(); }); - test('all optional settings used', () => { + test('all optional settings used', async () => { const target = join(testDir, 'all-settings'); fs.write(join(target, 'webapp/manifest.json'), testAppManifest); - generate( + await generate( target, { ...minimalInput, @@ -100,29 +100,29 @@ describe('ListReport', () => { }); describe('Test property custom "tabSizing"', () => { - test.each(tabSizingTestCases)('$name', ({ tabInfo, expectedAfterSave }) => { + test.each(tabSizingTestCases)('$name', async ({ tabInfo, expectedAfterSave }) => { const target = join(testDir, 'tab-sizing'); fs.write(join(target, 'webapp/manifest.json'), testAppManifest); - generate(target, { ...minimalInput, tabInfo }, fs); + await generate(target, { ...minimalInput, tabInfo }, fs); let updatedManifest = fs.read(join(target, 'webapp/manifest.json')); let result = detectTabSpacing(updatedManifest); expect(result).toEqual(expectedAfterSave); // Generate another page and check if new tab sizing recalculated correctly without passing tab size info - generate(target, { entity: 'Second' }, fs); + await generate(target, { entity: 'Second' }, fs); updatedManifest = fs.read(join(target, 'webapp/manifest.json')); result = detectTabSpacing(updatedManifest); expect(result).toEqual(expectedAfterSave); }); }); - test('Add library dependency `sap.fe.templates` ', () => { + test('Add library dependency `sap.fe.templates` ', async () => { const testManifest = JSON.parse(testAppManifest); delete testManifest['sap.ui5'].dependencies; const target = join(testDir, 'libraryDependency'); fs.write(join(target, 'webapp/manifest.json'), JSON.stringify(testManifest)); //act - generate(target, minimalInput, fs); + await generate(target, minimalInput, fs); //check expect( (fs.readJSON(join(target, 'webapp/manifest.json')) as any)?.['sap.ui5'].dependencies diff --git a/packages/fe-fpm-writer/test/unit/page/object.test.ts b/packages/fe-fpm-writer/test/unit/page/object.test.ts index 2398766852..6d69930116 100644 --- a/packages/fe-fpm-writer/test/unit/page/object.test.ts +++ b/packages/fe-fpm-writer/test/unit/page/object.test.ts @@ -57,27 +57,27 @@ describe('ObjectPage', () => { entity: 'OtherEntity' }; - test('minimal input', () => { + test('minimal input', async () => { const target = join(testDir, 'minimal-input'); fs.write(join(target, 'webapp/manifest.json'), testAppManifest); - generate(target, minimalInput, fs); + await generate(target, minimalInput, fs); expect(fs.readJSON(join(target, 'webapp/manifest.json'))).toMatchSnapshot(); }); - test('minimal input, plus minUi5Version and contextPath', () => { + test('minimal input, plus minUi5Version and contextPath', async () => { const target = join(testDir, 'minimal-input'); fs.write(join(target, 'webapp/manifest.json'), testAppManifest); const testApiData = JSON.parse(JSON.stringify(minimalInput)); testApiData.minUI5Version = '1.110'; testApiData.contextPath = '/my/navigation'; //act - generate(target, testApiData, fs); + await generate(target, testApiData, fs); //check expect(fs.readJSON(join(target, 'webapp/manifest.json'))).toMatchSnapshot(); }); - test('minimal input, plus optional page id', () => { + test('minimal input, plus optional page id', async () => { const target = join(testDir, 'minimal-input'); fs.write(join(target, 'webapp/manifest.json'), testAppManifest); const minInput = { @@ -86,15 +86,15 @@ describe('ObjectPage', () => { }; const testApiData = JSON.parse(JSON.stringify(minInput)); //act - generate(target, testApiData, fs); + await generate(target, testApiData, fs); //check expect(fs.readJSON(join(target, 'webapp/manifest.json'))).toMatchSnapshot(); }); - test('all optional settings', () => { + test('all optional settings', async () => { const target = join(testDir, 'all-settings'); fs.write(join(target, 'webapp/manifest.json'), testAppManifest); - generate( + await generate( target, { ...minimalInput, @@ -109,10 +109,10 @@ describe('ObjectPage', () => { expect(fs.readJSON(join(target, 'webapp/manifest.json'))).toMatchSnapshot(); }); - test('simple inbound navigation', () => { + test('simple inbound navigation', async () => { const target = join(testDir, 'with-nav'); fs.write(join(target, 'webapp/manifest.json'), testAppManifest); - generate( + await generate( target, { ...minimalInput, @@ -127,7 +127,7 @@ describe('ObjectPage', () => { expect((fs.readJSON(join(target, 'webapp/manifest.json')) as any)?.['sap.ui5'].routing).toMatchSnapshot(); }); - test('simple inbound navigation, plus optional page id', () => { + test('simple inbound navigation, plus optional page id', async () => { const target = join(testDir, 'with-nav'); fs.write(join(target, 'webapp/manifest.json'), testAppManifest); const minInput = { @@ -139,14 +139,14 @@ describe('ObjectPage', () => { navKey: true } }; - generate(target, minInput, fs); + await generate(target, minInput, fs); expect((fs.readJSON(join(target, 'webapp/manifest.json')) as any)?.['sap.ui5'].routing).toMatchSnapshot(); }); - test('simple nested navigation', () => { + test('simple nested navigation', async () => { const target = join(testDir, 'with-nested-nav'); fs.write(join(target, 'webapp/manifest.json'), testAppManifest); - generate( + await generate( target, { ...minimalInput, @@ -162,29 +162,29 @@ describe('ObjectPage', () => { }); describe('Test property custom "tabSizing"', () => { - test.each(tabSizingTestCases)('$name', ({ tabInfo, expectedAfterSave }) => { + test.each(tabSizingTestCases)('$name', async ({ tabInfo, expectedAfterSave }) => { const target = join(testDir, 'tab-sizing'); fs.write(join(target, 'webapp/manifest.json'), testAppManifest); - generate(target, { ...minimalInput, tabInfo }, fs); + await generate(target, { ...minimalInput, tabInfo }, fs); let updatedManifest = fs.read(join(target, 'webapp/manifest.json')); let result = detectTabSpacing(updatedManifest); expect(result).toEqual(expectedAfterSave); // Generate another page and check if new tab sizing recalculated correctly without passing tab size info - generate(target, { entity: 'Second' }, fs); + await generate(target, { entity: 'Second' }, fs); updatedManifest = fs.read(join(target, 'webapp/manifest.json')); result = detectTabSpacing(updatedManifest); expect(result).toEqual(expectedAfterSave); }); }); - test('Add library dependency `sap.fe.templates` ', () => { + test('Add library dependency `sap.fe.templates` ', async () => { const testManifest = JSON.parse(testAppManifest); delete testManifest['sap.ui5'].dependencies; const target = join(testDir, 'libraryDependency'); fs.write(join(target, 'webapp/manifest.json'), JSON.stringify(testManifest)); //act - generate(target, minimalInput, fs); + await generate(target, minimalInput, fs); //check expect( (fs.readJSON(join(target, 'webapp/manifest.json')) as any)?.['sap.ui5'].dependencies diff --git a/packages/fe-fpm-writer/test/unit/section.test.ts b/packages/fe-fpm-writer/test/unit/section.test.ts index 7def972739..45e84831cd 100644 --- a/packages/fe-fpm-writer/test/unit/section.test.ts +++ b/packages/fe-fpm-writer/test/unit/section.test.ts @@ -53,7 +53,7 @@ describe('CustomSection', () => { fs.delete(testDir); fs.write(join(testDir, 'webapp/manifest.json'), JSON.stringify(manifest)); }); - test('with fragmentFile', () => { + test('with fragmentFile', async () => { const testCustomSection: CustomSection = { ...customSection, fragmentFile: 'NewCustomSectionFragment' @@ -62,7 +62,7 @@ describe('CustomSection', () => { testDir, `webapp/${testCustomSection.folder}/${testCustomSection.fragmentFile}.fragment.xml` ); - generateCustomSection(testDir, { ...testCustomSection }, fs); + await generateCustomSection(testDir, { ...testCustomSection }, fs); const updatedManifest = fs.readJSON(join(testDir, 'webapp/manifest.json')) as Manifest; const settings = ( updatedManifest['sap.ui5']?.['routing']?.['targets']?.['sample']?.['options'] as Record @@ -70,12 +70,12 @@ describe('CustomSection', () => { expect(settings.content).toMatchSnapshot(); expect(fs.read(expectedSectionFragmentPath)).toMatchSnapshot(); }); - test('with handler, all properties', () => { + test('with handler, all properties', async () => { const testCustomSection: CustomSection = { ...customSection, eventHandler: true }; - generateCustomSection(testDir, { ...testCustomSection }, fs); + await generateCustomSection(testDir, { ...testCustomSection }, fs); const updatedManifest = fs.readJSON(join(testDir, 'webapp/manifest.json')) as Manifest; const settings = ( updatedManifest['sap.ui5']?.['routing']?.['targets']?.['sample']?.['options'] as Record @@ -85,14 +85,14 @@ describe('CustomSection', () => { expect(fs.read(expectedFragmentPath)).toMatchSnapshot(); expect(fs.read(expectedFragmentPath.replace('.fragment.xml', '.js'))).toMatchSnapshot(); }); - test('with existing handler, all properties', () => { + test('with existing handler, all properties', async () => { const testCustomSection: CustomSection = { ...customSection, eventHandler: true }; fs.write(expectedFragmentPath, 'dummyContent'); - generateCustomSection(testDir, { ...testCustomSection }, fs); + await generateCustomSection(testDir, { ...testCustomSection }, fs); const updatedManifest = fs.readJSON(join(testDir, 'webapp/manifest.json')) as Manifest; const settings = ( @@ -104,11 +104,11 @@ describe('CustomSection', () => { expect(fs.read(expectedFragmentPath)).toEqual('dummyContent'); }); - test('no handler, all properties', () => { + test('no handler, all properties', async () => { const testCustomSection: CustomSection = { ...customSection }; - generateCustomSection(testDir, { ...testCustomSection }, fs); + await generateCustomSection(testDir, { ...testCustomSection }, fs); const updatedManifest = fs.readJSON(join(testDir, 'webapp/manifest.json')) as Manifest; const settings = ( @@ -119,12 +119,12 @@ describe('CustomSection', () => { expect(fs.read(expectedFragmentPath)).toMatchSnapshot(); }); - test('custom control', () => { + test('custom control', async () => { const testCustomSection: CustomSection = { ...customSection, control: '' }; - generateCustomSection(testDir, { ...testCustomSection }, fs); + await generateCustomSection(testDir, { ...testCustomSection }, fs); const updatedManifest = fs.readJSON(join(testDir, 'webapp/manifest.json')) as Manifest; const settings = ( @@ -135,12 +135,12 @@ describe('CustomSection', () => { expect(fs.read(expectedFragmentPath)).toMatchSnapshot(); }); - test('no handler, no fs, all properties', () => { + test('no handler, no fs, all properties', async () => { const testCustomSection: CustomSection = { ...customSection }; - const testFS = generateCustomSection(testDir, { ...testCustomSection }); + const testFS = await generateCustomSection(testDir, { ...testCustomSection }); const updatedManifest = testFS.readJSON(join(testDir, 'webapp/manifest.json')) as Manifest; const settings = ( updatedManifest['sap.ui5']?.['routing']?.['targets']?.['sample']?.['options'] as Record @@ -150,13 +150,13 @@ describe('CustomSection', () => { expect(testFS.read(expectedFragmentPath)).toMatchSnapshot(); }); - test('no handler, no fs, no folder, section name uppercase', () => { + test('no handler, no fs, no folder, section name uppercase', async () => { const testCustomSection: CustomSection = { ...customSection, folder: undefined }; - const testFS = generateCustomSection(testDir, { ...testCustomSection }); + const testFS = await generateCustomSection(testDir, { ...testCustomSection }); const fragmentPath = join( testDir, `webapp`, @@ -167,14 +167,14 @@ describe('CustomSection', () => { expect(testFS.exists(fragmentPath)).toBeTruthy(); }); - test('no handler, no fs, no folder, section name lowercase', () => { + test('no handler, no fs, no folder, section name lowercase', async () => { const testCustomSection: CustomSection = { ...customSection, folder: undefined, name: 'newCustomSection' }; - const testFS = generateCustomSection(testDir, { ...testCustomSection }); + const testFS = await generateCustomSection(testDir, { ...testCustomSection }); const fragmentPath = join( testDir, `webapp`, @@ -185,14 +185,14 @@ describe('CustomSection', () => { expect(testFS.exists(fragmentPath)).toBeTruthy(); }); - test('no handler, no fs, no folder, section name uppercase', () => { + test('no handler, no fs, no folder, section name uppercase', async () => { const testCustomSection: CustomSection = { ...customSection, folder: undefined, name: 'NewCustomSection' }; - const testFS = generateCustomSection(testDir, { ...testCustomSection }); + const testFS = await generateCustomSection(testDir, { ...testCustomSection }); const fragmentPath = join( testDir, @@ -204,14 +204,14 @@ describe('CustomSection', () => { expect(testFS.exists(fragmentPath)).toBeTruthy(); }); - test('no handler, no fs, folder upper case, section name lowercase', () => { + test('no handler, no fs, folder upper case, section name lowercase', async () => { const testCustomSection: CustomSection = { ...customSection, folder: 'Any', name: 'newCustomSection' }; - const testFS = generateCustomSection(testDir, { ...testCustomSection }); + const testFS = await generateCustomSection(testDir, { ...testCustomSection }); const fragmentPath = join( testDir, `webapp`, @@ -221,7 +221,7 @@ describe('CustomSection', () => { expect(testFS.exists(fragmentPath)).toBeTruthy(); }); - test('different data and not existing target', () => { + test('different data and not existing target', async () => { const testCustomSection: CustomSection = { target: 'dummy', name: 'DummySection', @@ -236,7 +236,7 @@ describe('CustomSection', () => { testDir, `webapp/${testCustomSection.folder}/${testCustomSection.name}.fragment.xml` ); - generateCustomSection(testDir, { ...testCustomSection }, fs); + await generateCustomSection(testDir, { ...testCustomSection }, fs); const updatedManifest = fs.readJSON(join(testDir, 'webapp/manifest.json')) as Manifest; const targets = updatedManifest['sap.ui5']?.['routing']?.['targets']; @@ -246,14 +246,14 @@ describe('CustomSection', () => { }); const testVersions = ['1.85', '1.84', '1.86', '1.89', '1.90', '1.98']; - test.each(testVersions)('Versions %s, with handler, all properties', (minUI5Version) => { + test.each(testVersions)('Versions %s, with handler, all properties', async (minUI5Version) => { const testCustomSection: CustomSection = { ...customSection, eventHandler: true, minUI5Version }; - generateCustomSection(testDir, { ...testCustomSection }, fs); + await generateCustomSection(testDir, { ...testCustomSection }, fs); const updatedManifest = fs.readJSON(join(testDir, 'webapp/manifest.json')) as Manifest; const settings = ( @@ -266,11 +266,11 @@ describe('CustomSection', () => { }); const folderVariants = ['extensions/custom', 'extensions\\custom']; - test.each(folderVariants)('Existing folder variations - %s', (folderVariant) => { + test.each(folderVariants)('Existing folder variations - %s', async (folderVariant) => { const testCustomSection = JSON.parse(JSON.stringify(customSection)); testCustomSection.folder = folderVariant; - generateCustomSection(testDir, { ...testCustomSection }, fs); + await generateCustomSection(testDir, { ...testCustomSection }, fs); const updatedManifest = fs.readJSON(join(testDir, 'webapp/manifest.json')) as Manifest; const settings = ( @@ -284,41 +284,41 @@ describe('CustomSection', () => { }); describe('Test property "eventHandler"', () => { - const generateCustomSectionWithEventHandler = ( + const generateCustomSectionWithEventHandler = async ( sectionId: string, eventHandler: string | EventHandlerConfiguration, folder?: string ) => { - generateCustomSection(testDir, { ...customSection, name: sectionId, folder, eventHandler }, fs); + await generateCustomSection(testDir, { ...customSection, name: sectionId, folder, eventHandler }, fs); }; - test('"eventHandler" is empty "object" - create new file with default function name', () => { + test('"eventHandler" is empty "object" - create new file with default function name', async () => { const id = customSection.name; - generateCustomSectionWithEventHandler(id, {}, customSection.folder); + await generateCustomSectionWithEventHandler(id, {}, customSection.folder); const xmlPath = join(testDir, `webapp/${customSection.folder}/${id}.fragment.xml`); expect(fs.read(xmlPath)).toMatchSnapshot(); expect(fs.read(xmlPath.replace('.fragment.xml', '.js'))).toMatchSnapshot(); }); - test('"eventHandler" is "object" - create new file with custom file and function names', () => { + test('"eventHandler" is "object" - create new file with custom file and function names', async () => { const extension = { fnName: 'DummyOnAction', fileName: 'dummyAction' }; const id = customSection.name; - generateCustomSectionWithEventHandler(id, extension, customSection.folder); + await generateCustomSectionWithEventHandler(id, extension, customSection.folder); const fragmentName = `${id}.fragment.xml`; const xmlPath = join(testDir, `webapp/${customSection.folder}/${fragmentName}`); expect(fs.read(xmlPath)).toMatchSnapshot(); expect(fs.read(xmlPath.replace(fragmentName, `${extension.fileName}.js`))).toMatchSnapshot(); }); - test('"eventHandler" is "object" - create new file with custom function name', () => { + test('"eventHandler" is "object" - create new file with custom function name', async () => { const extension = { fnName: 'DummyOnAction' }; const id = customSection.name; - generateCustomSectionWithEventHandler(id, extension, customSection.folder); + await generateCustomSectionWithEventHandler(id, extension, customSection.folder); const xmlPath = join(testDir, `webapp/${customSection.folder}/${id}.fragment.xml`); expect(fs.read(xmlPath)).toMatchSnapshot(); expect(fs.read(xmlPath.replace('.fragment.xml', '.js'))).toMatchSnapshot(); @@ -346,7 +346,7 @@ describe('CustomSection', () => { ]; test.each(positions)( '"eventHandler" is object. Append new function to existing js file with $name', - ({ position, endOfLines }) => { + async ({ position, endOfLines }) => { // Generate handler with single method - content should be updated during generating of custom section fs.copyTpl(join(__dirname, '../../templates', 'common/EventHandler.js'), existingPath, { eventHandlerFnName: 'onPress' @@ -364,7 +364,7 @@ describe('CustomSection', () => { } }; - generateCustomSectionWithEventHandler(id, extension, folder); + await generateCustomSectionWithEventHandler(id, extension, folder); const xmlPath = join(testDir, 'webapp', folder, `${id}.fragment.xml`); expect(fs.read(xmlPath)).toMatchSnapshot(); // Check update js file content @@ -374,8 +374,8 @@ describe('CustomSection', () => { }); describe('Test property custom "tabSizing"', () => { - test.each(tabSizingTestCases)('$name', ({ tabInfo, expectedAfterSave }) => { - generateCustomSection( + test.each(tabSizingTestCases)('$name', async ({ tabInfo, expectedAfterSave }) => { + await generateCustomSection( testDir, { ...customSection, @@ -387,7 +387,7 @@ describe('CustomSection', () => { let result = detectTabSpacing(updatedManifest); expect(result).toEqual(expectedAfterSave); // Generate another section and check if new tab sizing recalculated correctly without passing tab size info - generateCustomSection( + await generateCustomSection( testDir, { ...customSection, @@ -441,8 +441,8 @@ describe('CustomSection', () => { } ]; positionTests.forEach((testCase) => { - test(`Test 'position' property. ${testCase.name}`, () => { - generateCustomSection( + test(`Test 'position' property. ${testCase.name}`, async () => { + await generateCustomSection( testDir, { ...customSection, diff --git a/packages/fe-fpm-writer/test/unit/subsection.test.ts b/packages/fe-fpm-writer/test/unit/subsection.test.ts index 9c7deb8a72..1de8d0b5ca 100644 --- a/packages/fe-fpm-writer/test/unit/subsection.test.ts +++ b/packages/fe-fpm-writer/test/unit/subsection.test.ts @@ -39,14 +39,14 @@ describe('SubCustomSection generateCustomSubSection', () => { }); const testVersions = ['1.85', '1.86', '1.98']; - test.each(testVersions)('Versions %s', (minUI5Version) => { + test.each(testVersions)('Versions %s', async (minUI5Version) => { const testCustomSubSection: CustomSubSection = { ...customSubSection, eventHandler: true, minUI5Version }; - generateCustomSubSection(testDir, { ...testCustomSubSection }, fs); + await generateCustomSubSection(testDir, { ...testCustomSubSection }, fs); const updatedManifest = fs.readJSON(join(testDir, 'webapp/manifest.json')) as Manifest; const settings = ( @@ -69,7 +69,7 @@ describe('SubCustomSection generateCustomSubSection', () => { parentSection: 'ExistingFacet2' } ]; - test.each(existingParentSectionTestCases)('$name', ({ parentSection }) => { + test.each(existingParentSectionTestCases)('$name', async ({ parentSection }) => { // Prepare manifest by adding existing sections const manifestTemp = JSON.parse(JSON.stringify(manifest)); manifestTemp['sap.ui5'].routing.targets.sample.options.settings.content.body.sections = { @@ -95,7 +95,7 @@ describe('SubCustomSection generateCustomSubSection', () => { ...customSubSection, parentSection }; - generateCustomSubSection(testDir, { ...testCustomSubSection }, fs); + await generateCustomSubSection(testDir, { ...testCustomSubSection }, fs); const updatedManifest = fs.readJSON(join(testDir, 'webapp/manifest.json')) as Manifest; const settings = ( updatedManifest['sap.ui5']?.['routing']?.['targets']?.['sample']?.['options'] as Record @@ -143,8 +143,8 @@ describe('SubCustomSection generateCustomSubSection', () => { } ]; positionTests.forEach((testCase) => { - test(`Test 'position' property. ${testCase.name}`, () => { - generateCustomSubSection( + test(`Test 'position' property. ${testCase.name}`, async () => { + await generateCustomSubSection( testDir, { ...customSubSection, diff --git a/packages/fe-fpm-writer/test/unit/view.test.ts b/packages/fe-fpm-writer/test/unit/view.test.ts index 5339669764..0e60405482 100644 --- a/packages/fe-fpm-writer/test/unit/view.test.ts +++ b/packages/fe-fpm-writer/test/unit/view.test.ts @@ -41,9 +41,9 @@ describe('CustomView', () => { fs.write(join(testDir, 'webapp/manifest.json'), JSON.stringify(manifest)); }); - test('only mandatory properties', () => { + test('only mandatory properties', async () => { //sut - generateCustomView(testDir, customView, fs); + await generateCustomView(testDir, customView, fs); updatedManifest = fs.readJSON(join(testDir, 'webapp/manifest.json')); const { extension, views } = getManifestSegments(); expect(extension).not.toBeDefined(); @@ -51,37 +51,37 @@ describe('CustomView', () => { expect(fs.read(expectedFragmentPath)).toMatchSnapshot(); }); - test('with control `true` (sample table fragment)', () => { + test('with control `true` (sample table fragment)', async () => { const testCustomView: CustomView = { ...customView, control: true }; - generateCustomView(testDir, testCustomView, fs); + await generateCustomView(testDir, testCustomView, fs); updatedManifest = fs.readJSON(join(testDir, 'webapp/manifest.json')); const { views } = getManifestSegments(); expect(views).toMatchSnapshot(); expect(fs.read(expectedFragmentPath)).toMatchSnapshot(); }); - test('with custom control passed in interface', () => { + test('with custom control passed in interface', async () => { const testCustomView: CustomView = { ...customView, control: '' }; - generateCustomView(testDir, testCustomView, fs); + await generateCustomView(testDir, testCustomView, fs); updatedManifest = fs.readJSON(join(testDir, 'webapp/manifest.json')); const { views } = getManifestSegments(); expect(views).toMatchSnapshot(); expect(fs.read(expectedFragmentPath)).toMatchSnapshot(); }); - test('with new handler', () => { + test('with new handler', async () => { //sut const testCustomView: CustomView = { ...customView, eventHandler: true }; - generateCustomView(testDir, testCustomView, fs); + await generateCustomView(testDir, testCustomView, fs); updatedManifest = fs.readJSON(join(testDir, 'webapp/manifest.json')); const { extension, views } = getManifestSegments(); @@ -91,14 +91,14 @@ describe('CustomView', () => { expect(fs.read(expectedFragmentPath.replace('.fragment.xml', '.controller.js'))).toMatchSnapshot(); }); - test('with existing handler', () => { + test('with existing handler', async () => { const controllerPath = 'my.test.App.ext.ExistingHandler.onCustomAction'; fs.write(controllerPath, 'dummyContent'); const testCustomView: CustomView = { ...customView, eventHandler: controllerPath }; - generateCustomView(testDir, testCustomView, fs); + await generateCustomView(testDir, testCustomView, fs); updatedManifest = fs.readJSON(join(testDir, 'webapp/manifest.json')); const { extension, views } = getManifestSegments(); @@ -108,13 +108,13 @@ describe('CustomView', () => { expect(fs.read(controllerPath)).toEqual('dummyContent'); }); - test('with new handler and new table fragment (all properties)', () => { + test('with new handler and new table fragment (all properties)', async () => { const testCustomView: CustomView = { ...customView, eventHandler: true, control: true }; - generateCustomView(testDir, testCustomView, fs); + await generateCustomView(testDir, testCustomView, fs); updatedManifest = fs.readJSON(join(testDir, 'webapp/manifest.json')); const { extension, views } = getManifestSegments(); @@ -124,7 +124,7 @@ describe('CustomView', () => { expect(fs.read(expectedFragmentPath.replace('.fragment.xml', '.controller.js'))).toMatchSnapshot(); }); - test('without existing views', () => { + test('without existing views', async () => { const testManifest = JSON.parse(JSON.stringify(manifest)); testManifest['sap.ui5']['routing']['targets']['sample']['options']['settings'] = {}; fs = create(createStorage()); @@ -134,7 +134,7 @@ describe('CustomView', () => { ...customView, control: true }; - generateCustomView(testDir, testCustomView, fs); + await generateCustomView(testDir, testCustomView, fs); updatedManifest = fs.readJSON(join(testDir, 'webapp/manifest.json')); const { views } = getManifestSegments(); @@ -142,7 +142,7 @@ describe('CustomView', () => { expect(fs.read(expectedFragmentPath)).toMatchSnapshot(); }); - test('with existing views', () => { + test('with existing views', async () => { const testManifest = JSON.parse(JSON.stringify(manifest)); (testManifest['sap.ui5']['routing']['targets']['sample']['options']['settings']['views'] as Views) = { paths: [ @@ -164,7 +164,7 @@ describe('CustomView', () => { ...customView, control: true }; - generateCustomView(testDir, testCustomView, fs); + await generateCustomView(testDir, testCustomView, fs); updatedManifest = fs.readJSON(join(testDir, 'webapp/manifest.json')); const { views } = getManifestSegments(); @@ -172,7 +172,7 @@ describe('CustomView', () => { expect(fs.read(expectedFragmentPath)).toMatchSnapshot(); }); - test('with existing views and custom views', () => { + test('with existing views and custom views', async () => { const testManifest = JSON.parse(JSON.stringify(manifest)); (testManifest['sap.ui5']['routing']['targets']['sample']['options']['settings']['views'] as Views) = { paths: [ @@ -194,7 +194,7 @@ describe('CustomView', () => { ...customView, control: true }; - generateCustomView(testDir, testCustomView, fs); + await generateCustomView(testDir, testCustomView, fs); updatedManifest = fs.readJSON(join(testDir, 'webapp/manifest.json')); const { views } = getManifestSegments(); @@ -202,7 +202,7 @@ describe('CustomView', () => { expect(fs.read(expectedFragmentPath)).toMatchSnapshot(); }); - test('with existing views, overwrite custom view entry, no view update', () => { + test('with existing views, overwrite custom view entry, no view update', async () => { const testManifest = JSON.parse(JSON.stringify(manifest)); const testData = JSON.parse(JSON.stringify(customView)); testData.viewUpdate = false; @@ -226,7 +226,7 @@ describe('CustomView', () => { ...customView, control: true }; - generateCustomView(testDir, testCustomView, fs); + await generateCustomView(testDir, testCustomView, fs); updatedManifest = fs.readJSON(join(testDir, 'webapp/manifest.json')); const { views } = getManifestSegments(); @@ -234,41 +234,41 @@ describe('CustomView', () => { }); describe('Test property "eventHandler"', () => { - const generateCustomViewWithEventHandler = ( + const generateCustomViewWithEventHandler = async ( viewId: string, eventHandler: string | EventHandlerConfiguration, folder?: string ) => { - generateCustomView(testDir, { ...customView, name: viewId, folder, eventHandler }, fs); + await generateCustomView(testDir, { ...customView, name: viewId, folder, eventHandler }, fs); }; - test('"eventHandler" is empty "object" - create new file with default function name', () => { + test('"eventHandler" is empty "object" - create new file with default function name', async () => { const id = customView.name; - generateCustomViewWithEventHandler(id, {}, customView.folder); + await generateCustomViewWithEventHandler(id, {}, customView.folder); const xmlPath = join(testDir, `webapp/${customView.folder}/${id}.fragment.xml`); expect(fs.read(xmlPath)).toMatchSnapshot(); expect(fs.read(xmlPath.replace('.fragment.xml', '.controller.js'))).toMatchSnapshot(); }); - test('"eventHandler" is "object" - create new file with custom file and function names', () => { + test('"eventHandler" is "object" - create new file with custom file and function names', async () => { const extension = { fnName: 'DummyOnAction', fileName: 'dummyAction' }; const id = customView.name; - generateCustomViewWithEventHandler(id, extension, customView.folder); + await generateCustomViewWithEventHandler(id, extension, customView.folder); const fragmentName = `${id}.fragment.xml`; const xmlPath = join(testDir, `webapp/${customView.folder}/${fragmentName}`); expect(fs.read(xmlPath)).toMatchSnapshot(); expect(fs.read(xmlPath.replace(fragmentName, `${extension.fileName}.controller.js`))).toMatchSnapshot(); }); - test('"eventHandler" is "object" - create new file with custom function name', () => { + test('"eventHandler" is "object" - create new file with custom function name', async () => { const extension = { fnName: 'DummyOnAction' }; const id = customView.name; - generateCustomViewWithEventHandler(id, extension, customView.folder); + await generateCustomViewWithEventHandler(id, extension, customView.folder); const xmlPath = join(testDir, `webapp/${customView.folder}/${id}.fragment.xml`); expect(fs.read(xmlPath)).toMatchSnapshot(); expect(fs.read(xmlPath.replace('.fragment.xml', '.controller.js'))).toMatchSnapshot(); @@ -290,7 +290,7 @@ describe('CustomView', () => { ]; test.each(positions)( '"eventHandler" is object. Append new function to existing js file with $name', - ({ position, endOfLines }) => { + async ({ position, endOfLines }) => { const fileName = 'MyExistingAction'; // Create existing file with existing actions const folder = join('extensions', 'custom'); @@ -315,7 +315,7 @@ describe('CustomView', () => { }; const id = customView.name; - generateCustomViewWithEventHandler(id, extension, folder); + await generateCustomViewWithEventHandler(id, extension, folder); const xmlPath = join(testDir, 'webapp', folder, `${id}.fragment.xml`); expect(fs.read(xmlPath)).toMatchSnapshot(); // Check update js file content @@ -325,13 +325,13 @@ describe('CustomView', () => { }); describe('Test property custom "tabSizing"', () => { - test.each(tabSizingTestCases)('$name', ({ tabInfo, expectedAfterSave }) => { - generateCustomView(testDir, { ...customView, tabInfo }, fs); + test.each(tabSizingTestCases)('$name', async ({ tabInfo, expectedAfterSave }) => { + await generateCustomView(testDir, { ...customView, tabInfo }, fs); let updatedManifest = fs.read(join(testDir, 'webapp/manifest.json')); let result = detectTabSpacing(updatedManifest); expect(result).toEqual(expectedAfterSave); // Generate another view and check if new tab sizing recalculated correctly without passing tab size info - generateCustomView(testDir, { ...customView, key: 'Second', name: 'Second' }, fs); + await generateCustomView(testDir, { ...customView, key: 'Second', name: 'Second' }, fs); updatedManifest = fs.read(join(testDir, 'webapp/manifest.json')); result = detectTabSpacing(updatedManifest); expect(result).toEqual(expectedAfterSave); diff --git a/packages/fiori-elements-writer/src/fpmConfig.ts b/packages/fiori-elements-writer/src/fpmConfig.ts index 9364f476ae..ac92452058 100644 --- a/packages/fiori-elements-writer/src/fpmConfig.ts +++ b/packages/fiori-elements-writer/src/fpmConfig.ts @@ -16,7 +16,7 @@ export async function generateFpmConfig( fs: Editor ): Promise { const config: FPMSettings = feApp.template.settings as unknown as FPMSettings; - generateCustomPage( + await generateCustomPage( basePath, { entity: config.entityConfig.mainEntityName,