Skip to content

Commit 524031d

Browse files
committed
Run tests in browser using Karma
1 parent c123e1e commit 524031d

File tree

2 files changed

+98
-2
lines changed

2 files changed

+98
-2
lines changed

karma.conf.js

+90
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
/*!
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
// Use Chrome executable installed through npm
21+
process.env.CHROME_BIN = require('puppeteer').executablePath();
22+
23+
module.exports = function (config) {
24+
config.set({
25+
26+
// base path that will be used to resolve all patterns (eg. files, exclude)
27+
basePath: '',
28+
29+
// frameworks to use
30+
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
31+
frameworks: ['jasmine'],
32+
33+
// list of files / patterns to load in the browser
34+
files: [
35+
'pkg/cordova.test.js',
36+
'test/**/test.*.js'
37+
],
38+
39+
// list of files / patterns to exclude
40+
exclude: [
41+
],
42+
43+
// preprocess matching files before serving them to the browser
44+
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
45+
preprocessors: {
46+
},
47+
48+
// test results reporter to use
49+
// possible values: 'dots', 'progress'
50+
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
51+
reporters: ['progress'],
52+
53+
// web server port
54+
port: 9876,
55+
56+
// enable / disable colors in the output (reporters and logs)
57+
colors: true,
58+
59+
// level of logging
60+
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
61+
logLevel: config.LOG_INFO,
62+
63+
// enable / disable watching file and executing tests whenever any file changes
64+
autoWatch: false,
65+
66+
// start these browsers
67+
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
68+
browsers: ['ChromeHeadless'],
69+
70+
// Continuous Integration mode
71+
// if true, Karma captures browsers, runs the tests and exits
72+
singleRun: true,
73+
74+
// Concurrency level
75+
// how many browser should be started simultaneous
76+
concurrency: Infinity
77+
});
78+
79+
if (process.env.TRAVIS) {
80+
config.set({
81+
browsers: ['ChromeHeadlessNoSandbox'],
82+
customLaunchers: {
83+
ChromeHeadlessNoSandbox: {
84+
base: 'ChromeHeadless',
85+
flags: ['--no-sandbox']
86+
}
87+
}
88+
});
89+
}
90+
};

package.json

+8-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
},
1717
"scripts": {
1818
"eslint": "eslint src test pkg",
19-
"test": "grunt test && npm run eslint",
19+
"pretest": "grunt compile:test",
20+
"test": "npm run eslint && karma start",
2021
"build": "grunt compile"
2122
},
2223
"license": "Apache-2.0",
@@ -78,9 +79,14 @@
7879
"grunt": "^1.0.1",
7980
"grunt-contrib-clean": "^1.0.0",
8081
"istanbul": "^0.4.5",
82+
"jasmine-core": "^3.2.1",
8183
"jasmine-node": "^1.14.6",
8284
"jsdom-no-contextify": "^3.1.0",
83-
"mkdirp": "^0.5.0"
85+
"karma": "^3.0.0",
86+
"karma-chrome-launcher": "^2.2.0",
87+
"karma-jasmine": "^1.1.2",
88+
"mkdirp": "^0.5.0",
89+
"puppeteer": "^1.8.0"
8490
},
8591
"cordova-platforms": {
8692
"cordova-android": "../cordova-android",

0 commit comments

Comments
 (0)