react-native-coverage 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Coverage.podspec +20 -0
- package/LICENSE +202 -0
- package/README.md +125 -0
- package/android/build.gradle +51 -0
- package/android/rn-coverage-jacoco.gradle +132 -0
- package/android/rn-coverage.gradle +68 -0
- package/android/src/main/AndroidManifest.xml +2 -0
- package/android/src/main/java/com/coverage/CoverageModule.kt +53 -0
- package/android/src/main/java/com/coverage/CoveragePackage.kt +35 -0
- package/app.plugin.js +1 -0
- package/bin/rn-coverage.js +11 -0
- package/cocoapods/coverage_post_install.rb +197 -0
- package/docs/cli.md +51 -0
- package/docs/config.md +27 -0
- package/docs/index.md +16 -0
- package/docs/integration/android.md +83 -0
- package/docs/integration/ci-appium.md +41 -0
- package/docs/integration/e2e-timing.md +20 -0
- package/docs/integration/ios.md +77 -0
- package/docs/integration/js.md +38 -0
- package/docs/pattern-c.md +5 -0
- package/docs/releasing.md +88 -0
- package/docs.json +24 -0
- package/ios/Coverage.h +5 -0
- package/ios/Coverage.mm +47 -0
- package/ios/CoverageConfig.h +21 -0
- package/ios/CoverageProfile.h +22 -0
- package/ios/CoverageProfile.mm +358 -0
- package/lib/module/NativeCoverage.js +10 -0
- package/lib/module/NativeCoverage.js.map +1 -0
- package/lib/module/assert-coverage.js +181 -0
- package/lib/module/assert-coverage.js.map +1 -0
- package/lib/module/cli/index.js +229 -0
- package/lib/module/cli/index.js.map +1 -0
- package/lib/module/config.js +83 -0
- package/lib/module/config.js.map +1 -0
- package/lib/module/exit-codes.js +22 -0
- package/lib/module/exit-codes.js.map +1 -0
- package/lib/module/index.js +35 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/js-coverage.js +172 -0
- package/lib/module/js-coverage.js.map +1 -0
- package/lib/module/node.js +15 -0
- package/lib/module/node.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/module/path-rewrite.js +44 -0
- package/lib/module/path-rewrite.js.map +1 -0
- package/lib/module/process-ios-native-coverage.js +258 -0
- package/lib/module/process-ios-native-coverage.js.map +1 -0
- package/lib/module/pull-native-coverage.js +210 -0
- package/lib/module/pull-native-coverage.js.map +1 -0
- package/lib/typescript/example-dynamic/App.d.ts +6 -0
- package/lib/typescript/example-dynamic/App.d.ts.map +1 -0
- package/lib/typescript/package.json +1 -0
- package/lib/typescript/src/NativeCoverage.d.ts +16 -0
- package/lib/typescript/src/NativeCoverage.d.ts.map +1 -0
- package/lib/typescript/src/assert-coverage.d.ts +53 -0
- package/lib/typescript/src/assert-coverage.d.ts.map +1 -0
- package/lib/typescript/src/cli/index.d.ts +4 -0
- package/lib/typescript/src/cli/index.d.ts.map +1 -0
- package/lib/typescript/src/config.d.ts +93 -0
- package/lib/typescript/src/config.d.ts.map +1 -0
- package/lib/typescript/src/exit-codes.d.ts +16 -0
- package/lib/typescript/src/exit-codes.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +16 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/lib/typescript/src/js-coverage.d.ts +36 -0
- package/lib/typescript/src/js-coverage.d.ts.map +1 -0
- package/lib/typescript/src/node.d.ts +14 -0
- package/lib/typescript/src/node.d.ts.map +1 -0
- package/lib/typescript/src/path-rewrite.d.ts +12 -0
- package/lib/typescript/src/path-rewrite.d.ts.map +1 -0
- package/lib/typescript/src/process-ios-native-coverage.d.ts +61 -0
- package/lib/typescript/src/process-ios-native-coverage.d.ts.map +1 -0
- package/lib/typescript/src/pull-native-coverage.d.ts +38 -0
- package/lib/typescript/src/pull-native-coverage.d.ts.map +1 -0
- package/package.json +184 -0
- package/plugin/build/index.d.ts +21 -0
- package/plugin/build/index.js +153 -0
- package/react-native-coverage.config.js.example +47 -0
- package/react-native.config.js +9 -0
- package/src/NativeCoverage.ts +16 -0
- package/src/assert-coverage.ts +260 -0
- package/src/cli/index.ts +420 -0
- package/src/config.ts +189 -0
- package/src/exit-codes.ts +20 -0
- package/src/index.tsx +35 -0
- package/src/js-coverage.ts +213 -0
- package/src/node.ts +52 -0
- package/src/path-rewrite.ts +52 -0
- package/src/process-ios-native-coverage.ts +425 -0
- package/src/pull-native-coverage.ts +269 -0
package/Coverage.podspec
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
require "json"
|
|
2
|
+
|
|
3
|
+
package = JSON.parse(File.read(File.join(__dir__, "package.json")))
|
|
4
|
+
|
|
5
|
+
Pod::Spec.new do |s|
|
|
6
|
+
s.name = "Coverage"
|
|
7
|
+
s.version = package["version"]
|
|
8
|
+
s.summary = package["description"]
|
|
9
|
+
s.homepage = package["homepage"]
|
|
10
|
+
s.license = package["license"]
|
|
11
|
+
s.authors = package["author"]
|
|
12
|
+
|
|
13
|
+
s.platforms = { :ios => min_ios_version_supported }
|
|
14
|
+
s.source = { :git => "https://github.com/invertase/react-native-coverage.git", :tag => "#{s.version}" }
|
|
15
|
+
|
|
16
|
+
s.source_files = "ios/**/*.{h,m,mm,swift,cpp}"
|
|
17
|
+
s.private_header_files = "ios/**/*.h"
|
|
18
|
+
|
|
19
|
+
install_modules_dependencies(s)
|
|
20
|
+
end
|
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
# react-native-coverage
|
|
2
|
+
|
|
3
|
+
**Testing is the backpressure you need in this brave agentic future.**
|
|
4
|
+
Coverage is the evidence so agents do not hand-wave past the testing.
|
|
5
|
+
You found the module for **integrated native coverage proof on iOS and Android**.
|
|
6
|
+
|
|
7
|
+
TurboModule flush → pull/export → LCOV/Jacoco reports → `assert` in CI.
|
|
8
|
+
Dedicated **test / e2e harness apps only** (Pattern C). New Architecture only.
|
|
9
|
+
|
|
10
|
+
> Not for production product apps. Put this in your harness workspace, not the shipping `package.json`.
|
|
11
|
+
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
## Have your agent wire it up
|
|
15
|
+
|
|
16
|
+
Paste this into your coding agent (Cursor, Claude, Codex, etc.) **before** you touch Gradle or Podfiles by hand:
|
|
17
|
+
|
|
18
|
+
```text
|
|
19
|
+
Integrate react-native-coverage into this repo's dedicated React Native test /
|
|
20
|
+
e2e harness app only (Pattern C — never the production app package.json).
|
|
21
|
+
|
|
22
|
+
Constraints:
|
|
23
|
+
- New Architecture / TurboModule only
|
|
24
|
+
- Follow https://github.com/invertase/react-native-coverage and docs under docs/
|
|
25
|
+
- Prefer the Expo config plugin when the harness is Expo; otherwise use the bare
|
|
26
|
+
Gradle + CocoaPods Ruby helpers from docs/integration/
|
|
27
|
+
- Wire libraryProjectMatchers / frameworkNamePrefixes for every native library
|
|
28
|
+
we need hits from
|
|
29
|
+
- Add CI steps that pull coverage and fail with rn-coverage assert (or equivalent)
|
|
30
|
+
when hits are empty (exit 2)
|
|
31
|
+
- Do not invent product-app install paths; keep the package out of the shipping app
|
|
32
|
+
|
|
33
|
+
After install: yarn/npm add react-native-coverage in the harness, apply plugin or
|
|
34
|
+
manual hooks, prebuild/pod install as needed, then show me the exact CI commands
|
|
35
|
+
to run and what green looks like.
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Then install in the **harness** (not the product app):
|
|
39
|
+
|
|
40
|
+
```sh
|
|
41
|
+
yarn add react-native-coverage
|
|
42
|
+
# or: npm install react-native-coverage
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
Expo harness — add the plugin (see [Android](./docs/integration/android.md) / [iOS](./docs/integration/ios.md) for options):
|
|
46
|
+
|
|
47
|
+
```json
|
|
48
|
+
{
|
|
49
|
+
"expo": {
|
|
50
|
+
"plugins": [
|
|
51
|
+
[
|
|
52
|
+
"react-native-coverage",
|
|
53
|
+
{
|
|
54
|
+
"libraryProjectMatchers": ["my-native-lib"],
|
|
55
|
+
"frameworkNamePrefixes": ["MyLib"],
|
|
56
|
+
"enableAndroidCoverage": true,
|
|
57
|
+
"forceDynamicFrameworks": false
|
|
58
|
+
}
|
|
59
|
+
]
|
|
60
|
+
]
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
```sh
|
|
66
|
+
npx expo prebuild
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
Bare RN: apply `android/rn-coverage*.gradle` and `cocoapods/coverage_post_install.rb` as documented. Copy `react-native-coverage.config.js.example` if you need host-specific paths.
|
|
70
|
+
|
|
71
|
+
**Prove it in CI** (empty hits must fail):
|
|
72
|
+
|
|
73
|
+
```sh
|
|
74
|
+
rn-coverage android pull && rn-coverage android report
|
|
75
|
+
rn-coverage ios pull && rn-coverage ios export && rn-coverage ios report
|
|
76
|
+
rn-coverage assert # exit 2 when coverage is empty — that is the point
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
Full CLI surface: [docs/cli.md](./docs/cli.md).
|
|
80
|
+
|
|
81
|
+
---
|
|
82
|
+
|
|
83
|
+
## What you get
|
|
84
|
+
|
|
85
|
+
| Piece | Role |
|
|
86
|
+
|-------|------|
|
|
87
|
+
| **TurboModule** | iOS LINKEDIT flush + Android Emma dump from the running app |
|
|
88
|
+
| **CLI (`rn-coverage`)** | `android pull\|report`, `ios pull\|export\|report\|summary`, `assert` |
|
|
89
|
+
| **Expo config plugin** | Gradle helpers + Podfile helper call (safe split) |
|
|
90
|
+
| **CocoaPods Ruby helper** | Pod LLVM flags + optional dynamic-framework restore |
|
|
91
|
+
| **Gradle Jacoco helpers** | `android/rn-coverage.gradle` + `android/rn-coverage-jacoco.gradle` |
|
|
92
|
+
|
|
93
|
+
Docs: [docs/](./docs/index.md) · Pattern C · Android · iOS · Config · [Releasing](./docs/releasing.md)
|
|
94
|
+
|
|
95
|
+
---
|
|
96
|
+
|
|
97
|
+
## Example / CI cells
|
|
98
|
+
|
|
99
|
+
This repo's `example/` (Expo) and `example-dynamic/` (bare, dynamic frameworks) are the harness. **Appium** (WebDriverIO) on every PR:
|
|
100
|
+
|
|
101
|
+
| Cell | Path | Notes |
|
|
102
|
+
|------|------|-------|
|
|
103
|
+
| iOS **dynamic** (primary) | `example-dynamic/` | Non-zero fixture LCOV gate |
|
|
104
|
+
| iOS **static** | `example/` | Expo staticlib merge; fixture hits still asserted |
|
|
105
|
+
| Android | `example/` | Jacoco + Appium |
|
|
106
|
+
|
|
107
|
+
```sh
|
|
108
|
+
yarn
|
|
109
|
+
yarn prepare
|
|
110
|
+
yarn test
|
|
111
|
+
yarn e2e:ios:dynamic
|
|
112
|
+
yarn e2e:ios:static
|
|
113
|
+
yarn e2e:android
|
|
114
|
+
node bin/rn-coverage.js --help
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
---
|
|
118
|
+
|
|
119
|
+
## Releasing
|
|
120
|
+
|
|
121
|
+
Conventional Commits + semantic-release; **manual** `workflow_dispatch` only (no push-to-main publish). Operator steps: [docs/releasing.md](./docs/releasing.md).
|
|
122
|
+
|
|
123
|
+
## License
|
|
124
|
+
|
|
125
|
+
Apache-2.0
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
buildscript {
|
|
2
|
+
ext.Coverage = [
|
|
3
|
+
kotlinVersion: "2.0.21",
|
|
4
|
+
minSdkVersion: 24,
|
|
5
|
+
compileSdkVersion: 36
|
|
6
|
+
]
|
|
7
|
+
|
|
8
|
+
ext.getExtOrDefault = { prop ->
|
|
9
|
+
if (rootProject.ext.has(prop)) {
|
|
10
|
+
return rootProject.ext.get(prop)
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
return Coverage[prop]
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
repositories {
|
|
17
|
+
google()
|
|
18
|
+
mavenCentral()
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
dependencies {
|
|
22
|
+
classpath "com.android.tools.build:gradle:8.7.2"
|
|
23
|
+
// noinspection DifferentKotlinGradleVersion
|
|
24
|
+
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${getExtOrDefault('kotlinVersion')}"
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
apply plugin: "com.android.library"
|
|
30
|
+
apply plugin: "kotlin-android"
|
|
31
|
+
|
|
32
|
+
apply plugin: "com.facebook.react"
|
|
33
|
+
|
|
34
|
+
android {
|
|
35
|
+
namespace "com.coverage"
|
|
36
|
+
|
|
37
|
+
compileSdkVersion getExtOrDefault("compileSdkVersion")
|
|
38
|
+
|
|
39
|
+
defaultConfig {
|
|
40
|
+
minSdkVersion getExtOrDefault("minSdkVersion")
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
compileOptions {
|
|
44
|
+
sourceCompatibility JavaVersion.VERSION_17
|
|
45
|
+
targetCompatibility JavaVersion.VERSION_17
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
dependencies {
|
|
50
|
+
implementation "com.facebook.react:react-android"
|
|
51
|
+
}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* react-native-coverage — app Jacoco report helper.
|
|
3
|
+
*
|
|
4
|
+
* Apply from the consumer app's `android/app/build.gradle` (Expo plugin does this):
|
|
5
|
+
*
|
|
6
|
+
* apply from: <package>/android/rn-coverage-jacoco.gradle
|
|
7
|
+
*
|
|
8
|
+
* Expects rootProject.ext.coverageLibraryProjectMatchers (same list as
|
|
9
|
+
* rn-coverage.gradle). Creates:
|
|
10
|
+
* - jacocoTestReport — merge unit *.exec + e2e *.ec (Codecov-style)
|
|
11
|
+
* - jacocoUnitTestReport — unit only
|
|
12
|
+
* - jacocoAndroidTestReport — e2e *.ec only
|
|
13
|
+
*
|
|
14
|
+
* Nested Gradle/Groovy closures must not read unqualified script locals —
|
|
15
|
+
* they resolve against the Project and throw MissingPropertyException.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
apply plugin: 'jacoco'
|
|
19
|
+
|
|
20
|
+
jacoco {
|
|
21
|
+
toolVersion = '0.8.14'
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
android {
|
|
25
|
+
jacoco {
|
|
26
|
+
version = '0.8.14'
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
tasks.withType(Test).configureEach { testTask ->
|
|
31
|
+
testTask.jacoco.includeNoLocationClasses = true
|
|
32
|
+
testTask.jacoco.excludes = ['jdk.internal.*']
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
ext.rnCoverageClassExcludes = [
|
|
36
|
+
'**/R.class',
|
|
37
|
+
'**/R$*.class',
|
|
38
|
+
'**/BuildConfig.*',
|
|
39
|
+
'**/Manifest*.*',
|
|
40
|
+
'**/*Test*.*',
|
|
41
|
+
'android/**/*.*',
|
|
42
|
+
]
|
|
43
|
+
|
|
44
|
+
def rnCoverageMatchers() {
|
|
45
|
+
return (rootProject.ext.has('coverageLibraryProjectMatchers')
|
|
46
|
+
? rootProject.ext.coverageLibraryProjectMatchers
|
|
47
|
+
: []).collect { it.toString() }
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
def matchedLibraryProjects() {
|
|
51
|
+
def matchers = rnCoverageMatchers()
|
|
52
|
+
return rootProject.subprojects.findAll { proj ->
|
|
53
|
+
proj.plugins.hasPlugin('com.android.library') &&
|
|
54
|
+
matchers.any { matcher -> proj.name.contains(matcher) }
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
def coverageClassDirectories() {
|
|
59
|
+
def excludes = project.ext.rnCoverageClassExcludes
|
|
60
|
+
def trees = []
|
|
61
|
+
matchedLibraryProjects().each { proj ->
|
|
62
|
+
def javacDebug = file("${proj.projectDir}/build/intermediates/javac/debug/compileDebugJavaWithJavac/classes")
|
|
63
|
+
def kotlinDebug = file("${proj.projectDir}/build/tmp/kotlin-classes/debug")
|
|
64
|
+
if (javacDebug.exists()) {
|
|
65
|
+
trees << fileTree(dir: javacDebug, excludes: excludes)
|
|
66
|
+
}
|
|
67
|
+
if (kotlinDebug.exists()) {
|
|
68
|
+
trees << fileTree(dir: kotlinDebug, excludes: excludes)
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return files(trees)
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
def coverageSourceDirectories() {
|
|
75
|
+
def srcs = []
|
|
76
|
+
matchedLibraryProjects().each { proj ->
|
|
77
|
+
def javaSrc = file("${proj.projectDir}/src/main/java")
|
|
78
|
+
def kotlinSrc = file("${proj.projectDir}/src/main/kotlin")
|
|
79
|
+
if (javaSrc.exists()) {
|
|
80
|
+
srcs << javaSrc
|
|
81
|
+
}
|
|
82
|
+
if (kotlinSrc.exists()) {
|
|
83
|
+
srcs << kotlinSrc
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return files(srcs)
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
def coverageExecutionData(List<String> includes) {
|
|
90
|
+
def trees = [fileTree(dir: project.buildDir, includes: includes)]
|
|
91
|
+
matchedLibraryProjects().each { proj ->
|
|
92
|
+
trees << fileTree(dir: proj.buildDir, includes: includes)
|
|
93
|
+
}
|
|
94
|
+
// Host-pulled Emma dumps commonly land under app/build/outputs/code_coverage
|
|
95
|
+
trees << fileTree(dir: "${project.buildDir}/outputs", includes: includes)
|
|
96
|
+
return files(trees)
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
def configureCoverageJacocoReport(JacocoReport reportTask) {
|
|
100
|
+
def htmlOutDir = layout.buildDirectory.dir("reports/jacoco/${reportTask.name}/html").get().asFile
|
|
101
|
+
|
|
102
|
+
reportTask.group = 'verification'
|
|
103
|
+
reportTask.reports {
|
|
104
|
+
xml.required = true
|
|
105
|
+
xml.outputLocation = layout.buildDirectory.file(
|
|
106
|
+
"reports/jacoco/${reportTask.name}/${reportTask.name}.xml"
|
|
107
|
+
)
|
|
108
|
+
html.required = true
|
|
109
|
+
html.outputLocation = htmlOutDir
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
reportTask.sourceDirectories.from = coverageSourceDirectories()
|
|
113
|
+
reportTask.classDirectories.from = coverageClassDirectories()
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
tasks.register('jacocoTestReport', JacocoReport) {
|
|
117
|
+
description = 'Merged Jacoco report (unit *.exec + e2e *.ec) for coverage library matchers'
|
|
118
|
+
configureCoverageJacocoReport(it)
|
|
119
|
+
executionData.from = coverageExecutionData(['**/*.exec', '**/*.ec'])
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
tasks.register('jacocoUnitTestReport', JacocoReport) {
|
|
123
|
+
description = 'Unit-only Jacoco report (*.exec)'
|
|
124
|
+
configureCoverageJacocoReport(it)
|
|
125
|
+
executionData.from = coverageExecutionData(['**/*.exec'])
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
tasks.register('jacocoAndroidTestReport', JacocoReport) {
|
|
129
|
+
description = 'E2e-only Jacoco report (*.ec from Emma flush / pull)'
|
|
130
|
+
configureCoverageJacocoReport(it)
|
|
131
|
+
executionData.from = coverageExecutionData(['**/*.ec'])
|
|
132
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* react-native-coverage — root Android instrumentation helper.
|
|
3
|
+
*
|
|
4
|
+
* Apply from the consumer app's `android/build.gradle` (Expo plugin does this):
|
|
5
|
+
*
|
|
6
|
+
* ext.coverageLibraryProjectMatchers = ['coverage-fixture', 'my-lib']
|
|
7
|
+
* apply from: new File([
|
|
8
|
+
* "node", "--print",
|
|
9
|
+
* "require.resolve('react-native-coverage/package.json')"
|
|
10
|
+
* ].execute(null, rootDir).text.trim()).getParentFile(),
|
|
11
|
+
* "android/rn-coverage.gradle")
|
|
12
|
+
*
|
|
13
|
+
* For each Android library subproject whose name contains a matcher:
|
|
14
|
+
* - apply Jacoco 0.8.14
|
|
15
|
+
* - enableAndroidTestCoverage on debug (Emma on-device .ec)
|
|
16
|
+
* - keep enableUnitTestCoverage false (AGP library unit probes are empty)
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
def coverageMatchers = (rootProject.ext.has('coverageLibraryProjectMatchers')
|
|
20
|
+
? rootProject.ext.coverageLibraryProjectMatchers
|
|
21
|
+
: []).collect { it.toString() }
|
|
22
|
+
|
|
23
|
+
if (coverageMatchers.isEmpty()) {
|
|
24
|
+
logger.lifecycle('[react-native-coverage] rn-coverage.gradle: no coverageLibraryProjectMatchers; skipping library instrumentation')
|
|
25
|
+
return
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
logger.lifecycle("[react-native-coverage] instrumenting library projects matching ${coverageMatchers}")
|
|
29
|
+
|
|
30
|
+
def configureCoverageLibrary = { Project subproject ->
|
|
31
|
+
if (!subproject.plugins.hasPlugin('com.android.library')) {
|
|
32
|
+
return
|
|
33
|
+
}
|
|
34
|
+
if (!coverageMatchers.any { matcher -> subproject.name.contains(matcher) }) {
|
|
35
|
+
return
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
subproject.pluginManager.apply('jacoco')
|
|
39
|
+
subproject.jacoco {
|
|
40
|
+
toolVersion = '0.8.14'
|
|
41
|
+
}
|
|
42
|
+
subproject.tasks.withType(Test).configureEach { testTask ->
|
|
43
|
+
testTask.jacoco.includeNoLocationClasses = true
|
|
44
|
+
testTask.jacoco.excludes = ['jdk.internal.*']
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
subproject.android {
|
|
48
|
+
buildTypes.debug {
|
|
49
|
+
enableAndroidTestCoverage = true
|
|
50
|
+
enableUnitTestCoverage = false
|
|
51
|
+
}
|
|
52
|
+
jacoco {
|
|
53
|
+
version = '0.8.14'
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
logger.lifecycle("[react-native-coverage] enabled Android test coverage on :${subproject.name}")
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
subprojects { subproject ->
|
|
61
|
+
if (subproject.state.executed) {
|
|
62
|
+
configureCoverageLibrary(subproject)
|
|
63
|
+
} else {
|
|
64
|
+
subproject.afterEvaluate {
|
|
65
|
+
configureCoverageLibrary(subproject)
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
package com.coverage
|
|
2
|
+
|
|
3
|
+
import android.util.Log
|
|
4
|
+
import com.facebook.react.bridge.ReactApplicationContext
|
|
5
|
+
import java.io.File
|
|
6
|
+
|
|
7
|
+
class CoverageModule(
|
|
8
|
+
reactContext: ReactApplicationContext,
|
|
9
|
+
) : NativeCoverageSpec(reactContext) {
|
|
10
|
+
/**
|
|
11
|
+
* Flush in-process Jacoco/Emma coverage to `filesDir/coverage.ec`.
|
|
12
|
+
* No-op (logged) when the Emma RT class is absent (coverage not enabled).
|
|
13
|
+
*/
|
|
14
|
+
override fun flush() {
|
|
15
|
+
try {
|
|
16
|
+
val coverageFile = File(reactApplicationContext.filesDir, COVERAGE_FILE_NAME)
|
|
17
|
+
val emmaRT = Class.forName("com.vladium.emma.rt.RT")
|
|
18
|
+
val dump =
|
|
19
|
+
emmaRT.getMethod(
|
|
20
|
+
"dumpCoverageData",
|
|
21
|
+
File::class.java,
|
|
22
|
+
Boolean::class.javaPrimitiveType,
|
|
23
|
+
Boolean::class.javaPrimitiveType,
|
|
24
|
+
)
|
|
25
|
+
dump.invoke(null, coverageFile, false, false)
|
|
26
|
+
Log.i(TAG, "[native-coverage] flushed Jacoco coverage to ${coverageFile.absolutePath}")
|
|
27
|
+
} catch (e: ClassNotFoundException) {
|
|
28
|
+
Log.w(
|
|
29
|
+
TAG,
|
|
30
|
+
"[native-coverage] Jacoco/Emma RT class not found; coverage is likely not enabled in this build",
|
|
31
|
+
)
|
|
32
|
+
} catch (e: Exception) {
|
|
33
|
+
Log.e(TAG, "[native-coverage] flush failed", e)
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
override fun dumpJsCoverage(json: String) {
|
|
38
|
+
try {
|
|
39
|
+
val out = File(reactApplicationContext.filesDir, JS_COVERAGE_FILE_NAME)
|
|
40
|
+
out.writeText(json)
|
|
41
|
+
Log.i(TAG, "[native-coverage] wrote JS coverage to ${out.absolutePath}")
|
|
42
|
+
} catch (e: Exception) {
|
|
43
|
+
Log.e(TAG, "[native-coverage] dumpJsCoverage failed", e)
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
companion object {
|
|
48
|
+
const val NAME = NativeCoverageSpec.NAME
|
|
49
|
+
private const val TAG = "Coverage"
|
|
50
|
+
private const val COVERAGE_FILE_NAME = "coverage.ec"
|
|
51
|
+
private const val JS_COVERAGE_FILE_NAME = "coverage-final.json"
|
|
52
|
+
}
|
|
53
|
+
}
|