diff options
| author | Nick Merwin <[email protected]> | 2019-11-20 17:05:48 -0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2019-11-20 17:05:48 -0800 |
| commit | 336123fe05e7f80d79fc8522b4ff21a60fffe77c (patch) | |
| tree | 97e5b9343471fc73ddf4ffb20cd71ca58367d6c6 /lib/convertLcovToCoveralls.js | |
| parent | eba01a29c69f28ffd7f50556492a43b5ba2486d7 (diff) | |
| download | node-coveralls-336123fe05e7f80d79fc8522b4ff21a60fffe77c.tar.xz node-coveralls-336123fe05e7f80d79fc8522b4ff21a60fffe77c.zip | |
ES6
* remove unused variables
* move `require`s at the top
* check for prototype built-ins
* run in strict mode
* always check for error values in tests
* make style consistent
* mark Node.js 6 as the minimum supported version in package.json
* Use the arrow return syntax
* logger.js: use `Boolean` to make the intention clearer.
* Use the rest params instead of arguments.
* test/getOptions.js: beautify git data.
* Update logger.js
Remove `hasDebugEnvVariable` function; it's just a `process.env` check
* Create .jshintrc
Diffstat (limited to 'lib/convertLcovToCoveralls.js')
| -rw-r--r-- | lib/convertLcovToCoveralls.js | 102 |
1 files changed, 57 insertions, 45 deletions
diff --git a/lib/convertLcovToCoveralls.js b/lib/convertLcovToCoveralls.js index 521e749..a6d5665 100644 --- a/lib/convertLcovToCoveralls.js +++ b/lib/convertLcovToCoveralls.js @@ -1,90 +1,104 @@ -var TRAVIS_JOB_ID = process.env.TRAVIS_JOB_ID || 'unknown'; -var fs = require('fs'); -var lcovParse = require('lcov-parse'); -var path = require('path'); -var logger = require('./logger')(); - -var detailsToCoverage = function(length, details){ - var coverage = new Array(length); - details.forEach(function(obj){ +'use strict'; + +const fs = require('fs'); +const path = require('path'); +const lcovParse = require('lcov-parse'); +const logger = require('./logger')(); + +const detailsToCoverage = (length, details) => { + const coverage = new Array(length); + details.forEach(obj => { coverage[obj.line - 1] = obj.hit; }); return coverage; }; -var detailsToBranches = function(details){ - var branches = []; - details.forEach(function(obj){ - ['line','block','branch','taken'].forEach(function(key){ +const detailsToBranches = details => { + const branches = []; + details.forEach(obj => { + ['line', 'block', 'branch', 'taken'].forEach(key => { branches.push(obj[key] || 0); }); }); return branches; }; -var convertLcovFileObject = function(file, filepath){ - var rootpath = filepath; +const convertLcovFileObject = (file, filepath) => { + const rootpath = filepath; filepath = path.resolve(rootpath, file.file); - var source = fs.readFileSync(filepath, 'utf8'); - var lines = source.split("\n"); - var coverage = detailsToCoverage(lines.length, file.lines.details); - var branches = detailsToBranches(file.branches.details); - return { name : path.relative(rootpath, path.resolve(rootpath, file.file)).split( path.sep ).join( "/" ), - source : source, - coverage : coverage, - branches : branches }; + const source = fs.readFileSync(filepath, 'utf8'); + const lines = source.split('\n'); + const coverage = detailsToCoverage(lines.length, file.lines.details); + const branches = detailsToBranches(file.branches.details); + + return { + name: path.relative(rootpath, path.resolve(rootpath, file.file)).split(path.sep).join('/'), + source, + coverage, + branches + }; }; -var cleanFilePath = function(file) { - if (file.indexOf('!') > -1) { - var regex = /^(.*!)(.*)$/g; - var matches = regex.exec(file); - return matches[matches.length-1]; +const cleanFilePath = file => { + if (file.includes('!')) { + const regex = /^(.*!)(.*)$/g; + const matches = regex.exec(file); + return matches[matches.length - 1]; } return file; }; -var convertLcovToCoveralls = function(input, options, cb){ - var filepath = options.filepath || ''; - logger.debug("in: ", filepath); +const convertLcovToCoveralls = (input, options, cb) => { + let filepath = options.filepath || ''; + logger.debug('in: ', filepath); filepath = path.resolve(process.cwd(), filepath); - lcovParse(input, function(err, parsed){ - if (err){ - logger.error("error from lcovParse: ", err); - logger.error("input: ", input); + lcovParse(input, (err, parsed) => { + if (err) { + logger.error('error from lcovParse: ', err); + logger.error('input: ', input); return cb(err); } - var postJson = { - source_files : [] + + const postJson = { + source_files: [] }; - if (options.git){ + + if (options.git) { postJson.git = options.git; } - if (options.run_at){ + + if (options.run_at) { postJson.run_at = options.run_at; } - if (options.service_name){ + + if (options.service_name) { postJson.service_name = options.service_name; } - if (options.service_job_id){ + + if (options.service_job_id) { postJson.service_job_id = options.service_job_id; } + if (options.service_pull_request) { postJson.service_pull_request = options.service_pull_request; } + if (options.repo_token) { postJson.repo_token = options.repo_token; } + if (options.parallel) { postJson.parallel = options.parallel; } + if (options.service_pull_request) { postJson.service_pull_request = options.service_pull_request; } - parsed.forEach(function(file){ + + parsed.forEach(file => { file.file = cleanFilePath(file.file); - var currentFilePath = path.resolve(filepath, file.file); + const currentFilePath = path.resolve(filepath, file.file); if (fs.existsSync(currentFilePath)) { postJson.source_files.push(convertLcovFileObject(file, filepath)); } @@ -97,7 +111,6 @@ module.exports = convertLcovToCoveralls; /* example coveralls json file - { "service_job_id": "1234567890", "service_name": "travis-ci", @@ -115,7 +128,6 @@ module.exports = convertLcovToCoveralls; ] } - example output from lcov parser: [ |
