Skip to content

Commit 620c8ca

Browse files
authored
Re-enable coverage reporting for firebase-js-sdk (#9761)
1 parent 715c042 commit 620c8ca

File tree

4 files changed

+267
-4
lines changed

4 files changed

+267
-4
lines changed

.github/workflows/test-all.yml

Lines changed: 59 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,14 @@
1414

1515
name: Test All Packages
1616

17-
on: pull_request
17+
on:
18+
pull_request:
19+
push:
20+
branches:
21+
- main
22+
23+
permissions:
24+
contents: read
1825

1926
env:
2027
# make chromedriver detect installed Chrome version and download the corresponding driver
@@ -73,6 +80,7 @@ jobs:
7380
- name: install Chrome stable
7481
run: |
7582
npx @puppeteer/browsers install chrome@stable
83+
- uses: actions/checkout@v4
7684
- name: Download build archive
7785
uses: actions/download-artifact@v4
7886
with:
@@ -98,11 +106,27 @@ jobs:
98106
FIREBASE_TOKEN: ${{ secrets.FIREBASE_CLI_TOKEN }}
99107
- name: Generate coverage file
100108
run: yarn ci:coverage
109+
- name: Merge and fix coverage files for test-the-rest
110+
run: |
111+
# Clear out any existing master file just in case
112+
> ./lcov-all.info
113+
114+
# Find all LCOV files across all packages
115+
find ./packages -type f -name "lcov.info" | while read lcov_file; do
116+
# lcov_file looks like: ./packages/analytics/coverage/lcov.info
117+
# Extract the package name (the 3rd part of the path split by '/')
118+
PKG_NAME=$(echo "$lcov_file" | cut -d'/' -f3)
119+
120+
# Fix the path for this specific package and append it to the master file
121+
sed "s|SF:src/|SF:packages/$PKG_NAME/src/|g" "$lcov_file" >> ./lcov-all.info
122+
done
101123
- name: Run coverage
102124
uses: coverallsapp/github-action@master
103125
with:
104126
github-token: ${{ secrets.GITHUB_TOKEN }}
105127
path-to-lcov: ./lcov-all.info
128+
flag-name: test-the-rest-coverage
129+
parallel: true
106130
continue-on-error: true
107131

108132
test-auth:
@@ -120,6 +144,7 @@ jobs:
120144
echo "::warning ::${CHROME_VERSION_MISMATCH_MESSAGE}"
121145
echo "::warning ::Previously validated version: ${CHROME_VALIDATED_VERSION} vs. Installed version: $chromeVersionString"
122146
fi
147+
- uses: actions/checkout@v4
123148
- name: Download build archive
124149
uses: actions/download-artifact@v4
125150
with:
@@ -144,11 +169,20 @@ jobs:
144169
FIREBASE_TOKEN: ${{ secrets.FIREBASE_CLI_TOKEN }}
145170
- name: Generate coverage file
146171
run: yarn ci:coverage
172+
- name: Merge and fix coverage files for test-auth
173+
run: |
174+
# 1. Smash all Node and Browser coverage files into one giant file
175+
find ./packages/auth/coverage -type f -name "lcov.info" -exec cat {} + > ./lcov-all-auth.info
176+
177+
# 2. Fix standard Node paths
178+
sed -i 's|SF:src/|SF:packages/auth/src/|g' ./lcov-all-auth.info
147179
- name: Run coverage
148180
uses: coverallsapp/github-action@master
149181
with:
150182
github-token: ${{ secrets.GITHUB_TOKEN }}
151-
path-to-lcov: ./lcov-all.info
183+
path-to-lcov: ./lcov-all-auth.info
184+
flag-name: test-auth-coverage
185+
parallel: true
152186
continue-on-error: true
153187

154188
test-firestore:
@@ -160,6 +194,7 @@ jobs:
160194
- name: install Chrome stable
161195
run: |
162196
npx @puppeteer/browsers install chrome@stable
197+
- uses: actions/checkout@v4
163198
- name: Download build archive
164199
uses: actions/download-artifact@v4
165200
with:
@@ -184,11 +219,20 @@ jobs:
184219
EXPERIMENTAL_MODE: true
185220
- name: Generate coverage file
186221
run: yarn ci:coverage
222+
- name: Merge and fix coverage files for test-firestore
223+
run: |
224+
# 1. Smash all Node and Browser coverage files into one giant file
225+
find ./packages/firestore/coverage -type f -name "lcov.info" -exec cat {} + > ./lcov-all-firestore.info
226+
227+
# 2. Fix standard Node paths
228+
sed -i 's|SF:src/|SF:packages/firestore/src/|g' ./lcov-all-firestore.info
187229
- name: Run coverage
188230
uses: coverallsapp/github-action@master
189231
with:
190232
github-token: ${{ secrets.GITHUB_TOKEN }}
191-
path-to-lcov: ./lcov-all.info
233+
path-to-lcov: ./lcov-all-firestore.info
234+
flag-name: test-firestore-coverage
235+
parallel: true
192236
continue-on-error: true
193237
test-firestore-integration:
194238
strategy:
@@ -203,6 +247,7 @@ jobs:
203247
- name: install Chrome stable
204248
run: |
205249
npx @puppeteer/browsers install chrome@stable
250+
- uses: actions/checkout@v4
206251
- name: Download build archive
207252
uses: actions/download-artifact@v4
208253
with:
@@ -221,3 +266,14 @@ jobs:
221266
working-directory: integration/firestore
222267
env:
223268
FIREBASE_TOKEN: ${{ secrets.FIREBASE_CLI_TOKEN }}
269+
270+
coveralls-finish:
271+
name: Finalize Coveralls
272+
needs: [test-the-rest-coverage, test-auth-coverage, test-firestore-coverage]
273+
runs-on: ubuntu-latest
274+
steps:
275+
- name: Coveralls Finished
276+
uses: coverallsapp/github-action@master
277+
with:
278+
github-token: ${{ secrets.GITHUB_TOKEN }}
279+
parallel-finished: true

config/webpack.test.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,3 +112,29 @@ module.exports = {
112112
})
113113
]
114114
};
115+
116+
// If we are in a CI environment or a developer has explicity asked for coverage (e.g.
117+
// "COVERAGE=true yarn test:browser:unit"), add the babel-loader to instrument the code with
118+
// istanbul
119+
if (
120+
(process.env.CI && process.env.CI !== 'false') ||
121+
process.env.COVERAGE === 'true'
122+
) {
123+
module.exports.module.rules.push({
124+
test: /\.tsx?$/,
125+
// 'post' ensures this runs AFTER ts-loader converts TS to ES2020 JS
126+
enforce: 'post',
127+
use: {
128+
loader: 'babel-loader',
129+
options: {
130+
plugins: ['istanbul'] // Uses babel-plugin-istanbul to add coverage counters
131+
}
132+
},
133+
include: path.resolve(__dirname, '../packages'),
134+
exclude: [
135+
/node_modules/,
136+
/\.test\.tsx?$/, // Don't instrument the tests themselves
137+
/test\//
138+
]
139+
});
140+
}

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@
9393
"api-documenter-me": "0.1.1",
9494
"api-extractor-me": "0.1.2",
9595
"babel-loader": "8.4.1",
96+
"babel-plugin-istanbul": "7.0.1",
9697
"chai": "4.5.0",
9798
"chai-as-promised": "7.1.2",
9899
"chalk": "4.1.2",

0 commit comments

Comments
 (0)