Skip to content

Commit adfd0fb

Browse files
authored
Merge pull request mozilla#335 from hildjj/coverage
Coverage tools
2 parents df6608d + 39db032 commit adfd0fb

File tree

6 files changed

+80
-4
lines changed

6 files changed

+80
-4
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,5 @@ node_modules/*
55
build/
66
package-lock.json
77
bench/*.svg
8+
.nyc_output/
9+
coverage/

.travis.yml

+10
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,16 @@ node_js:
66
- "8"
77
- "9"
88

9+
install:
10+
- npm install
11+
- npm install coveralls
12+
13+
script:
14+
- npm run coverage
15+
16+
after_success:
17+
- nyc report --reporter=text-lcov | coveralls
18+
919
cache:
1020
directories:
1121
- node_modules

.waiting.html

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<title>Code coverage report for All files</title>
5+
<style>
6+
body {
7+
font-family: Helvetica Neue, Helvetica, Arial;
8+
font-size: 20px;
9+
color:#333;
10+
margin: 50px;
11+
}
12+
code {
13+
color: green;
14+
}
15+
</style>
16+
</head>
17+
<body>
18+
<div>This page will refresh with a coverage report, as long as you have
19+
executed <code>npm run dev</code>. Please be patient.</div>
20+
</body>
21+
</html>

CONTRIBUTING.md

+24
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ very appreciated.
1616
- [Submitting Pull Requests](#submitting-pull-requests)
1717
- [Running Tests](#running-tests)
1818
- [Writing New Tests](#writing-new-tests)
19+
- [Checking code coverage](#checking-code-coverage)
1920
- [Updating the `lib/mappings.wasm` WebAssembly Module](#updating-the-libmappingswasm-webassembly-module)
2021

2122
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
@@ -113,6 +114,29 @@ can use as well:
113114
var util = require('./util');
114115
```
115116

117+
## Checking code coverage
118+
119+
It's fun to find ways to test lines of code that aren't visited by
120+
the tests yet.
121+
122+
```shell
123+
$ npm run coverage
124+
$ open coverage/index.html
125+
```
126+
127+
This will allow you to browse to red sections of the code that need
128+
more attention. Even more cool, however, is to run:
129+
130+
```shell
131+
$ npm run dev
132+
```
133+
134+
(On some operating systems, this may pop up a request for node to be able to open a socket. Click "Allow" or the equivalent.)
135+
136+
This will run the coverage tools, and monitor all of the files in the
137+
project, re-running the coverage tools and refreshing the browser when
138+
any files change. There will be a small web server running on port 4103 to enable this. Control-C to stop.
139+
116140
## Updating the `lib/mappings.wasm` WebAssembly Module
117141

118142
Ensure that you have the Rust toolchain installed:

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
[![Build Status](https://travis-ci.org/mozilla/source-map.png?branch=master)](https://travis-ci.org/mozilla/source-map)
44

5+
[![Coverage Status](https://coveralls.io/repos/github/mozilla/source-map/badge.svg)](https://coveralls.io/github/mozilla/source-map)
6+
57
[![NPM](https://nodei.co/npm/source-map.png?downloads=true&downloadRank=true)](https://www.npmjs.com/package/source-map)
68

79
This is a library to generate and consume the source map format

package.json

+21-4
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,32 @@
5959
},
6060
"license": "BSD-3-Clause",
6161
"scripts": {
62-
"test": "npm run lint && npm run build && node test/run-tests.js",
63-
"build": "webpack --color",
6462
"lint": "eslint *.js lib/ test/",
63+
"prebuild": "npm run lint",
64+
"build": "webpack --color",
65+
"pretest": "npm run build",
66+
"test": "node test/run-tests.js",
67+
"precoverage": "npm run build",
68+
"coverage": "nyc node test/run-tests.js",
69+
"setup": "mkdir -p coverage && cp -n .waiting.html coverage/index.html || true",
70+
"dev:live": "live-server --port=4103 --ignorePattern='(js|css|png)$' coverage",
71+
"dev:watch": "watch 'npm run coverage' lib/ test/",
72+
"predev": "npm run setup",
73+
"dev": "npm-run-all -p --silent dev:*",
74+
"clean": "rm -rf coverage .nyc_output",
6575
"toc": "doctoc --title '## Table of Contents' README.md && doctoc --title '## Table of Contents' CONTRIBUTING.md"
6676
},
6777
"devDependencies": {
6878
"doctoc": "^0.15.0",
69-
"webpack": "^3.10",
70-
"eslint": "^4.19.1"
79+
"eslint": "^4.19.1",
80+
"live-server": "^1.2.0",
81+
"npm-run-all": "^4.1.2",
82+
"nyc": "^11.7.1",
83+
"watch": "^1.0.2",
84+
"webpack": "^3.10"
85+
},
86+
"nyc": {
87+
"reporter": "html"
7188
},
7289
"typings": "source-map"
7390
}

0 commit comments

Comments
 (0)