Skip to content

Commit fd06960

Browse files
kumilingusvtalas
authored andcommitted
Istanbul Coverage Test (clientIO#996)
1 parent f338e3f commit fd06960

35 files changed

+3538
-2821
lines changed

.bowerrc

-3
This file was deleted.

.gitignore

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
build/
22
node_modules/
3-
lib/*/*
4-
coverage.info
5-
npm-debug.log
6-
phantomjsdriver.log
3+
coverage/
4+
*.log

.travis.yml

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ node_js:
55

66
before_install:
77
- npm install -g grunt-cli
8-
- npm install -g bower
98

109
install: npm install
1110

Gruntfile.js

+121-114
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,13 @@ module.exports = function(grunt) {
4545
'plugins/tools/*.js'
4646
],
4747

48-
geometry: ['src/geometry.js'],
49-
vectorizer: ['src/vectorizer.js'],
48+
geometry: [
49+
'src/geometry.js'
50+
],
51+
52+
vectorizer: [
53+
'src/vectorizer.js'
54+
],
5055

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

6065
plugins: {
61-
6266
'shapes.erd': ['plugins/shapes/joint.shapes.erd.js'],
6367
'shapes.fsa': ['plugins/shapes/joint.shapes.fsa.js'],
6468
'shapes.org': ['plugins/shapes/joint.shapes.org.js'],
@@ -67,9 +71,16 @@ module.exports = function(grunt) {
6771
'shapes.devs': ['plugins/shapes/joint.shapes.devs.js'],
6872
'shapes.uml': ['plugins/shapes/joint.shapes.uml.js'],
6973
'shapes.logic': ['plugins/shapes/joint.shapes.logic.js'],
70-
7174
'layout.DirectedGraph': ['plugins/layout/DirectedGraph/joint.layout.DirectedGraph.js']
72-
}
75+
},
76+
77+
dependecies: [
78+
'node_modules/jquery/dist/jquery.js',
79+
'node_modules/lodash/lodash.js',
80+
'node_modules/backbone/backbone.js',
81+
'node_modules/graphlib/dist/graphlib.core.js',
82+
'node_modules/dagre/dist/dagre.core.js',
83+
]
7384
};
7485

7586
var css = {
@@ -473,39 +484,6 @@ module.exports = function(grunt) {
473484
}
474485
}
475486
},
476-
qunit: {
477-
all: [
478-
'test/**/*.html',
479-
'!test/**/coverage.html',
480-
'!test/**/node_modules/**'
481-
],
482-
all_coverage: [
483-
'test/**/coverage.html',
484-
'!test/**/node_modules/**'
485-
],
486-
joint: [
487-
'test/jointjs/*.html',
488-
'!test/jointjs/coverage.html',
489-
'!test/**/node_modules/**'
490-
],
491-
geometry: ['test/geometry/*.html'],
492-
vectorizer: ['test/vectorizer/*.html']
493-
},
494-
shell: {
495-
496-
/*
497-
Run `bower install` in the context of the given directory.
498-
*/
499-
bowerInstall: {
500-
command: function(dir, environment) {
501-
502-
var flags = environment && environment === 'production' ? ' --production': '';
503-
var cmd = 'cd ' + dir + ' && bower --allow-root install' + flags;
504-
505-
return cmd;
506-
}
507-
}
508-
},
509487
syntaxHighlighting: {
510488
docs: {
511489
src: [
@@ -568,78 +546,112 @@ module.exports = function(grunt) {
568546
tasks: ['newer:concat:types']
569547
}
570548
},
549+
qunit: {
550+
joint: [
551+
'test/jointjs/requirejs.html',
552+
'test/jointjs/browserify.html',
553+
'test/jointjs/lodash3/index.html'
554+
],
555+
geometry: [
556+
'test/geometry/requirejs.html',
557+
],
558+
vectorizer: [
559+
'test/vectorizer/requirejs.html'
560+
]
561+
},
562+
karma: {
563+
options: {
564+
basePath: '',
565+
autoWatch: false,
566+
frameworks: ['sinon', 'qunit'],
567+
browsers: karmaBrowsers(),
568+
reporters: ['progress', 'coverage'],
569+
singleRun: true,
570+
exclude: [
571+
'test/**/require.js',
572+
'test/**/browserify.js'
573+
]
574+
},
575+
geometry: {
576+
options: {
577+
files: [
578+
js.geometry,
579+
'test/geometry/*.js'
580+
],
581+
preprocessors: karmaPreprocessors(js.geometry),
582+
coverageReporter: karmaCoverageReporters('geometry')
583+
},
584+
},
585+
vectorizer: {
586+
options: {
587+
files: [
588+
js.geometry,
589+
js.vectorizer,
590+
'test/vectorizer/*.js',
591+
],
592+
preprocessors: karmaPreprocessors(js.vectorizer),
593+
coverageReporter: karmaCoverageReporters('vectorizer')
594+
}
595+
},
596+
joint: {
597+
options: {
598+
files: [
599+
js.dependecies,
600+
js.geometry,
601+
js.vectorizer,
602+
js.polyfills,
603+
js.core,
604+
allJSPlugins(),
605+
'test/utils.js',
606+
'test/jointjs/**/*.js',
607+
],
608+
preprocessors: karmaPreprocessors([].concat(js.core, allJSPlugins())),
609+
coverageReporter: karmaCoverageReporters('joint')
610+
}
611+
}
612+
},
571613
env: {
572614

573615
}
574616
};
575617

576-
var isTestCoverageTask = grunt.cli.tasks.indexOf('test:coverage') !== -1;
577-
578-
if (isTestCoverageTask) {
579-
580-
(function() {
581-
582-
// Replace all qunit configurations with the 'urls' method.
583-
// Append all URLs with ?coverage=true&grunt
584-
// This will run all qunit tests with test coverage enabled and report results back to grunt.
585-
586-
var reporter = grunt.option('reporter') || 'lcov';
587-
588-
// Serve up the test files via an express app.
589-
var express = require('express');
590-
var serveStatic = require('serve-static');
591-
var app = express();
592-
var host = 'localhost';
593-
var port = 3000;
594-
595-
app.use('/', serveStatic(__dirname));
596-
app.listen(port, host);
597-
598-
var name, files;
599-
600-
for (name in config.qunit) {
601-
602-
// Resolve the paths for all files referenced in the task.
603-
files = grunt.file.expand(config.qunit[name]);
604-
605-
// Overwrite QUnit task config with URLs method.
606-
config.qunit[name] = { options: { urls: [] }};
607-
608-
files.forEach(function(file) {
609-
610-
var url = 'http://' + host + ':' + port + '/' + file + '?coverage=true&reporter=' + reporter;
611-
612-
config.qunit[name].options.urls.push(url);
613-
});
614-
}
615-
616-
var reporterToFileExtension = {
617-
lcov: 'info'
618-
};
619-
620-
var reports = [];
621-
622-
grunt.event.on('qunit.report', function(data) {
623-
624-
reports.push(data);
625-
});
626-
627-
process.on('exit', function() {
628-
629-
var ext = reporterToFileExtension[reporter];
630-
var outputFile = grunt.option('output') || 'coverage' + (ext ? '.' + ext : '');
631-
var data;
632-
633-
switch (reporter) {
634-
case 'lcov':
635-
data = reports.join('\n');
636-
break;
637-
}
618+
function karmaBrowsers() {
619+
var browser = grunt.option('browser') || 'PhantomJS';
620+
return [browser];
621+
}
638622

639-
grunt.file.write(outputFile, data);
640-
});
623+
function karmaPreprocessors(files) {
624+
var preprocessors = ['coverage'];
625+
return files.reduce(function(files, file) {
626+
files[file] = preprocessors;
627+
return files;
628+
}, {});
629+
}
641630

642-
})();
631+
function karmaCoverageReporters(name) {
632+
var reporters;
633+
var check;
634+
var reporter = grunt.option('reporter') || '';
635+
if (!reporter && grunt.cli.tasks.indexOf('test:coverage') !== -1) {
636+
reporter = 'html';
637+
}
638+
switch (reporter) {
639+
case 'lcov':
640+
reporters = [{ type: 'lcovonly', subdir: '.', file: `${name}.lcov` }];
641+
break;
642+
case 'html':
643+
reporters = [{ type: 'html' }];
644+
break;
645+
case '':
646+
reporters = [{ type: 'text-summary' }];
647+
check = grunt.file.readJSON('coverage.json')[name];
648+
break;
649+
default:
650+
grunt.log.error(`Invalid reporter "${reporter}". Use "lcov" or "html".`);
651+
process.exit(1);
652+
return;
653+
}
654+
return { dir: `coverage/${name}`, reporters, check }
643655
}
644656

645657
(function registerPartials(partials) {
@@ -823,20 +835,15 @@ module.exports = function(grunt) {
823835
'concat:types'
824836
]);
825837

826-
grunt.registerTask('test:server', ['mochaTest:server']);
827-
grunt.registerTask('test:client', ['qunit:all']);
838+
grunt.registerTask('test:bundles', [ 'qunit:joint', 'qunit:vectorizer', 'qunit:geometry'])
839+
grunt.registerTask('test:src', ['karma:geometry', 'karma:vectorizer', 'karma:joint']);
840+
grunt.registerTask('test:coverage', ['test:src']);
828841
grunt.registerTask('test:code-style', ['eslint']);
842+
grunt.registerTask('test:server', ['mochaTest:server']);
843+
grunt.registerTask('test:client', ['test:src', 'test:bundles']);
829844
grunt.registerTask('test', ['test:server', 'test:client', 'test:code-style']);
830845

831-
grunt.registerTask('test:coverage', [
832-
'qunit:all_coverage'
833-
]);
834-
835-
grunt.registerTask('bowerInstall', [
836-
'shell:bowerInstall:.'
837-
]);
838-
839-
grunt.registerTask('install', ['bowerInstall', 'build:all']);
846+
grunt.registerTask('install', ['build:all']);
840847
grunt.registerTask('default', ['install', 'build', 'watch']);
841848

842849
var e2eBrowsers = {

README.md

+15-10
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,15 @@ Please see [http://jointjs.com](http://jointjs.com) for more information, demos
3030

3131
## Supported browsers
3232

33-
Only the good ones (those that support SVG):
34-
3533
* Latest Google Chrome (including mobile)
3634
* Latest Firefox
37-
* Safari (including mobile)
38-
* IE 9+
35+
* Latest Safari (including mobile)
36+
* Latest MSEdge
37+
* Latest Opera
38+
* IE 10+
39+
* PhantomJS
3940

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

4143
## Development Environment
4244

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

5354
### Setup
@@ -65,9 +66,8 @@ cd joint
6566
Run installation
6667
```
6768
npm install
68-
bower install
6969
```
70-
This will install all npm and bower dependencies as well as run a full build.
70+
This will install all npm dependencies as well as run a full build.
7171

7272
### Tests
7373

@@ -91,14 +91,19 @@ To run code style checks:
9191
grunt test:code-style
9292
```
9393

94+
### Code Coverage Reports
9495

95-
### Code Coverage
96+
To output a code coverage report in HTML:
97+
```
98+
grunt test:coverage"
99+
```
96100

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

103108

104109
### Building Distribution Files

0 commit comments

Comments
 (0)