ferlores / mochify-istanbul Goto Github PK
View Code? Open in Web Editor NEWInstrument + create reports using istanbul with the mochify stream
License: Other
Instrument + create reports using istanbul with the mochify stream
License: Other
I use mochify a lot and this is a great add-on!
I found an error with required mustache templates in the javascript files being tested. The mustache templates are required as follows and are in the same directory as the javascript files:
var template= require("./template.mustache");
The browserify-hogan transformer is applied on mustache templates. The transformer is specified in the package.json
.
I have tried excluding mustache templates using --exclude '**/*.mustache'
which leads to another error as it seems (the console is spitting out a whole lot of JSON).
The command I'm running is:
mochify --plugin [ mochify-istanbul --exclude '**/*.mustache' --report cobertura ] ./test/*.js
Here it has .plugin(plugin, opts)
https://github.com/mantoni/mochify.js#code-coverage-with-istanbul
but in your docs it has
.plugin(plugin(opts))
if i run it like desribed in your docs i get
/home/mike/code/smokejs/node_modules/mochify-istanbul/index.js:7
var excludePattern = options.exclude ? [].concat(options.exclude) : [''];
^
TypeError: Cannot read property 'exclude' of undefined
at instrument (/home/mike/code/smokejs/node_modules/mochify-istanbul/index.js:7:31)
at module.exports (/home/mike/code/smokejs/node_modules/mochify-istanbul/index.js:77:15)
at Object.<anonymous> (/home/mike/code/smokejs/testRunner.js:17:3)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:906:3
I'm using a simple default setup to check code coverage with these results:
$ node_modules/.bin/mochify --plugin [ mochify-istanbul --report text ]
# phantomjs:
............
12 passing (12ms)
---------------------|-----------|-----------|-----------|-----------|
File | % Stmts |% Branches | % Funcs | % Lines |
---------------------|-----------|-----------|-----------|-----------|
lib/ | 16.67 | 0 | 0 | 16.67 |
sorter.js | 16.67 | 0 | 0 | 16.67 |
test/ | 3.23 | 100 | 0 | 3.23 |
create-test.js | 3.23 | 100 | 0 | 3.23 |
---------------------|-----------|-----------|-----------|-----------|
All files | 9.09 | 0 | 0 | 9.09 |
---------------------|-----------|-----------|-----------|-----------|
Although this project has 99.76% coverage reported by coverify:
$ node_modules/.bin/mochify --cover
# phantomjs:
............
12 passing (34ms)
# .../lib/sorter.js: line 12, column -68-41
throw new TypeError("Sorter cannot resolve '" + keys.slice(0, i).join(".")
+ "'' from " + JSON.stringify(obj));
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
# coverage: 427/428 (99.76 %)
Error: Exit 1
I'd like to use mochify-istanbul like this:
$ mochify --plugin [ mochify-istanbul --cobertura ]
This would allow me to add it as a devDependency and then simply configure it in the npm script.
Mochify is using subargs, so the --cobertura
option will be passed to this plugin as { cobertura : true }
.
What do you think?
Would be nice if the plugin would support these sets similar to coverify from the mochify suite, related: mantoni/mochify.js#74
I'm runing mochify like so
var mochify = require('mochify');
var istanbul = require('mochify-istanbul');
var aliasify = require('aliasify').configure({
aliases: {
"config": "./test/fixtures/config.js"
},
configDir: __dirname,
verbose: false
});
mochify({
reporter : 'spec',
port: 4444,
cover: false,
phantomjs: 'node_modules/.bin/phantomjs'
}).transform(aliasify).plugin(istanbul,{
"exclude": ['./test/*', './node_modules/**/*'],
"report": ['text', 'cobertura', 'json'],
"dir": './coverage'
}).bundle();
When it runs it complains about
Error: Line 1: Unexpected token : while parsing file: /home/mike/code/smokejs/test/fixtures/article/1.json
/home/mike/code/smokejs/test/fixtures/article/1.json:1
module.exports=
^
ParseError: Unexpected token
Error: Line 2: Unexpected token : while parsing file: /home/mike/code/smokejs/test/fixtures/author/peter.json
Error: Line 2: Unexpected token : while parsing file: /home/mike/code/smokejs/test/fixtures/homepage.json
----------|-----------|-----------|-----------|-----------|
File | % Stmts | % Branches | % Funcs | % Lines |
---|---|---|---|---|
---------- | ----------- | ----------- | ----------- | ----------- |
All files | 100 | 100 | 100 | 100 |
---------- | ----------- | ----------- | ----------- | ----------- |
The release 2.2.0 causes the error below (Windows and Unix). Version 2.1.3 works fine.
C:\dev\projects\XXX\node_modules\mochify-istanbul\node_modules\resolve\lib\sync.js:33
throw new Error("Cannot find module '" + x + "' from '" + y + "'");
^
Error: Cannot find module 'istanbul' from 'C:\dev\projects\XXX'
at Function.module.exports [as sync] (C:\dev\projects\XXX\node_modules\mochify-istanbul\node_modules\resolve\lib\sync.js:33:11)
at instrument (C:\dev\projects\XXX\node_modules\mochify-istanbul\index.js:9:38)
at module.exports (C:\dev\projects\XXX\node_modules\mochify-istanbul\index.js:100:15)
at Browserify.plugin (C:\dev\projects\XXX\node_modules\mochify\node_modules\browserify\index.js:347:9)
at C:\dev\projects\XXX\node_modules\mochify\lib\mochify.js:136:11
at Array.forEach (native)
at module.exports (C:\dev\projects\XXX\node_modules\mochify\lib\mochify.js:132:28)
at Object.<anonymous> (C:\dev\projects\XXX\node_modules\mochify\bin\cmd.js:27:1)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
How I use mochify-istanbul:
"config": {
"cover_report": "cobertura"
},
"scripts": {
"test:browser": "mochify ./browser/test/*.js",
"cover": "npm run test:browser -- --plugin [ mochify-istanbul --report $npm_package_config_cover_report --exclude '**/*.mustache' ]"
}
Running into an issue where I can't seem to find a way to get the coverage to report properly. The code I am testing is in a directory which is then symlinked in the node_modules
directory to allow for easy access (can require('app/foo.js')
as opposed to require('../../app/foo.js')
). Unfortunately, even without describing the node_modules in the exclude option (**/node_modules/**/*
) I can't get coverage to run through this file. It only runs if I require it as ../../app/foo.js
. Is there any way around this with globs? Basically would want to ignore all node_modules aside from one (the symlink).
When using the mochify "watch" option, the coverage reporting doesn't work correctly, it instead outputs something like the following to the console:
__coverage__='{"/Volumes/Server/project/client/js/app/Helpers.js":{"path":"/Volumes/Server/project/client/js/app/Helpers.js","s":{"1":1,"2":1,"3":1,"4":0},"b":{},"f":{"1":1,"2":0},"fnMap":{"1":{"name":"(anonymous_1)","line":11,"loc":{"start":{"line":11,"column":19},"end":{"line":11,"column":31}}},"2":{"name":"(anonymous_2)","line":19,"loc":{"start":{"line":19,"column":17},"end":{"line":19,"column":29}}}},"statementMap":{"1":{"start":{"line":3,"column":0},"end":{"line":4,"column":35}},"2":{"start":{"line":6,"column":0},"end":{"line":22,"column":2}},"3":{"start":{"line":12,"column":8},"end":{"line":12,"column":45}},"4":{"start":{"line":20,"column":8},"end":{"line":20,"column":68}}},"branchMap":{}},"/Volumes/Server/project/client/js/app/config.js":{"path":"/Volumes/Server/project/client/js/app/config.js","s":{"1":1,"2":1,"3":1,"4":1},"b":{"1":[1,0]},"f":{"1":1},"fnMap":{"1":{"name":"(anonymous_1)","line":21,"loc":{"start":{"line":21,"column":14},"end":{"line":21,"column":29}}}},"statementMap":{"1":{"start":{"line":3,"column":0},"end":{"line":6,"column":6}},"2":{"start":{"line":8,"column":0},"end":{"line":19,"column":3}},"3":{"start":{"line":21,"column":0},"end":{"line":23,"column":2}},"4":{"start":{"line":22,"column":4},"end":{"line":22,"column":36}}},"branchMap":{"1":{"line":5,"type":"binary-expr","locations":[{"start":{"line":5,"column":13},"end":{"line":5,"column":24}},{"start":{"line":5,"column":28},"end":{"line":5,"column":41}}]}}},"/Volumes/Server/project/client/js/app/shared/models/User.js":{"path":"/Volumes/Server/project/client/js/app/shared/models/User.js","s":{"1":1,"2":1,"3":3,"4":9,"5":9,"6":3,"7":9},"b":{"1":[9,4],"2":[3,6],"3":[9,5]},"f":{"1":3,"2":9},"fnMap":{"1":{"name":"(anonymous_1)","line":7,"loc":{"start":{"line":7,"column":16},"end":{"line":7,"column":28}}},"2":{"name":"(anonymous_2)","line":20,"loc":{"start":{"line":20,"column":17},"end":{"line":20,"column":29}}}},"statementMap":{"1":{"start":{"line":3,"column":0},"end":{"line":4,"column":35}},"2":{"start":{"line":6,"column":0},"end":{"line":31,"column":3}},"3":{"start":{"line":8,"column":8},"end":{"line":8,"column":58}},"4":{"start":{"line":21,"column":16},"end":{"line":21,"column":71}},"5":{"start":{"line":23,"column":16},"end":{"line":25,"column":17}},"6":{"start":{"line":24,"column":20},"end":{"line":24,"column":56}},"7":{"start":{"line":27,"column":16},"end":{"line":27,"column":28}}},"branchMap":{"1":{"line":21,"type":"binary-expr","locations":[{"start":{"line":21,"column":27},"end":{"line":21,"column":49}},{"start":{"line":21,"column":53},"end":{"line":21,"column":70}}]},"2":{"line":23,"type":"if","locations":[{"start":{"line":23,"column":16},"end":{"line":23,"column":16}},{"start":{"line":23,"column":16},"end":{"line":23,"column":16}}]},"3":{"line":23,"type":"binary-expr","locations":[{"start":{"line":23,"column":20},"end":{"line":23,"column":42}},{"start":{"line":23,"column":46},"end":{"line":23,"column":67}}]}}}}'
Any idea on a way around this?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.