Skip to content

Commit 7db74e6

Browse files
authored
Instrument Repo for Code Coverage (#268)
* First pass coverage implementation * Instrumenting node coverage where appropriate * [AUTOMATED]: Prettier Code Styling * Configure to pipe to coveralls * Configure karma to report coverage by browser * Augment .travis.yml to report coverage * Refacor .travis.yml to use yarn for consistency * Refactor to properly use lcovonly reporter * Refactor to run coverage scripts only on success * [AUTOMATED]: Prettier Code Styling
1 parent c5e318c commit 7db74e6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+1165
-929
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,7 @@ dist
1414
.idea
1515
.vscode
1616
*.iml
17+
18+
# Coverage
19+
.nyc_output
20+
coverage

.travis.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ before_install:
1414
before_script:
1515
- cp config/ci.config.json config/project.json
1616
script:
17-
- xvfb-run npm test
17+
- xvfb-run yarn test
18+
after_success:
19+
- yarn test:coverage
1820

1921
# Misc Addons/Configs
2022
dist: trusty

config/karma.base.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ const config = {
6666
// test results reporter to use
6767
// possible values: 'dots', 'progress'
6868
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
69-
reporters: ['spec' /*, 'saucelabs' */],
69+
reporters: ['spec', 'coverage-istanbul' /*, 'saucelabs' */],
7070

7171
// web server port
7272
port: 8089,
@@ -113,6 +113,12 @@ const config = {
113113

114114
// Pass through --grep option to filter the tests that run.
115115
args: argv.grep ? ['--grep', argv.grep] : []
116+
},
117+
118+
coverageIstanbulReporter: {
119+
dir: path.resolve(process.cwd(), 'coverage/browser/%browser%'),
120+
fixWebpackSourcePaths: true,
121+
reports: ['lcovonly']
116122
}
117123
};
118124

config/webpack.test.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const path = require('path');
1818
const webpack = require('webpack');
1919

2020
module.exports = {
21-
devtool: 'eval-source-map',
21+
devtool: 'source-map',
2222
module: {
2323
rules: [
2424
{
@@ -27,9 +27,18 @@ module.exports = {
2727
use: 'ts-loader'
2828
},
2929
{
30-
test: /\.js$/,
31-
use: ['source-map-loader'],
30+
test: /\.[tj]sx?$/,
31+
use: 'source-map-loader',
3232
enforce: 'pre'
33+
},
34+
{
35+
test: /\.tsx?$/,
36+
use: {
37+
loader: 'istanbul-instrumenter-loader',
38+
options: { esModules: true }
39+
},
40+
enforce: 'post',
41+
include: path.resolve(process.cwd(), 'src')
3342
}
3443
]
3544
},

integration/firestore/gulpfile.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ function reworkFirebasePaths() {
3636
/**
3737
* This regex is designed to match the following statement used in our
3838
* firestore integratino test suites:
39-
*
39+
*
4040
* import firebase from '../../util/firebase_export';
41-
*
41+
*
4242
* It will handle variations in whitespace, single/double quote
4343
* differences, as well as different paths to a valid firebase_export
4444
*/

integration/shared/validator.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ function validateNamespace(definition, candidate) {
4343
const candidateChunk = candidate[key];
4444

4545
/**
46-
* Grab all of the keys that aren't meta properties and capture
46+
* Grab all of the keys that aren't meta properties and capture
4747
* them for more testing later
4848
*/
4949
const internalKeys = Object.keys(definitionChunk).filter(
@@ -72,16 +72,16 @@ function validateNamespace(definition, candidate) {
7272
}
7373

7474
/**
75-
* Keys marked with `__return` allow us to validate the
75+
* Keys marked with `__return` allow us to validate the
7676
* return value of a specific part of the API
77-
*
77+
*
7878
* e.g.
7979
* {
8080
* ...
8181
* app: {
8282
* __return: {
8383
* <PROPERTIES OF AN APP>
84-
* }
84+
* }
8585
* }
8686
* }
8787
*/

package.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
"repl": "node tools/repl.js",
2424
"pretest": "node tools/pretest.js",
2525
"test": "lerna run --parallel test",
26+
"pretest:coverage": "mkdirp coverage",
27+
"test:coverage": "lcov-result-merger 'packages/**/lcov.info' | coveralls",
2628
"test:setup": "node tools/config.js"
2729
},
2830
"repository": {
@@ -36,14 +38,18 @@
3638
"devDependencies": {
3739
"chalk": "^2.3.0",
3840
"child-process-promise": "^2.2.1",
41+
"coveralls": "^3.0.0",
3942
"firebase-tools": "^3.10.1",
4043
"glob": "^7.1.2",
4144
"gulp-sourcemaps": "^2.6.1",
4245
"gulp-typescript": "^3.2.3",
4346
"husky": "^0.14.3",
4447
"inquirer": "^3.2.3",
48+
"istanbul-instrumenter-loader": "^3.0.0",
49+
"lcov-result-merger": "^1.2.0",
4550
"lerna": "^2.1.0",
4651
"merge2": "^1.2.0",
52+
"mkdirp": "^0.5.1",
4753
"mz": "^2.7.0",
4854
"ora": "^1.3.0",
4955
"prettier": "^1.7.0",

packages/app/package.json

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
"dev": "gulp dev",
99
"test": "run-p test:browser test:node",
1010
"test:browser": "karma start --single-run",
11-
"test:node": "mocha test/**/*.test.* --compilers ts:ts-node/register --exit",
11+
"test:browser:debug": "karma start --browsers Chrome --auto-watch",
12+
"test:node": "nyc --reporter lcovonly -- mocha test/**/*.test.* --compilers ts:ts-node/register --exit",
1213
"prepare": "gulp build"
1314
},
1415
"license": "Apache-2.0",
@@ -26,13 +27,15 @@
2627
"karma": "^1.7.0",
2728
"karma-chrome-launcher": "^2.2.0",
2829
"karma-cli": "^1.0.1",
30+
"karma-coverage-istanbul-reporter": "^1.3.0",
2931
"karma-mocha": "^1.3.0",
3032
"karma-sauce-launcher": "^1.2.0",
3133
"karma-sourcemap-loader": "^0.3.7",
3234
"karma-spec-reporter": "^0.0.31",
3335
"karma-webpack": "^2.0.4",
3436
"mocha": "^4.0.1",
3537
"npm-run-all": "^4.1.1",
38+
"nyc": "^11.2.1",
3639
"sinon": "^4.0.2",
3740
"source-map-loader": "^0.2.3",
3841
"ts-loader": "^3.1.0",
@@ -47,5 +50,11 @@
4750
"bugs": {
4851
"url": "https://github.com/firebase/firebase-js-sdk/issues"
4952
},
50-
"typings": "dist/index.d.ts"
53+
"typings": "dist/index.d.ts",
54+
"nyc": {
55+
"extension": [
56+
".ts"
57+
],
58+
"reportDir": "./coverage/node"
59+
}
5160
}

packages/app/src/firebaseApp.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -312,14 +312,14 @@ class FirebaseAppImpl implements FirebaseApp {
312312
/**
313313
* Return a service instance associated with this app (creating it
314314
* on demand), identified by the passed instanceIdentifier.
315-
*
315+
*
316316
* NOTE: Currently storage is the only one that is leveraging this
317317
* functionality. They invoke it by calling:
318-
*
318+
*
319319
* ```javascript
320320
* firebase.app().storage('STORAGE BUCKET ID')
321321
* ```
322-
*
322+
*
323323
* The service name is passed to this already
324324
* @internal
325325
*/
@@ -364,10 +364,10 @@ class FirebaseAppImpl implements FirebaseApp {
364364
/**
365365
* If the app has overwritten the addAuthTokenListener stub, forward
366366
* the active token listeners on to the true fxn.
367-
*
367+
*
368368
* TODO: This function is required due to our current module
369369
* structure. Once we are able to rely strictly upon a single module
370-
* implementation, this code should be refactored and Auth should
370+
* implementation, this code should be refactored and Auth should
371371
* provide these stubs and the upgrade logic
372372
*/
373373
if (props.INTERNAL && props.INTERNAL.addAuthTokenListener) {

packages/app/test/firebaseApp.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -351,8 +351,7 @@ describe('Firebase App Class', () => {
351351
(app2 as any).test();
352352
// Confirm extended INTERNAL getToken resolve with the corresponding
353353
// service's value.
354-
return app.INTERNAL
355-
.getToken()
354+
return app.INTERNAL.getToken()
356355
.then(token => {
357356
assert.equal('tokenFor0', token.accessToken);
358357
return app2.INTERNAL.getToken();

packages/database/index.node.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ import './src/nodePatches';
2828
/**
2929
* A one off register function which returns a database based on the app and
3030
* passed database URL.
31-
*
31+
*
3232
* @param app A valid FirebaseApp-like object
33-
* @param url A valid Firebase databaseURL
33+
* @param url A valid Firebase databaseURL
3434
*/
3535

3636
const ServerValue = Database.ServerValue;

packages/database/package.json

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"dev": "gulp dev",
1010
"test": "run-p test:browser test:node",
1111
"test:browser": "karma start --single-run",
12-
"test:node": "mocha 'test/{,!(browser)/**/}*.test.ts' --compilers ts:ts-node/register -r src/nodePatches.ts --retries 5 --timeout 5000 --exit",
12+
"test:node": "nyc --reporter lcovonly -- mocha 'test/{,!(browser)/**/}*.test.ts' --compilers ts:ts-node/register -r src/nodePatches.ts --retries 5 --timeout 5000 --exit",
1313
"prepare": "gulp build"
1414
},
1515
"license": "Apache-2.0",
@@ -37,6 +37,7 @@
3737
"karma-webpack": "^2.0.4",
3838
"mocha": "^4.0.1",
3939
"npm-run-all": "^4.1.1",
40+
"nyc": "^11.2.1",
4041
"sinon": "^4.0.2",
4142
"source-map-loader": "^0.2.3",
4243
"ts-loader": "^3.1.0",
@@ -51,5 +52,11 @@
5152
"bugs": {
5253
"url": "https://github.com/firebase/firebase-js-sdk/issues"
5354
},
54-
"typings": "dist/cjs/index.d.ts"
55+
"typings": "dist/cjs/index.d.ts",
56+
"nyc": {
57+
"extension": [
58+
".ts"
59+
],
60+
"reportDir": "./coverage/node"
61+
}
5562
}

packages/database/src/core/SyncTree.ts

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -546,24 +546,24 @@ export class SyncTree {
546546
private collectDistinctViewsForSubTree_(
547547
subtree: ImmutableTree<SyncPoint>
548548
): View[] {
549-
return subtree.fold<
550-
View[]
551-
>((relativePath, maybeChildSyncPoint, childMap) => {
552-
if (maybeChildSyncPoint && maybeChildSyncPoint.hasCompleteView()) {
553-
const completeView = maybeChildSyncPoint.getCompleteView();
554-
return [completeView];
555-
} else {
556-
// No complete view here, flatten any deeper listens into an array
557-
let views: View[] = [];
558-
if (maybeChildSyncPoint) {
559-
views = maybeChildSyncPoint.getQueryViews();
549+
return subtree.fold<View[]>(
550+
(relativePath, maybeChildSyncPoint, childMap) => {
551+
if (maybeChildSyncPoint && maybeChildSyncPoint.hasCompleteView()) {
552+
const completeView = maybeChildSyncPoint.getCompleteView();
553+
return [completeView];
554+
} else {
555+
// No complete view here, flatten any deeper listens into an array
556+
let views: View[] = [];
557+
if (maybeChildSyncPoint) {
558+
views = maybeChildSyncPoint.getQueryViews();
559+
}
560+
forEach(childMap, function(key: string, childViews: View[]) {
561+
views = views.concat(childViews);
562+
});
563+
return views;
560564
}
561-
forEach(childMap, function(key: string, childViews: View[]) {
562-
views = views.concat(childViews);
563-
});
564-
return views;
565565
}
566-
});
566+
);
567567
}
568568

569569
/**

packages/database/src/core/snap/LeafNode.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,10 @@ export class LeafNode implements Node {
121121
} else if (newChildNode.isEmpty() && childName !== '.priority') {
122122
return this;
123123
} else {
124-
return LeafNode.__childrenNodeConstructor.EMPTY_NODE
125-
.updateImmediateChild(childName, newChildNode)
126-
.updatePriority(this.priorityNode_);
124+
return LeafNode.__childrenNodeConstructor.EMPTY_NODE.updateImmediateChild(
125+
childName,
126+
newChildNode
127+
).updatePriority(this.priorityNode_);
127128
}
128129
}
129130

packages/database/src/core/snap/childSet.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ export const buildChildSet = function<K, V>(
8686
return null;
8787
} else if (length == 1) {
8888
namedNode = childList[low];
89-
key = keyFn ? keyFn(namedNode) : (namedNode as any) as K;
89+
key = keyFn ? keyFn(namedNode) : ((namedNode as any) as K);
9090
return new LLRBNode(
9191
key,
9292
(namedNode.node as any) as V,
@@ -99,7 +99,7 @@ export const buildChildSet = function<K, V>(
9999
const left = buildBalancedTree(low, middle);
100100
const right = buildBalancedTree(middle + 1, high);
101101
namedNode = childList[middle];
102-
key = keyFn ? keyFn(namedNode) : (namedNode as any) as K;
102+
key = keyFn ? keyFn(namedNode) : ((namedNode as any) as K);
103103
return new LLRBNode(
104104
key,
105105
(namedNode.node as any) as V,
@@ -121,7 +121,7 @@ export const buildChildSet = function<K, V>(
121121
index -= chunkSize;
122122
const childTree = buildBalancedTree(low + 1, high);
123123
const namedNode = childList[low];
124-
const key: K = keyFn ? keyFn(namedNode) : (namedNode as any) as K;
124+
const key: K = keyFn ? keyFn(namedNode) : ((namedNode as any) as K);
125125
attachPennant(
126126
new LLRBNode(key, (namedNode.node as any) as V, color, null, childTree)
127127
);

packages/database/src/core/util/CountedSet.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export class CountedSet<K, V> {
2929
* @param {V} val
3030
*/
3131
add(item: K, val: V) {
32-
this.set[item as any] = val !== null ? val : true as any;
32+
this.set[item as any] = val !== null ? val : (true as any);
3333
}
3434

3535
/**

packages/database/src/core/util/SortedMap.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,9 @@ export class LLRBNode<K, V> {
157157
) {
158158
this.color = color != null ? color : LLRBNode.RED;
159159
this.left =
160-
left != null ? left : SortedMap.EMPTY_NODE as LLRBEmptyNode<K, V>;
160+
left != null ? left : (SortedMap.EMPTY_NODE as LLRBEmptyNode<K, V>);
161161
this.right =
162-
right != null ? right : SortedMap.EMPTY_NODE as LLRBEmptyNode<K, V>;
162+
right != null ? right : (SortedMap.EMPTY_NODE as LLRBEmptyNode<K, V>);
163163
}
164164

165165
static RED = true;

packages/database/src/core/view/filter/LimitedFilter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ export class LimitedFilter implements NodeFilter {
270270
const newChildNamedNode = new NamedNode(childKey, childSnap);
271271
const windowBoundary = this.reverse_
272272
? oldEventCache.getFirstChild(this.index_)
273-
: oldEventCache.getLastChild(this.index_) as NamedNode;
273+
: (oldEventCache.getLastChild(this.index_) as NamedNode);
274274
const inRange = this.rangedFilter_.matches(newChildNamedNode);
275275
if (oldEventCache.hasChild(childKey)) {
276276
const oldChildSnap = oldEventCache.getImmediateChild(childKey);

packages/database/src/realtime/WebSocketConnection.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,9 @@ export class WebSocketConnection implements Transport {
149149
// UA Format: Firebase/<wire_protocol>/<sdk_version>/<platform>/<device>
150150
const options: { [k: string]: object } = {
151151
headers: {
152-
'User-Agent': `Firebase/${PROTOCOL_VERSION}/${firebase.SDK_VERSION}/${process.platform}/${device}`
152+
'User-Agent': `Firebase/${PROTOCOL_VERSION}/${
153+
firebase.SDK_VERSION
154+
}/${process.platform}/${device}`
153155
}
154156
};
155157

packages/database/test/query.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ describe('Query Tests', function() {
8383
/**
8484
* Because we are testing invalid queries, I am casting
8585
* to `any` to avoid the typechecking error. This can
86-
* occur when a user uses the SDK through a pure JS
86+
* occur when a user uses the SDK through a pure JS
8787
* client, rather than typescript
8888
*/
8989
expect(function() {

0 commit comments

Comments
 (0)