Skip to content

Commit 557d2f1

Browse files
committed
docs: update readme
1 parent 210568e commit 557d2f1

File tree

1 file changed

+52
-6
lines changed

1 file changed

+52
-6
lines changed

Diff for: README.md

+52-6
Original file line numberDiff line numberDiff line change
@@ -109,28 +109,74 @@ Now open your [browser test page localhost:3000/](http://localhost:3000/) and th
109109

110110
Refresh the [localhost:3000/coverage](http://localhost:3000/coverage) in your browser to see there is client coverage now.
111111

112-
### Specific setup for Meteor package
112+
### Specific setup for Meteor packages
113113

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:
115117

116118
```js
117119
[...]
118120
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']);
120122
[...]
121123
});
122124
```
123125

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+
}
125158
```
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
126170
"scripts": {
127171
"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"
130175
}
131176
```
132177
The task `setup-test` is the cutting edge workaround that creates an empty meteor app that will run your test later.
133178

179+
134180
### Specific setup for Typescript
135181

136182
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

Comments
 (0)