generated from SAP/repository-template
-
Notifications
You must be signed in to change notification settings - Fork 43
/
Copy pathgenerateOPATests.ts
53 lines (51 loc) · 2.12 KB
/
generateOPATests.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import { generateFreestyleOPAFiles } from '@sap-ux/ui5-test-writer';
import type { Package } from '@sap-ux/ui5-application-writer';
import type { FreestyleApp, BasicAppSettings } from './types';
import type { Logger } from '@sap-ux/logger';
import type { Editor } from 'mem-fs-editor';
/**
* Adds test scripts to the package.json object.
*
* @param {Package} packageJson - The package.json object to update.
* @param {boolean} addMock - Whether to include the UI5 mock YAML configuration.
*/
function addTestScripts(packageJson: Package, addMock: boolean): void {
// Note: 'ui5MockYamlScript' is empty when no data source is selected.
const ui5MockYamlScript = addMock ? '--config ./ui5-mock.yaml ' : '';
packageJson.scripts = {
...packageJson.scripts,
'unit-test': `fiori run ${ui5MockYamlScript}--open 'test/unit/unitTests.qunit.html'`,
'int-test': `fiori run ${ui5MockYamlScript}--open 'test/integration/opaTests.qunit.html'`
};
}
/**
* Generates OPA tests for a freestyle application.
*
* @param {string} basePath - The base directory path.
* @param {FreestyleApp} ffApp - The freestyle application configuration.
* @param {boolean} addMock - Whether to include the UI5 mock YAML configuration.
* @param {Package} packageJson - The package.json object to update.
* @param {Editor} [fs] - Optional file system editor instance.
* @param {Logger} [log] - Optional logger instance.
* @returns {Promise<Editor>} - The modified file system editor.
*/
export async function generateOPATests<T>(
basePath: string,
ffApp: FreestyleApp<T>,
addMock: boolean,
packageJson: Package,
fs?: Editor,
log?: Logger
): Promise<void> {
addTestScripts(packageJson, addMock);
const config = {
appId: ffApp.app.id,
applicationDescription: ffApp.app.description,
applicationTitle: ffApp.app.title,
viewName: (ffApp.template.settings as BasicAppSettings).viewName,
ui5Theme: ffApp.ui5?.ui5Theme,
ui5Version: ffApp.ui5?.version,
enableTypeScript: ffApp.appOptions?.typescript
};
await generateFreestyleOPAFiles(basePath, config, fs, log);
}