Skip to content

Commit b5836a5

Browse files
matz3RandomByte
authored andcommitted
Add Karma testing and ESLint validation
1 parent ad4bd41 commit b5836a5

File tree

4 files changed

+153
-9
lines changed

4 files changed

+153
-9
lines changed

README.md

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,18 @@
2424
```
2525

2626
## Testing
27-
* Start a local server and run the unit tests (http://localhost:8080/test/unit/unitTests.qunit.html)
27+
* Run ESLint code validation
2828
```sh
29-
ui5 serve -o /test/unit/unitTests.qunit.html
29+
npm run lint
3030
```
31-
* Start a local server and run the OPA5 tests (http://localhost:8080/test/integration/opaTests.qunit.html)
31+
* Start a local server and execute the tests automatically after every change
3232
```sh
33-
ui5 serve -o /test/integration/opaTests.qunit.html
33+
npm run watch
34+
```
35+
* Run ESLint, start a local server and run the tests in CI mode
36+
```sh
37+
npm test
3438
```
35-
3639
## Building
3740
### Option 1: Standard preload build
3841
1. Execute the build

karma-ci.conf.js

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// Karma configuration
2+
// Generated on Wed Jun 13 2018 14:38:44 GMT+0200 (CEST)
3+
4+
module.exports = function(config) {
5+
require("./karma.conf")(config);
6+
config.set({
7+
8+
// preprocess matching files before serving them to the browser
9+
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
10+
preprocessors: {
11+
'{webapp,webapp/!(test)}/*.js': ['coverage']
12+
},
13+
14+
coverageReporter: {
15+
includeAllSources: true,
16+
reporters: [
17+
{
18+
type: 'html',
19+
dir: '../coverage/'
20+
},
21+
{
22+
type: 'text'
23+
}
24+
],
25+
check: {
26+
each: {
27+
statements: 100,
28+
branches: 100,
29+
functions: 100,
30+
lines: 100
31+
}
32+
}
33+
},
34+
35+
client: {
36+
qunit: {
37+
showUI: false
38+
}
39+
},
40+
41+
// test results reporter to use
42+
// possible values: 'dots', 'progress'
43+
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
44+
reporters: ['progress', 'coverage'],
45+
46+
// start these browsers
47+
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
48+
browsers: ['PhantomJS'],
49+
50+
// Continuous Integration mode
51+
// if true, Karma captures browsers, runs the tests and exits
52+
singleRun: true,
53+
54+
});
55+
};

karma.conf.js

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
// Karma configuration
2+
// Generated on Wed Jun 13 2018 14:38:44 GMT+0200 (CEST)
3+
4+
module.exports = function(config) {
5+
config.set({
6+
7+
// base path that will be used to resolve all patterns (eg. files, exclude)
8+
basePath: 'webapp',
9+
10+
// frameworks to use
11+
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
12+
frameworks: ['qunit', 'openui5'],
13+
14+
openui5: {
15+
path: 'http://localhost:8080/resources/sap-ui-core.js'
16+
},
17+
18+
client: {
19+
openui5: {
20+
config: {
21+
theme: 'sap_belize',
22+
language: 'EN',
23+
bindingSyntax: 'complex',
24+
compatVersion: 'edge',
25+
preload: 'async',
26+
resourceroots: {'sap.ui.demo.todo': './base'}
27+
},
28+
tests: [
29+
'sap/ui/demo/todo/test/unit/allTests',
30+
'sap/ui/demo/todo/test/integration/AllJourneys'
31+
]
32+
},
33+
clearContext: false,
34+
qunit: {
35+
showUI: true
36+
}
37+
},
38+
39+
// list of files / patterns to load in the browser
40+
files: [
41+
{ pattern: '**', included: false, served: true, watched: true }
42+
],
43+
44+
// test results reporter to use
45+
// possible values: 'dots', 'progress'
46+
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
47+
reporters: ['progress'],
48+
49+
// level of logging
50+
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
51+
logLevel: config.LOG_INFO,
52+
53+
// level of browser logging
54+
browserConsoleLogOptions: {
55+
level: 'warn'
56+
},
57+
58+
// enable / disable watching file and executing tests whenever any file changes
59+
autoWatch: true,
60+
61+
// start these browsers
62+
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
63+
browsers: ['Chrome'],
64+
65+
// Continuous Integration mode
66+
// if true, Karma captures browsers, runs the tests and exits
67+
singleRun: false,
68+
69+
});
70+
};

package.json

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,30 @@
44
"description": "Sample of an OpenUI5 app",
55
"private": true,
66
"scripts": {
7-
"start": "ui5 serve --open index.html",
8-
"opa5": "ui5 serve --open test/integration/opaTests.qunit.html",
9-
"qunit": "ui5 serve --open test/unit/unitTests.qunit.html"
7+
"start": "ui5 serve",
8+
"lint": "eslint webapp",
9+
"karma": "karma start",
10+
"karma-ci": "karma start karma-ci.conf.js",
11+
"watch": "start-server-and-test start http://localhost:8080 karma",
12+
"test": "npm run lint && rimraf coverage && start-server-and-test start http://localhost:8080 karma-ci",
13+
"build": "rimraf dist && ui5 build --a"
1014
},
1115
"dependencies": {
1216
"@openui5/sap.m": "^1.52.5",
1317
"@openui5/sap.ui.core": "^1.52.5",
1418
"@openui5/themelib_sap_belize": "^1.52.5"
1519
},
16-
"devDependencies": {}
20+
"devDependencies": {
21+
"@ui5/cli": "0.0.1",
22+
"eslint": "^4.19.1",
23+
"karma": "^2.0.2",
24+
"karma-chrome-launcher": "^2.2.0",
25+
"karma-coverage": "^1.1.2",
26+
"karma-openui5": "^0.2.3",
27+
"karma-phantomjs-launcher": "^1.0.4",
28+
"karma-qunit": "^1.2.1",
29+
"qunitjs": "^2.4.1",
30+
"rimraf": "^2.6.2",
31+
"start-server-and-test": "^1.4.1"
32+
}
1733
}

0 commit comments

Comments
 (0)