Skip to content

Commit

Permalink
Add eslint, clean code and remove dependency to underscore to fix tes…
Browse files Browse the repository at this point in the history
…t-packages issues
  • Loading branch information
serut committed May 13, 2016
1 parent 7132031 commit d8191cb
Show file tree
Hide file tree
Showing 15 changed files with 102 additions and 90 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
assets
12 changes: 12 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"parserOptions": {
"ecmaVersion": 6,
"sourceType": "module",
"ecmaFeatures": {
"jsx": true
}
},
"rules": {
"semi": 2
}
}
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ before_install:
# Install spacejam
- npm install -g https://github.com/serut/spacejam/tarball/master
- npm install -g https://github.com/nickmerwin/node-coveralls/tarball/master
- npm install -g eslint

script:
- spacejam test-packages ./ --loglevel debug --coverage && cat lcov.info | coveralls
- eslint .
12 changes: 6 additions & 6 deletions client/methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ Meteor.sendCoverage = function (callback) {
callback(stats, arguments);
}
}
})
});
}
}
}
};

/**
* Usage: Meteor.exportCoverage(null, function(err) {console.log(err)})
Expand All @@ -50,8 +50,8 @@ Meteor.exportCoverage = function (type, callback) {
error: function() {
callback(arguments);
}
})
}
});
};

/**
* Usage: Meteor.importCoverage(function(err) {console.log(err)})
Expand All @@ -66,5 +66,5 @@ Meteor.importCoverage = function (callback) {
error: function() {
callback(arguments);
}
})
}
});
};
7 changes: 3 additions & 4 deletions conf/default-coverage.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
"public": [
]
},
"serverside": {

}
"serverside": [
]
}
}
}
8 changes: 3 additions & 5 deletions package.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package.describe({
name: 'lmieulet:meteor-coverage',
version: '0.5.0',
version: '0.6.0',
summary: 'Server and client coverage for Meteor',
git: 'https://github.com/serut/meteor-coverage',
documentation: 'README.md',
Expand All @@ -9,8 +9,7 @@ Package.describe({

Package.onUse(function(api) {
api.versionsFrom('METEOR@1.3.1');
api.use(['ecmascript', 'meteorhacks:picker@1.0.3', 'underscore'], 'server');

api.use(['ecmascript', 'meteorhacks:picker@1.0.3'], 'server');

api.use("modules");
// Add datasets
Expand Down Expand Up @@ -51,9 +50,8 @@ Npm.depends({
});

Package.onTest(function (api) {
api.use('lmieulet:meteor-coverage');
api.use(['lmieulet:meteor-coverage', 'tinytest'], ['server', 'client']);
api.use('jquery', 'client');
api.use('tinytest');

api.addFiles('tests/methods.js', 'client');
api.addFiles([
Expand Down
4 changes: 2 additions & 2 deletions server/conf.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
IS_COVERAGE_ACTIVE = process.env["COVERAGE"] === "1"
IS_COVERAGE_ACTIVE = process.env["COVERAGE"] === "1";
if (IS_COVERAGE_ACTIVE) {
COVERAGE_APP_FOLDER = process.env["COVERAGE_APP_FOLDER"] || '/SET/ENV/COVERAGE_APP_FOLDER/OR/READ/README/';
var fs = Npm.require('fs'),
Expand All @@ -20,6 +20,6 @@ if (IS_COVERAGE_ACTIVE) {
}
//TODO validate the json
return JSON.parse(fileContent);
}
};
Conf = get();
}
30 changes: 15 additions & 15 deletions server/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ if (IS_COVERAGE_ACTIVE) {
var opts = render_getReportOpts(prefix);
render_alterFS(res);
var context = render_getContext(res);
var report = ReportImpl.create('html', opts)
var report = ReportImpl.create('html', opts);
if (filePath) {
var child = CoverageData.getFileReport(coverage, filePath);
report.onDetail(child, context);
} else {
var root = CoverageData.getTreeReport(coverage)
var root = CoverageData.getTreeReport(coverage);
report.onSummary(root, context);
}
}
Expand All @@ -64,7 +64,7 @@ if (IS_COVERAGE_ACTIVE) {
function render_alterFS(res) {
res.close = function() {
this.end();
}
};
}


Expand All @@ -85,7 +85,7 @@ if (IS_COVERAGE_ACTIVE) {
return prefix + "asset/" + name;
}
}
}
};
}

function mergeCoverageWith(obj) {
Expand All @@ -99,14 +99,14 @@ if (IS_COVERAGE_ACTIVE) {
}

function exportFile (res, type) {
Log.info("export coverage using the following format:", type)
Log.info("export coverage using the following format:", type);

switch (type) {
case 'lcovonly':
var opts = exportFile_getOpts(type),
report = ReportImpl.create(type, opts);
report.file = path.join(COVERAGE_APP_FOLDER, report.file);
var context = exportFile_getContext(report.file)
var context = exportFile_getContext(report.file);

break;
}
Expand Down Expand Up @@ -158,18 +158,18 @@ if (IS_COVERAGE_ACTIVE) {
reportPath = path.join(COVERAGE_APP_FOLDER, reportFilename);
fs.writeFile(reportPath, coverageReport, function (err) {
if (err) {
throw "failed to write report file: "+reportPath
throw "failed to write report file: "+reportPath;
}
res.end('Thanks !');
})
});
break;
}
}
function exportFile_getOpts(type) {
var opts = IS_COVERAGE_VERBOSE ? {verbose: true} : {};
switch (type) {
case 'teamcity':
opts.file = 'teamcity.file'
opts.file = 'teamcity.file';
}
return opts;
}
Expand All @@ -196,15 +196,15 @@ if (IS_COVERAGE_ACTIVE) {
}

function importCoverage (res){
Log.info("import coverage")
Log.info("import coverage");
var reportPath = path.join(COVERAGE_APP_FOLDER, reportFilename);
fs.exists(reportPath, function(exists) {
if (!exists) {
throw "report file not found: "+reportPath
throw "report file not found: "+reportPath;
}
fs.readFile(reportPath, 'utf8', function (err, fileContent) {
if (err) {
throw "failed to read report file: "+reportPath
throw "failed to read report file: "+reportPath;
}
var coverageObj = JSON.parse(fileContent);
for (var property in coverageObj) {
Expand All @@ -213,14 +213,14 @@ if (IS_COVERAGE_ACTIVE) {
}
res.end('Thanks !');
}
})
})
});
});
}

Core = {
render: render,
mergeClientCoverage: mergeCoverageWith,
exportFile: exportFile,
importCoverage: importCoverage
}
};
}
14 changes: 7 additions & 7 deletions server/coverage-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ if (IS_COVERAGE_ACTIVE) {
CoverageData = {
filterCoverageReport: function(report) {
if (report.data == undefined) {
throw "Invalid report"
throw "Invalid report";
}
var newData = {};
for (var property in report.data) {
if (report.data.hasOwnProperty(property)) {
if (this.isAccepted(property)) {
//Log.info('isAccepted', property)
newData[property] = report.data[property]
newData[property] = report.data[property];
} else {
Log.info('isRefused', property)
Log.info('isRefused', property);
}
}
}
Expand Down Expand Up @@ -76,7 +76,7 @@ if (IS_COVERAGE_ACTIVE) {
},
getFileReport: function(coverage, filePath) {
var coverageMap = this.getReport(coverage);
var node = Report.summarizers.flat(coverageMap)
var node = Report.summarizers.flat(coverageMap);
var childs = node.getRoot().getChildren();
var child = undefined;
for (var i = 0; i < childs.length; i++) {
Expand All @@ -88,13 +88,13 @@ if (IS_COVERAGE_ACTIVE) {
},
getTreeReport: function (coverage) {
var coverageMap = this.getReport(coverage);
var node = Report.summarizers.flat(coverageMap)
var node = Report.summarizers.flat(coverageMap);
return node.getRoot();
},
getLcovonlyReport: function (coverage) {
coverageMap = this.getReport(coverage);
var node = Report.summarizers.flat(coverageMap)
var node = Report.summarizers.flat(coverageMap);
return node.getRoot().getChildren();
}
}
};
}
36 changes: 18 additions & 18 deletions server/handlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ if (IS_COVERAGE_ACTIVE) {
showCoverage = function (params, req, res, next) {
var url = params.query.p;
Core.render(url, res, '/coverage/');
}
};

getAsset = function(params, req, res, next) {
var assetsDir = path.join(path.resolve('.'), "assets/packages/lmieulet_meteor-coverage/assets/"),
Expand All @@ -27,15 +27,15 @@ if (IS_COVERAGE_ACTIVE) {
});
}
});
}
};

addClientCoverage = function (params, req, res, next) {
var body = req.body;
if (! body) {
res.writeHead(400);
res.end();
}
var clientCoverage
var clientCoverage;
for (var property in body) {
if (body.hasOwnProperty(property)) {
clientCoverage = body[property];
Expand All @@ -48,30 +48,30 @@ if (IS_COVERAGE_ACTIVE) {
res.writeHead(400);
res.end("Nothing has been imported");
}
}
};

exportFile = function (params, req, res, next) {
var _type = params.type,
allowedTypes = ['cobertura', 'html', 'json', 'json-summary', 'lcov', 'none', 'teamcity', 'text', 'text-lcov', 'text-summary', 'lcovonly', 'coverage'];
type = (_.contains(allowedTypes, _type)) ? _type : 'coverage';
type = (allowedTypes.indexOf(_type) > -1) ? _type : 'coverage';

try {
Core.exportFile(res, type);
} catch (e) {
Log.error("Failed to export", e, e.stack)
Log.error("Failed to export", e, e.stack);
res.writeHead(400);
res.end("Nothing has been export");
}
}
};
importCoverage = function (params, req, res, next) {
try {
Core.importCoverage(res);
} catch (e) {
Log.error("Failed to import", e, e.stack)
Log.error("Failed to import", e, e.stack);
res.writeHead(400);
res.end("No file has been import");
}
}
};

instrumentClientJs = function(params, req, res, next) {
var fileurl = req.url.split('?')[0];
Expand All @@ -80,32 +80,32 @@ if (IS_COVERAGE_ACTIVE) {
pathLabel;
// Either a package
if (req.url.indexOf('/packages') == 0) {
path = '../web.browser'
path = '../web.browser';
pathLabel = path + fileurl;
} else if (req.url.indexOf('/app') == 0){
// Or the app/app.js
path = '../web.browser'
path = '../web.browser';
pathLabel = path + fileurl;
} else {
// Or a public file
path = '../web.browser/app'
path = '../web.browser/app';
pathLabel = path + fileurl;
}
res.setHeader('Content-type', 'application/javascript')
res.setHeader('Content-type', 'application/javascript');
fs.exists(path + fileurl, function(exists) {
if (!exists) return next();
fs.readFile(path + fileurl, 'utf8', function (err, fileContent) {
if (err) return next();
Instrumenter.instrumentJs(fileContent, pathLabel, function(err, data) {
if (err) throw err;
res.end(data);
})
})
})
});
});
});
} else {
next();
}
}
};

Handlers = {
showCoverage: showCoverage,
Expand All @@ -114,6 +114,6 @@ if (IS_COVERAGE_ACTIVE) {
instrumentClientJs: instrumentClientJs,
exportFile: exportFile,
importCoverage: importCoverage
}
};

}
Loading

0 comments on commit d8191cb

Please sign in to comment.