Skip to content

Commit 4a64f53

Browse files
authored
Merge the content from the testing branch into main (#32)
Finally bring them together. The testing branch will be emptied once this is merged.
1 parent 918373e commit 4a64f53

19 files changed

+641
-229
lines changed

.babelrc.json

-13
This file was deleted.

.gitignore

+4-1
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,8 @@ tsconfig.tsbuildinfo
2323
# Dependency directories
2424
node_modules/
2525

26-
# build results
26+
# build/test results
2727
dist
28+
coverage
29+
report
30+
.nyc_output

.nycrc.json

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"all": true,
3+
"sourceMap": false,
4+
"exclude": [
5+
"**/test/**/*.ts"
6+
]
7+
}

README.md

+43-24
Original file line numberDiff line numberDiff line change
@@ -2,42 +2,50 @@
22

33
[![REUSE status](https://api.reuse.software/badge/github.com/SAP-samples/ui5-typescript-helloworld)](https://api.reuse.software/info/github.com/SAP-samples/ui5-typescript-helloworld)
44

5-
Note: in general, all information relevant for UI5 application development in TypeScript can be found at https://sap.github.io/ui5-typescript
5+
**The main resource in this repository is [the detailed step-by-step guide](step-by-step.md), which explains how the TypeScript setup is created from scratch and how all the bits and pieces fit together.**
66

77
## Description
88

9-
This app demonstrates a TypeScript setup for developing UI5 applications.
9+
This app demonstrates the TypeScript setup for developing UI5 applications, including testing. The focus is on *understanding the setup* [step by step](step-by-step.md).
1010

11-
As the focus is on the TypeScript setup, the app code itself is quite minimal, it is not using models, translation files etc.
11+
If you are *not* here for understanding the setup, then:
12+
- The *fastest* way to get started with an app is using the yeoman-based [Easy-UI5 template "ts-app"](https://github.com/ui5-community/generator-ui5-ts-app).
13+
- In the *[custom-controls](https://github.com/SAP-samples/ui5-typescript-helloworld/tree/custom-controls)* branch, there is an example how custom controls can be developed in TypeScript within applications.
14+
- In the [ui5-2.0](https://github.com/SAP-samples/ui5-typescript-helloworld/tree/ui5-2.0) branch, this repository demonstrates how an application can be tested against the type definitions (and runtime) of the upcoming *UI5 2.x version*.
15+
- A more complete *real-life-like* application is in the [TypeScript branch of the "UI5 CAP Event App"](https://github.com/SAP-samples/ui5-cap-event-app/tree/typescript). It comes with an [explanation](https://github.com/SAP-samples/ui5-cap-event-app/blob/typescript/docs/typescript.md) of what UI5 TypeScript code usually looks like and what to consider.
16+
- All *general information* about UI5 application development in TypeScript and links to tutorials, videos etc. can be found at https://sap.github.io/ui5-typescript.
1217

13-
**This repository also contains [a detailed step-by-step guide](step-by-step.md), which explains how this setup is created and how all the bits and pieces fit together.**
1418

15-
**In the [custom-controls](https://github.com/SAP-samples/ui5-typescript-helloworld/tree/custom-controls) branch, this repository also contains instructions and an example how custom controls can be developed in TypeScript within applications.**
19+
## Overview of TypeScript-related Entities
1620

17-
**In the [ui5-2.0](https://github.com/SAP-samples/ui5-typescript-helloworld/tree/ui5-2.0) branch, this repository demonstrates how an application can be tested against the type definitions (and runtime) of the upcoming UI5 2.x version.**
21+
- The UI5 type definitions (`*.d.ts` files) are loaded as dev dependency from [npm](https://www.npmjs.com/package/@types/openui5).
22+
- The file [tsconfig.json](tsconfig.json) contains the configuration for the TypeScript compilation, including a reference to the UI5 `*.d.ts` files.
23+
- The TypeScript-to-JavaScript transpilation is done by [`ui5-tooling-transpile`](https://www.npmjs.com/package/ui5-tooling-transpile), which acts as both a build plugin (build results are stored in the `dist` folder) and middleware (the UI5 dev server transpiles the TypeScript files from `webapp` before sending it to the browser). Under the hood it uses the [Babel](https://babeljs.io/) transpiler.
24+
- In addition to the TypeScript compilation, there is also a conversion from the ES6 module and class syntax used in the source files to the classic UI5 module loading and class definition syntax (`sap.ui.require(...)`/`sap.ui.define(...)` and `SuperClass.extend(...)`). This conversion is also done by `ui5-tooling-transpile`, using the [babel-plugin-transform-modules-ui5](https://github.com/ui5-community/babel-plugin-transform-modules-ui5) project from the UI5 Community (initially developed by Ryan Murphy).
1825

19-
**The [TypeScript branch of the "UI5 CAP Event App"](https://github.com/SAP-samples/ui5-cap-event-app/tree/typescript) sample demonstrates a slightly more complex application, using the same setup. It comes with an [explanation](https://github.com/SAP-samples/ui5-cap-event-app/blob/typescript/docs/typescript.md) of what UI5 TypeScript code usually looks like and what to consider.**
26+
## A Note on Testing
2027

21-
The UI5con 2021 session on TypeScript ([recording available at YouTube](https://www.youtube.com/watch?v=aXzcsOZH4q8)) explains the overall approach for TypeScript and UI5.
28+
The main differences to tests written in JavaScript relate to a) writing OPA tests and b) configuring code coverage instrumentation:
2229

23-
There is also an [application template](https://github.com/ui5-community/generator-ui5-ts-app) (based on yeoman and easy-ui5) which has been shown in the [UI5con Keynote](https://www.youtube.com/watch?v=aXzcsOZH4q8) and explained in [this blog](https://blogs.sap.com/2021/07/01/getting-started-with-typescript-for-ui5-application-development/).
30+
The *structural* code differences to writing tests in *JavaScript* are:
31+
1. The **OPA Pages are simply classes extending `Opa5`, having the actions and assertions as class methods**.
32+
2. The **OPA Journeys do not use the `Given`/`When`/`Then` objects, but call actions and assertions directly on the Page objects**.
2433

25-
| :point_up: Overview of TypeScript-related Entities |
26-
|:---------------------------|
27-
| The UI5 type definitions (`*.d.ts` files) are loaded as dev dependency from [npm](https://www.npmjs.com/package/@types/openui5). They are a work in progress, so while they should be working well already, we are still improving them, which might also lead to breaking changes.<br/>
28-
The file [tsconfig.json](tsconfig.json) contains the configuration for the TypeScript compilation, including a reference to the UI5 `*.d.ts` files.<br/>
29-
Normally, the UI5 JavaScript files (controllers, Component.js etc.) would reside in the `webapp` folder. Now they are in the [src](src) folder. The TypeScript compilation will create the `webapp` folder and put all output there. <br/>
30-
In addition to the TypeScript compilation, there is also a conversion from the ES6 module and class syntax used in the source files to the classic UI5 module loading and class definition syntax (`sap.ui.define(...)` and `superClass.extend(...)`). This conversion is using the [babel-plugin-transform-modules-ui5](https://github.com/ui5-community/babel-plugin-transform-modules-ui5) project from the UI5 Community (initially developed by Ryan Murphy). <br/>
31-
Both, the TypeScript compilation and the ES6 syntax transformation, are executed by Babel, as configured in the file [.babelrc.json](.babelrc.json)<br/>
32-
This combined transformation is triggered by both the `build:ts` and `watch:ts` scripts in [package.json](package.json). |
34+
This simplifies the test code a lot and at the same time avoids type complications in TypeScript caused by OPA APIs not fitting a typed language.
35+
All other testing code is converted from JavaScript in the same way as regular application code is (i.e. using real ECMAScript classes and modules).
3336

37+
The *setup* difference is in the configuration to instrument code for coverage reporting: the `istanbul` library needs to be added to the Babel config of `ui5-tooling-transpile-middleware` in `ui5.yaml`.
38+
39+
Details can be found in the later sections of [step-by-step.md](step-by-step.md).
40+
41+
> Note: the test setup is now using the [`ui5-test-runner`](https://github.com/ArnaudBuchholz/ui5-test-runner) instead of deprecated `karma`.
3442
3543

3644
## Requirements
3745

3846
Either [npm](https://www.npmjs.com/), [yarn](https://yarnpkg.com/), or [pnpm](https://pnpm.io/) for dependency management.
3947

40-
## Download and Installation
48+
## Setup
4149

4250
1. Clone the project:
4351

@@ -68,6 +76,17 @@ As shown in the terminal after executing this command, the app is then running o
6876

6977
In the browser, you can directly debug the original TypeScript code, which is supplied via sourcemaps (need to be enabled in the browser's developer console if it does not work straight away). If the browser doesn't automatically jump to the TypeScript code when setting breakpoints, use e.g. `Ctrl`/`Cmd` + `P` in Chrome to open the `*.ts` file you want to debug.
7078

79+
## Run the Tests
80+
81+
The tests can be executed either manually or in an automated way using [`ui5-test-runner`](https://github.com/ArnaudBuchholz/ui5-test-runner):
82+
83+
1. *Manual execution*: use `npm start` and then execute the tests by opening the [testsuite](http://localhost:8080/test/testsuite.qunit.html) at [http://localhost:8080/test/testsuite.qunit.html](http://localhost:8080/test/testsuite.qunit.html) in your browser. You can also directly launch the [QUnit tests](http://localhost:8080/test/Test.qunit.html?testsuite=test-resources/ui5/typescript/helloworld/testsuite.qunit&test=unit/unitTests) or the [Integration tests](http://localhost:8080/test/Test.qunit.html?testsuite=test-resources/ui5/typescript/helloworld/testsuite.qunit&test=integration/opaTests) individually.
84+
<!-- 2. *Test-driven* development by running Karma in watch mode using `npm run karma` (which triggers the test each time a source file changes) -->
85+
2. *Headless testing*: launch test-runner either *without* coverage reporting using `npm run test-runner` or *with* coverage using `npm run test-runner-coverage`.
86+
While the tests are running, their status can be monitored at http://localhost:8081/_/progress.html
87+
88+
> Note: when the application to test is passed using the `--url` argument (as we do it in this sample), then there is [no "watch" mode of the ui5-test-runner so far](https://github.com/ArnaudBuchholz/ui5-test-runner/issues/119), which automatically re-runs the tests when a resource changes.
89+
7190
## Build the App
7291

7392
### Unoptimized (but quick)
@@ -122,6 +141,7 @@ npm run lint
122141
## Limitations
123142

124143
- At this time, the used eslint rules are not verified to be optimal or to be in sync with UI5 recommendations.
144+
- In the future there might be further improvements to how tests are written and configured.
125145

126146
## Known Issues
127147

@@ -131,16 +151,15 @@ None.
131151

132152
The sample code is provided **as-is**. No support is provided.
133153

134-
[Create an issue](https://github.com/SAP-samples/ui5-typescript-helloworld/issues) in this repository if you find a bug.
135-
Questions can be [asked in SAP Community](https://answers.sap.com/questions/ask.html).
154+
[Create an issue](https://github.com/SAP-samples/ui5-typescript-helloworld/issues) in this repository if you find a bug in the sample app code or documentation.
136155

137-
<!-- ## Contributing -->
156+
For issues in the UI5 type definitions which are caused by the dts-generator please open [issues in the dts-generator's repository](https://github.com/SAP/ui5-typescript/issues).<br>
138157

139-
## References
158+
Issues in the UI5 type definitions which are also present in the [API documentation](https://ui5.sap.com/#/api) originate from the JSDoc comments in the original OpenUI5/SAPUI5 code, so please directly open an [OpenUI5](https://github.com/SAP/openui5/issues)/SAPUI5 ticket for those.
140159

141-
Once you have understood the setup and want to inspect the code of a slightly more comprehensive UI5 app written in TypeScript, you can check out the [TypeScript version of the UI5 CAP Event App Sample](https://github.com/SAP-samples/ui5-cap-event-app/tree/typescript).
160+
Questions can be [asked in SAP Community](https://answers.sap.com/questions/ask.html).
142161

143162
## License
144163

145-
Copyright (c) 2023 SAP SE or an SAP affiliate company. All rights reserved.
164+
Copyright (c) 2023-2025 SAP SE or an SAP affiliate company. All rights reserved.
146165
This project is licensed under the Apache Software License, version 2.0 except as noted otherwise in the [LICENSE](LICENSE) file.

package.json

+9-2
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,14 @@
88
"build": "ui5 build --clean-dest",
99
"build:opt": "ui5 build self-contained --clean-dest --all",
1010
"start": "ui5 serve --port 8080 -o index.html",
11+
"start-coverage": "ui5 serve --port 8080 --config ui5-coverage.yaml",
1112
"start:dist": "ui5 serve --port 8080 -o index.html --config ui5-dist.yaml",
1213
"ts-typecheck": "tsc --noEmit",
1314
"lint": "eslint webapp",
15+
"test-runner": "ui5-test-runner --url http://localhost:8080/test/testsuite.qunit.html",
16+
"test-runner-coverage": "ui5-test-runner --url http://localhost:8080/test/testsuite.qunit.html --coverage -ccb 60 -ccf 100 -ccl 80 -ccs 80",
17+
"test-ui5": "ui5-test-runner --start start-coverage --url http://localhost:8080/test/testsuite.qunit.html --coverage -ccb 60 -ccf 100 -ccl 80 -ccs 80",
18+
"test": "npm run lint && npm run test-ui5",
1419
"ui5lint": "ui5lint"
1520
},
1621
"repository": {
@@ -21,12 +26,14 @@
2126
"@types/openui5": "1.131.0",
2227
"@ui5/cli": "^4",
2328
"@ui5/linter": "^1.5.0",
24-
"eslint": "^9.17.0",
29+
"babel-plugin-istanbul": "^7.0.0",
30+
"eslint": "^9.19.0",
2531
"globals": "^15.14.0",
26-
"typescript": "^5.7.2",
32+
"typescript": "^5.7.3",
2733
"typescript-eslint": "^8.18.1",
2834
"ui5-middleware-livereload": "^3",
2935
"ui5-middleware-simpleproxy": "^3",
36+
"ui5-test-runner": "^5.4.3",
3037
"ui5-tooling-transpile": "^3"
3138
}
3239
}

0 commit comments

Comments
 (0)