Skip to content

Commit

Permalink
Merge pull request #91 from etamponi/master
Browse files Browse the repository at this point in the history
Support CoffeeScript v2
  • Loading branch information
jwalton committed Dec 13, 2017
2 parents 36e8912 + 306d521 commit 6d4cb9f
Show file tree
Hide file tree
Showing 18 changed files with 1,475 additions and 89 deletions.
2 changes: 2 additions & 0 deletions .gitignore
@@ -1,3 +1,5 @@
/.idea

/node_modules
/lib
/npm-debug.log
Expand Down
5 changes: 4 additions & 1 deletion CHANGELOG.md
@@ -1,5 +1,8 @@
# coffee-coverage Changelog

### v3.0.0
- This version works with CoffeeScript v2

### v2.0.0
- Add support for [nyc](https://github.com/istanbuljs/nyc).

Expand Down Expand Up @@ -72,7 +75,7 @@ Breaking changes:

### v0.2.0

- Force coffee-script to disable chaining of if/else if statements during compile. This
- Force coffeescript to disable chaining of if/else if statements during compile. This
fix is required for coffee-script 1.6.3 and higher.

### v0.1.4
Expand Down
4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -15,7 +15,7 @@ Instruments CoffeeScript files for code coverage. Compiles .coffee files to .js
Features
--------

* Native coffee-script instrumentation - [not based on source maps](./docs/comparison-to-ibrik.md)
* Native coffeescript instrumentation - [not based on source maps](./docs/comparison-to-ibrik.md)
* Conditional instrumentation with [pragmas](./docs/pragmas.md)
* Support for [nyc](./docs/HOWTO-nyc.md) style instrumentation
* Support for [Istanbul](./docs/HOWTO-istanbul.md) style instrumentation
Expand All @@ -34,7 +34,7 @@ files, then from your project's folder, run:

$ npm install --save-dev coffee-coverage
$ npm install --save-dev istanbul
$ mocha --recursive --compilers coffee:coffee-script/register --require coffee-coverage/register-istanbul test
$ mocha --recursive --compilers coffee:coffeescript/register --require coffee-coverage/register-istanbul test

$ ./node_modules/.bin/istanbul report
```
Expand Down
12 changes: 3 additions & 9 deletions bin/citest.sh
@@ -1,12 +1,6 @@
#!/usr/bin/env bash

echo Testing with Coffee-Script v1.7.1
npm install coffee-script@1.7.1
COFFEECOV_OUT=coverage/coverage-coffee-1_7_1.json npm test
echo Testing with Coffee-Script v1.8.0
npm install coffee-script@1.8.0
COFFEECOV_OUT=coverage/coverage-coffee-1_8_0.json npm test
echo Testing with Coffee-Script v1.9.2
npm install coffee-script@1.9.2
COFFEECOV_OUT=coverage/coverage-coffee-1_9_2.json npm test
echo Testing with Coffee-Script v2.0.2
npm install coffeescript@2.0.2
COFFEECOV_OUT=coverage/coverage-coffee-2_0_2.json npm test
npm run coverage-report
4 changes: 2 additions & 2 deletions docs/HOWTO-codeship-and-coveralls.md
Expand Up @@ -9,14 +9,14 @@ working.
First, you need your project building in [Codeship](https://codeship.com), and you need your
project set up in [Coveralls.io](https://coveralls.io/).

Assuming you have a coffee-script project with tests cases stored in /test, and you are using
Assuming you have a coffeescript project with tests cases stored in /test, and you are using
mocha to run your unit tests, `cd` to your project and run:

npm install --save-dev coffee-coverage istanbul coveralls

Save your mocha options in `./test/mocha.opts`:

--compilers coffee:coffee-script/register
--compilers coffee:coffeescript/register
--require coffee-coverage/register-istanbul
--recursive

Expand Down
8 changes: 4 additions & 4 deletions docs/HOWTO-istanbul.md
Expand Up @@ -12,12 +12,12 @@ Contents
Quick Start with Mocha
----------------------

Assuming you have a coffee-script project with tests cases stored in /test, and you are using
Assuming you have a coffeescript project with tests cases stored in /test, and you are using
mocha to run your unit tests, `cd` to your project and run:

npm install --save-dev coffee-coverage istanbul
mocha --recursive \
--compilers coffee:coffee-script/register \
--compilers coffee:coffeescript/register \
--require coffee-coverage/register-istanbul \
test
./node_modules/.bin/istanbul report
Expand Down Expand Up @@ -49,7 +49,7 @@ and your tests are set up to load code from /src, then run:
npm install --save-dev coffee-coverage
npm install --save-dev istanbul
./node_modules/.bin/istanbul cover -x 'lib/**' ./node_modules/.bin/_mocha -- \
--compilers coffee:coffee-script/register \
--compilers coffee:coffeescript/register \
--require coffee-coverage/register-istanbul \
--recursive \
test
Expand All @@ -62,7 +62,7 @@ Run with NPM

Save your mocha options in `/test/mocha.opts`:

--compilers coffee:coffee-script/register
--compilers coffee:coffeescript/register
--require coffee-coverage/register-istanbul
--recursive

Expand Down
6 changes: 3 additions & 3 deletions docs/HOWTO-jscoverage.md
Expand Up @@ -13,7 +13,7 @@ Contents
Quick Start with Mocha
----------------------

Assuming you have a coffee-script project with tests cases stored in /test, and you are using
Assuming you have a coffeescript project with tests cases stored in /test, and you are using
mocha to run your unit tests, `cd` to your project and run:

npm install --save-dev coffee-coverage
Expand Down Expand Up @@ -41,7 +41,7 @@ Run with NPM

Save your mocha options in `/test/mocha.opts`:

--compilers coffee:coffee-script/register
--compilers coffee:coffeescript/register
--recursive

In package.json, add:
Expand Down Expand Up @@ -76,7 +76,7 @@ Alternatively, you can use coffeeCoverage to statically compile your code with i

# Compile everything except the test directory with coffeeCoverage
coffeeCoverage --initfile ./lib/init.js --exclude test --path abbr ./src ./lib
# Compile the test directory with regular coffee-script
# Compile the test directory with regular coffeescript
coffee -o ./lib/test ./src/test

This also writes an "lib/init.js" which initializes all the execution counts to 0. This is handy,
Expand Down
6 changes: 3 additions & 3 deletions docs/HOWTO-nyc.md
Expand Up @@ -12,12 +12,12 @@ Contents
Quick Start with Mocha
----------------------

Assuming you have a coffee-script project with tests cases stored in /test, and you are using
Assuming you have a coffeescript project with tests cases stored in /test, and you are using
mocha to run your unit tests, `cd` to your project and run:

npm install --save-dev coffee-coverage nyc
./node_modules/.bin/nyc --reporter lcov ./node_modules/.bin/mocha --recursive \
--compilers coffee:coffee-script/register \
--compilers coffee:coffeescript/register \
--require coffee-coverage/register-istanbul \
test

Expand All @@ -44,7 +44,7 @@ Run with NPM

Save your mocha options in `/test/mocha.opts`:

--compilers coffee:coffee-script/register
--compilers coffee:coffeescript/register
--require coffee-coverage/register-istanbul
--recursive

Expand Down
4 changes: 2 additions & 2 deletions docs/HOWTO-travisci-and-coveralls.md
Expand Up @@ -9,14 +9,14 @@ working.
First, you need to sign up for an account at [Travis-CI](https://travis-ci.org/) and you need
to add your project in [Coveralls.io](https://coveralls.io/).

Assuming you have a coffee-script project with tests cases stored in /test, and you are using
Assuming you have a coffeescript project with tests cases stored in /test, and you are using
mocha to run your unit tests, `cd` to your project and run:

npm install --save-dev coffee-coverage istanbul coveralls

Save your mocha options in `./test/mocha.opts`:

--compilers coffee:coffee-script/register
--compilers coffee:coffeescript/register
--require coffee-coverage/register-istanbul
--recursive

Expand Down
8 changes: 4 additions & 4 deletions docs/development.md
@@ -1,15 +1,15 @@
Overview
--------
The 5 mile high view of coffee-coverage is; first we use
[coffee-script to parse the input and generate an abstract syntax tree (AST)](https://github.com/benbria/coffee-coverage/blob/c7566d50493ad98953640ccc5e7dc0080576d08a/src/coffeeCoverage.coffee#L319).
[coffeescript to parse the input and generate an abstract syntax tree (AST)](https://github.com/benbria/coffee-coverage/blob/c7566d50493ad98953640ccc5e7dc0080576d08a/src/coffeeCoverage.coffee#L319).
Then we visit every node in the AST with an
[instrumentor](https://github.com/benbria/coffee-coverage/tree/master/src/instrumentors) which, generally, adds some
extra nodes into the resulting coffee-script. Finally we
extra nodes into the resulting coffeescript. Finally we
[compile the resulting AST](https://github.com/benbria/coffee-coverage/blob/c7566d50493ad98953640ccc5e7dc0080576d08a/src/coffeeCoverage.coffee#L350)
out into JavaScript.

All the information about where a particular fragment of source came from is based on the [`locationData`](https://github.com/jashkenas/coffeescript/blob/98dd1bf8e80aa7974422a5fdef3075a9e7329d00/src/helpers.coffee#L98)
found in the coffee-script node.
found in the coffeescript node.

You'll notice that instrumentors have a
[`getInitString()`](https://github.com/benbria/coffee-coverage/blob/c7566d50493ad98953640ccc5e7dc0080576d08a/src/instrumentors/Istanbul.coffee#L402)
Expand All @@ -27,7 +27,7 @@ If we're running coffee-coverage directly from mocha, this is pretty easy. We j
instrumentation data to a global variable, then right before the program terminates we [write this global data
out to a JSON file](https://github.com/benbria/coffee-coverage/blob/c7566d50493ad98953640ccc5e7dc0080576d08a/src/register.coffee#L134).

If we're running `istanbul cover` to generate coverage for a project with mixed JS and coffee-script content, then
If we're running `istanbul cover` to generate coverage for a project with mixed JS and coffeescript content, then
things get a little more exciting. The problem is that
[Istanbul generates a unique variable name](https://github.com/gotwarlost/istanbul/blob/c87ada03cb485e4f9110224899b68d8dc27e4bf3/lib/command/common/run-with-cover.js#L158)
for coverage data on every run, which means coffee-coverage needs to
Expand Down

0 comments on commit 6d4cb9f

Please sign in to comment.