Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Coffeescript utility classes now will have logical branches ignored in coverage #36

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,3 @@ node_modules/
cover_html/

npm-debug.log

lib/
69 changes: 69 additions & 0 deletions lib/clean.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/command.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions lib/cover.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions lib/hook.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/ibrik.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 8 additions & 5 deletions lib/instrumenter.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/report.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,15 @@
"url": "git://github.com/Constellation/ibrik.git"
},
"dependencies": {
"coffee-script": "~1.8.0",
"coffee-script": "~1.10.0",
"esprima": "1.2.x",
"estraverse": "^1.9.0",
"fileset": "0.1.x",
"istanbul": "~0.3.2",
"lodash": "~2.4.1",
"mkdirp": "~0.5.0",
"optimist": "~0.6.1",
"semver": "^4.3.6",
"which": "~1.0.5"
},
"devDependencies": {
Expand Down
67 changes: 67 additions & 0 deletions src/clean.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# Copyright (C) 2012-2014 Yusuke Suzuki <[email protected]>
# Copyright (C) 2013-2014 Jeff Stamerjohn <[email protected]>
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

coffee = require 'coffee-script'
semver = require 'semver'

ignoreString = '/* istanbul ignore next: coffeescript utility boilerplate */'

utilities =
extends:
'1.8.0':
original: '__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }'
replacement: "__extends = function(child, parent) { for (var key in parent) { #{ignoreString} if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }"
'1.9.0':
original: 'extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }'
replacement: "extend = function(child, parent) { for (var key in parent) { #{ignoreString} if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }"
'1.10.0':
original: 'extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }'
replacement: "extend = function(child, parent) { for (var key in parent) { #{ignoreString} if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }"

indexOf:
'1.8.0':
original: '__indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; }'
replacement: "__indexOf = #{ignoreString} [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { #{ignoreString} if (i in this && this[i] === item) return i; } return -1; }"
'1.9.0':
original: 'indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; }'
replacement: "indexOf = #{ignoreString} [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { #{ignoreString} if (i in this && this[i] === item) return i; } return -1; }"
'1.10.0':
original: 'indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; }'
replacement: "indexOf = #{ignoreString} [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { #{ignoreString} if (i in this && this[i] === item) return i; } return -1; }"

clean = (compiledJS) ->
switch semver.minor coffee.VERSION
when 8 then version = '1.8.0'
when 9 then version = '1.9.0'
when 10 then version = '1.10.0'
else return compiledJS

newCompiledJS = compiledJS

for utilityKey, utilityVersions of utilities when utility = utilityVersions[version]
newCompiledJS = newCompiledJS.replace utility.original, utility.replacement

return newCompiledJS

module.exports = clean
# vim: set sw=4 ts=4 et tw=80 :
2 changes: 2 additions & 0 deletions src/instrumenter.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ _ = require 'lodash'
esprima = require 'esprima'
path = require 'path'
fs = require 'fs'
clean = require './clean'

# Use ECMAScript 5.1th indirect call to eval instead of direct eval call.
globalEval = (source) ->
Expand All @@ -45,6 +46,7 @@ class Instrumenter extends istanbul.Instrumenter

try
code = coffee.compile code, sourceMap: true
code.js = clean code.js
program = esprima.parse(code.js, {
loc: true
range: true
Expand Down