Skip to content

Commit 98a34df

Browse files
committed
build: upload coverage to firebase
* Introduces a gulp task that will run on Travis Push builds and will upload coverage results to a Firebase database. Closes angular#128.
1 parent d78a370 commit 98a34df

File tree

7 files changed

+64
-4
lines changed

7 files changed

+64
-4
lines changed

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@
8484
"karma": "^1.5.0",
8585
"karma-browserstack-launcher": "^1.2.0",
8686
"karma-chrome-launcher": "^2.0.0",
87+
"karma-coverage": "^1.1.1",
8788
"karma-firefox-launcher": "^1.0.1",
8889
"karma-jasmine": "^1.1.0",
8990
"karma-sauce-launcher": "^1.1.0",

scripts/ci/build-and-test.sh

+7-1
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ source scripts/ci/sources/mode.sh
1111
source scripts/ci/sources/tunnel.sh
1212

1313
start_tunnel
14-
1514
wait_for_tunnel
15+
1616
if is_lint; then
1717
$(npm bin)/gulp ci:lint
1818
elif is_e2e; then
@@ -24,4 +24,10 @@ elif is_payload; then
2424
else
2525
$(npm bin)/gulp ci:test
2626
fi
27+
28+
# Don't upload coverage for both test modes (browserstack and saucelabs) and inside of PRs.
29+
if [[ "$MODE" == "saucelabs_required" ]] && [ "$TRAVIS_PULL_REQUEST" = "false" ]; then
30+
$(npm bin)/gulp ci:coverage
31+
fi
32+
2733
teardown_tunnel

test/karma.conf.js

+16-3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ module.exports = (config) => {
1212
require('karma-sauce-launcher'),
1313
require('karma-chrome-launcher'),
1414
require('karma-firefox-launcher'),
15-
require('karma-sourcemap-loader')
15+
require('karma-sourcemap-loader'),
16+
require('karma-coverage')
1617
],
1718
files: [
1819
{pattern: 'dist/vendor/core-js/client/core.js', included: true, watched: false},
@@ -50,16 +51,23 @@ module.exports = (config) => {
5051

5152
customLaunchers: customLaunchers,
5253

53-
exclude: [],
5454
preprocessors: {
55-
'**/*.js': ['sourcemap']
55+
'dist/@angular/material/**/*.js': ['sourcemap']
5656
},
57+
5758
reporters: ['dots'],
59+
5860
port: 9876,
5961
colors: true,
6062
logLevel: config.LOG_INFO,
6163
autoWatch: false,
6264

65+
coverageReporter: {
66+
type : 'json-summary',
67+
dir : 'dist/coverage/',
68+
subdir: '.'
69+
},
70+
6371
sauceLabs: {
6472
testName: 'material2',
6573
startConnect: false,
@@ -92,6 +100,11 @@ module.exports = (config) => {
92100
if (process.env['TRAVIS']) {
93101
let buildId = `TRAVIS #${process.env.TRAVIS_BUILD_NUMBER} (${process.env.TRAVIS_BUILD_ID})`;
94102

103+
if (process.env['TRAVIS_PULL_REQUEST'] === 'false') {
104+
config.preprocessors['dist/@angular/material/**/!(*+(.|-)spec).js'] = ['coverage'];
105+
config.reporters.push('coverage');
106+
}
107+
95108
// The MODE variable is the indicator of what row in the test matrix we're running.
96109
// It will look like <platform>_<alias>, where platform is one of 'saucelabs' or 'browserstack',
97110
// and alias is one of the keys in the CI configuration variable declared in

tools/gulp/constants.ts

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ export const SOURCE_ROOT = join(PROJECT_ROOT, 'src');
88
export const DIST_ROOT = join(PROJECT_ROOT, 'dist');
99
export const DIST_COMPONENTS_ROOT = join(DIST_ROOT, '@angular/material');
1010

11+
export const COVERAGE_RESULT_FILE = join(DIST_ROOT, 'coverage', 'coverage-summary.json');
12+
1113
export const SASS_AUTOPREFIXER_OPTIONS = {
1214
browsers: [
1315
'last 2 versions',

tools/gulp/gulpfile.ts

+1
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ import './tasks/unit-test';
1313
import './tasks/docs';
1414
import './tasks/aot';
1515
import './tasks/payload';
16+
import './tasks/coverage';

tools/gulp/tasks/ci.ts

+3
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,6 @@ task('ci:aot', ['aot:build']);
1717

1818
/** Task which reports the size of the library and stores it in a database. */
1919
task('ci:payload', ['payload']);
20+
21+
/** Task that uploads the coverage results to a firebase database. */
22+
task('ci:coverage', ['coverage:upload']);

tools/gulp/tasks/coverage.ts

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import {task} from 'gulp';
2+
import {existsSync} from 'fs-extra';
3+
import {COVERAGE_RESULT_FILE} from '../constants';
4+
import {spawnSync} from 'child_process';
5+
import {isTravisPushBuild, openFirebaseDashboardDatabase} from '../task_helpers';
6+
7+
task('coverage:upload', () => {
8+
if (!existsSync(COVERAGE_RESULT_FILE)) {
9+
throw new Error('No coverage file has been found!');
10+
}
11+
12+
if (!isTravisPushBuild()) {
13+
throw new Error('Coverage results will be only uploaded inside of Travis Push builds.');
14+
}
15+
16+
let results = require(COVERAGE_RESULT_FILE)['total'];
17+
18+
// To reduce database payload, the covered lines won't be pushed to the Firebase database.
19+
delete results['linesCovered'];
20+
21+
return uploadResults(results);
22+
});
23+
24+
/** Uploads the coverage results to the firebase database. */
25+
function uploadResults(results: any): Promise<void> {
26+
let latestSha = spawnSync('git', ['rev-parse', 'HEAD']).stdout.toString().trim();
27+
let database = openFirebaseDashboardDatabase();
28+
29+
return database.ref('coverage-reports').child(latestSha).set(results)
30+
.then(() => database.goOffline(), () => database.goOffline());
31+
}
32+
33+
// TODO(devversion): In the future we might have a big database where we can store full summaries.
34+
// TODO(devversion): We could also move the coverage to a bot and reply with the results on PRs.

0 commit comments

Comments
 (0)