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

Istanbul Coverage Test #996

Merged
merged 11 commits into from
Oct 30, 2018
Merged
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
3 changes: 0 additions & 3 deletions .bowerrc

This file was deleted.

6 changes: 2 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
build/
node_modules/
lib/*/*
coverage.info
npm-debug.log
phantomjsdriver.log
coverage/
*.log
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ node_js:

before_install:
- npm install -g grunt-cli
- npm install -g bower

install: npm install

Expand Down
235 changes: 121 additions & 114 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,13 @@ module.exports = function(grunt) {
'plugins/tools/*.js'
],

geometry: ['src/geometry.js'],
vectorizer: ['src/vectorizer.js'],
geometry: [
'src/geometry.js'
],

vectorizer: [
'src/vectorizer.js'
],

polyfills: [
'plugins/polyfills/base64.js',
Expand All @@ -58,7 +63,6 @@ module.exports = function(grunt) {
],

plugins: {

'shapes.erd': ['plugins/shapes/joint.shapes.erd.js'],
'shapes.fsa': ['plugins/shapes/joint.shapes.fsa.js'],
'shapes.org': ['plugins/shapes/joint.shapes.org.js'],
Expand All @@ -67,9 +71,16 @@ module.exports = function(grunt) {
'shapes.devs': ['plugins/shapes/joint.shapes.devs.js'],
'shapes.uml': ['plugins/shapes/joint.shapes.uml.js'],
'shapes.logic': ['plugins/shapes/joint.shapes.logic.js'],

'layout.DirectedGraph': ['plugins/layout/DirectedGraph/joint.layout.DirectedGraph.js']
}
},

dependecies: [
'node_modules/jquery/dist/jquery.js',
'node_modules/lodash/lodash.js',
'node_modules/backbone/backbone.js',
'node_modules/graphlib/dist/graphlib.core.js',
'node_modules/dagre/dist/dagre.core.js',
]
};

var css = {
Expand Down Expand Up @@ -473,39 +484,6 @@ module.exports = function(grunt) {
}
}
},
qunit: {
all: [
'test/**/*.html',
'!test/**/coverage.html',
'!test/**/node_modules/**'
],
all_coverage: [
'test/**/coverage.html',
'!test/**/node_modules/**'
],
joint: [
'test/jointjs/*.html',
'!test/jointjs/coverage.html',
'!test/**/node_modules/**'
],
geometry: ['test/geometry/*.html'],
vectorizer: ['test/vectorizer/*.html']
},
shell: {

/*
Run `bower install` in the context of the given directory.
*/
bowerInstall: {
command: function(dir, environment) {

var flags = environment && environment === 'production' ? ' --production': '';
var cmd = 'cd ' + dir + ' && bower --allow-root install' + flags;

return cmd;
}
}
},
syntaxHighlighting: {
docs: {
src: [
Expand Down Expand Up @@ -568,78 +546,112 @@ module.exports = function(grunt) {
tasks: ['newer:concat:types']
}
},
qunit: {
joint: [
'test/jointjs/requirejs.html',
'test/jointjs/browserify.html',
'test/jointjs/lodash3/index.html'
],
geometry: [
'test/geometry/requirejs.html',
],
vectorizer: [
'test/vectorizer/requirejs.html'
]
},
karma: {
options: {
basePath: '',
autoWatch: false,
frameworks: ['sinon', 'qunit'],
browsers: karmaBrowsers(),
reporters: ['progress', 'coverage'],
singleRun: true,
exclude: [
'test/**/require.js',
'test/**/browserify.js'
]
},
geometry: {
options: {
files: [
js.geometry,
'test/geometry/*.js'
],
preprocessors: karmaPreprocessors(js.geometry),
coverageReporter: karmaCoverageReporters('geometry')
},
},
vectorizer: {
options: {
files: [
js.geometry,
js.vectorizer,
'test/vectorizer/*.js',
],
preprocessors: karmaPreprocessors(js.vectorizer),
coverageReporter: karmaCoverageReporters('vectorizer')
}
},
joint: {
options: {
files: [
js.dependecies,
js.geometry,
js.vectorizer,
js.polyfills,
js.core,
allJSPlugins(),
'test/utils.js',
'test/jointjs/**/*.js',
],
preprocessors: karmaPreprocessors([].concat(js.core, allJSPlugins())),
coverageReporter: karmaCoverageReporters('joint')
}
}
},
env: {

}
};

var isTestCoverageTask = grunt.cli.tasks.indexOf('test:coverage') !== -1;

if (isTestCoverageTask) {

(function() {

// Replace all qunit configurations with the 'urls' method.
// Append all URLs with ?coverage=true&grunt
// This will run all qunit tests with test coverage enabled and report results back to grunt.

var reporter = grunt.option('reporter') || 'lcov';

// Serve up the test files via an express app.
var express = require('express');
var serveStatic = require('serve-static');
var app = express();
var host = 'localhost';
var port = 3000;

app.use('/', serveStatic(__dirname));
app.listen(port, host);

var name, files;

for (name in config.qunit) {

// Resolve the paths for all files referenced in the task.
files = grunt.file.expand(config.qunit[name]);

// Overwrite QUnit task config with URLs method.
config.qunit[name] = { options: { urls: [] }};

files.forEach(function(file) {

var url = 'http://' + host + ':' + port + '/' + file + '?coverage=true&reporter=' + reporter;

config.qunit[name].options.urls.push(url);
});
}

var reporterToFileExtension = {
lcov: 'info'
};

var reports = [];

grunt.event.on('qunit.report', function(data) {

reports.push(data);
});

process.on('exit', function() {

var ext = reporterToFileExtension[reporter];
var outputFile = grunt.option('output') || 'coverage' + (ext ? '.' + ext : '');
var data;

switch (reporter) {
case 'lcov':
data = reports.join('\n');
break;
}
function karmaBrowsers() {
var browser = grunt.option('browser') || 'PhantomJS';
return [browser];
}

grunt.file.write(outputFile, data);
});
function karmaPreprocessors(files) {
var preprocessors = ['coverage'];
return files.reduce(function(files, file) {
files[file] = preprocessors;
return files;
}, {});
}

})();
function karmaCoverageReporters(name) {
var reporters;
var check;
var reporter = grunt.option('reporter') || '';
if (!reporter && grunt.cli.tasks.indexOf('test:coverage') !== -1) {
reporter = 'html';
}
switch (reporter) {
case 'lcov':
reporters = [{ type: 'lcovonly', subdir: '.', file: `${name}.lcov` }];
break;
case 'html':
reporters = [{ type: 'html' }];
break;
case '':
reporters = [{ type: 'text-summary' }];
check = grunt.file.readJSON('coverage.json')[name];
break;
default:
grunt.log.error(`Invalid reporter "${reporter}". Use "lcov" or "html".`);
process.exit(1);
return;
}
return { dir: `coverage/${name}`, reporters, check }
}

(function registerPartials(partials) {
Expand Down Expand Up @@ -823,20 +835,15 @@ module.exports = function(grunt) {
'concat:types'
]);

grunt.registerTask('test:server', ['mochaTest:server']);
grunt.registerTask('test:client', ['qunit:all']);
grunt.registerTask('test:bundles', [ 'qunit:joint', 'qunit:vectorizer', 'qunit:geometry'])
grunt.registerTask('test:src', ['karma:geometry', 'karma:vectorizer', 'karma:joint']);
grunt.registerTask('test:coverage', ['test:src']);
grunt.registerTask('test:code-style', ['eslint']);
grunt.registerTask('test:server', ['mochaTest:server']);
grunt.registerTask('test:client', ['test:src', 'test:bundles']);
grunt.registerTask('test', ['test:server', 'test:client', 'test:code-style']);

grunt.registerTask('test:coverage', [
'qunit:all_coverage'
]);

grunt.registerTask('bowerInstall', [
'shell:bowerInstall:.'
]);

grunt.registerTask('install', ['bowerInstall', 'build:all']);
grunt.registerTask('install', ['build:all']);
grunt.registerTask('default', ['install', 'build', 'watch']);

var e2eBrowsers = {
Expand Down
25 changes: 15 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,15 @@ Please see [http://jointjs.com](http://jointjs.com) for more information, demos

## Supported browsers

Only the good ones (those that support SVG):

* Latest Google Chrome (including mobile)
* Latest Firefox
* Safari (including mobile)
* IE 9+
* Latest Safari (including mobile)
* Latest MSEdge
* Latest Opera
* IE 10+
* PhantomJS

Any problem with JointJS in the above browsers should be reported as a bug in JointJS.

## Development Environment

Expand All @@ -47,7 +49,6 @@ If you want to work on JointJS locally, use the following guidelines to get star
Make sure you have the following dependencies installed on your system:
* [Node.js](https://nodejs.org/)
* [grunt-cli](http://gruntjs.com/using-the-cli)
* [bower](http://bower.io/)
* git

### Setup
Expand All @@ -65,9 +66,8 @@ cd joint
Run installation
```
npm install
bower install
```
This will install all npm and bower dependencies as well as run a full build.
This will install all npm dependencies as well as run a full build.

### Tests

Expand All @@ -91,14 +91,19 @@ To run code style checks:
grunt test:code-style
```

### Code Coverage Reports

### Code Coverage
To output a code coverage report in HTML:
```
grunt test:coverage"
```

To output a code coverage report in [lcov format](http://ltp.sourceforge.net/coverage/lcov/geninfo.1.php) for all unit tests:
To output a code coverage report in [lcov format](http://ltp.sourceforge.net/coverage/lcov/geninfo.1.php):
```
grunt test:coverage --reporter="lcov"
```
The output will be saved to a new file named `coverage.info` at the root of the project directory.

The output for all unit tests will be saved in the `coverage` directory.


### Building Distribution Files
Expand Down
Loading