@@ -109,28 +109,74 @@ Now open your [browser test page localhost:3000/](http://localhost:3000/) and th
109
109
110
110
Refresh the [ localhost:3000/coverage] ( http://localhost:3000/coverage ) in your browser to see there is client coverage now.
111
111
112
- ### Specific setup for Meteor package
112
+ ### Specific setup for Meteor packages
113
113
114
- In a meteor package, you need to add inside the ` package.js ` file:
114
+
115
+ #### 1. Add Test Dependencies
116
+ In a Meteor package, you need to add inside the ` package.js ` file the following dependencies:
115
117
116
118
``` js
117
119
[... ]
118
120
Package .onTest (function (api ) {
119
- api .
use ([
' lmieulet:meteor-legacy-coverage@0.2 .0' ,
' lmieulet:[email protected] .0 ' ,
' meteortesting:mocha' ]);
121
+ api .use ([' lmieulet:meteor-legacy-coverage@0.4 .0' , ' lmieulet:meteor-coverage@4. 3.0' ,' meteortesting:mocha@3.0.0 ' ]);
120
122
[... ]
121
123
});
122
124
```
123
125
124
- Creating a Meteor package in 2018 is a nightmare, so please stay calm when you discover the following ` package.json ` that prevents so many issues :
126
+ #### 2. Add Coverage Config
127
+ Additionally, you need to add the ` coverage.json ` file at the top-level of your package (where ` package.js ` ) is located
128
+ with the following minimal content:
129
+
130
+ ``` json
131
+ {
132
+ "include" : [
133
+ " **/packages/namespace_packagename.js" ,
134
+ " **/namespace:packagename/**"
135
+ ]
136
+ }
137
+ ```
138
+
139
+ Where ` namespace ` is the name of the package owner and ` packagename ` the name of the package,
140
+ similar to ` lmieulet:meteor-coverage ` .
141
+
142
+ #### 3. Add ` .babelrc `
143
+
144
+ In order to get your package instrumented by istanbul you need to make sure to have the babel environment
145
+ defined within the package!
146
+
147
+ Add the ` .babelrc ` file at the top-level of your package (where ` package.js ` ) is located
148
+ with the following minimal content:
149
+
150
+ ``` json
151
+ {
152
+ "env" : {
153
+ "COVERAGE" : {
154
+ "plugins" :[" istanbul" ]
155
+ }
156
+ }
157
+ }
125
158
```
159
+
160
+ With this, babel will only instrument your packages during tests that contain ` BABEL_ENV=COVERAGE ` as environment
161
+ variable!
162
+
163
+ > Note, for package tests it's not sufficient to have a ` "babel" ` entry in ` package.json ` . You have to add the
164
+ > ` .babelrc ` file to make it work!
165
+
166
+ #### 4. Run the tests
167
+ The best way to manage your package tests is using a ` package.json ` file that prevents so many issues :
168
+
169
+ ``` json
126
170
"scripts" : {
127
171
"setup-test" : " rm -rf ./someapp && meteor create --bare someapp && cd someapp && cp ../.coverage.json . && meteor npm i --save puppeteer && mkdir packages && ln -s ../../ ./packages/meteor-coverage" ,
128
- "test": "meteor npm run setup-test && cd someapp && TEST_BROWSER_DRIVER=puppeteer COVERAGE_VERBOSE=1 COVERAGE=1 COVERAGE_OUT_LCOVONLY=1 COVERAGE_APP_FOLDER=$(pwd)/ meteor test-packages --once --driver-package meteortesting:mocha ./packages/meteor-coverage",
129
- "test:watch": "cd someapp && TEST_WATCH=1 COVERAGE=1 COVERAGE_APP_FOLDER=$(pwd)/ meteor test-packages --driver-package meteortesting:mocha ./packages/meteor-coverage"
172
+ "test" : " meteor npm run setup-test && cd someapp && BABEL_ENV=COVERAGE TEST_BROWSER_DRIVER=puppeteer COVERAGE_VERBOSE=1 COVERAGE=1 COVERAGE_OUT_LCOVONLY=1 COVERAGE_APP_FOLDER=$(pwd)/ meteor test-packages --once --driver-package meteortesting:mocha ./packages/meteor-coverage" ,
173
+ "test:watch" : " cd someapp && BABEL_ENV=COVERAGE TEST_WATCH=1 COVERAGE=1 COVERAGE_APP_FOLDER=$(pwd)/ meteor test-packages --driver-package meteortesting:mocha ./packages/meteor-coverage" ,
174
+ "test:headless" : " cd someapp && BABEL_ENV=COVERAGE TEST_BROWSER_DRIVER=puppeteer COVERAGE_VERBOSE=1 COVERAGE=1 COVERAGE_OUT_LCOVONLY=1 COVERAGE_APP_FOLDER=$(pwd)/ meteor test-packages --driver-package meteortesting:mocha ./packages/meteor-coverage"
130
175
}
131
176
```
132
177
The task ` setup-test ` is the cutting edge workaround that creates an empty meteor app that will run your test later.
133
178
179
+
134
180
### Specific setup for Typescript
135
181
136
182
If you use Typescript, you cannot use babel to instrument your code, you need to rely on ` lmieulet:meteor-legacy-coverage ` (like packages).
0 commit comments