Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Minor lint tweaks (#285)
  • Loading branch information
XhmikosR committed Apr 23, 2020
1 parent ff21930 commit 3647673
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 29 deletions.
19 changes: 14 additions & 5 deletions lib/convertLcovToCoveralls.js
Expand Up @@ -7,19 +7,23 @@ const logger = require('./logger')();

const detailsToCoverage = (length, details) => {
const coverage = new Array(length);

details.forEach(obj => {
coverage[obj.line - 1] = obj.hit;
});

return coverage;
};

const detailsToBranches = details => {
const branches = [];

details.forEach(obj => {
['line', 'block', 'branch', 'taken'].forEach(key => {
branches.push(obj[key] || 0);
});
});

return branches;
};

Expand Down Expand Up @@ -67,7 +71,7 @@ const convertLcovToCoveralls = (input, options, cb) => {
if (options.flag_name) {
postJson.flag_name = options.flag_name;
}

if (options.git) {
postJson.git = options.git;
}
Expand All @@ -79,11 +83,11 @@ const convertLcovToCoveralls = (input, options, cb) => {
if (options.service_name) {
postJson.service_name = options.service_name;
}

if (options.service_number) {
postJson.service_number = options.service_number;
}

if (options.service_job_id) {
postJson.service_job_id = options.service_job_id;
}
Expand All @@ -107,6 +111,7 @@ const convertLcovToCoveralls = (input, options, cb) => {
postJson.source_files.push(convertLcovFileObject(file, filepath));
}
});

return cb(null, postJson);
});
};
Expand Down Expand Up @@ -134,7 +139,7 @@ module.exports = convertLcovToCoveralls;
example output from lcov parser:
[
[
{
"file": "index.js",
"lines": {
Expand All @@ -156,6 +161,10 @@ example output from lcov parser:
{
"line": 5,
"hit": 1
},
}
]
}
}
]
*/
3 changes: 2 additions & 1 deletion lib/getOptions.js
Expand Up @@ -180,6 +180,7 @@ const getBaseOptions = cb => {
if (coveralls_yaml_conf.repo_token) {
options.repo_token = coveralls_yaml_conf.repo_token;
}

if (coveralls_yaml_conf.service_name) {
options.service_name = coveralls_yaml_conf.service_name;
}
Expand All @@ -190,7 +191,7 @@ const getBaseOptions = cb => {
options.repo_token = process.env.COVERALLS_REPO_TOKEN;
}

if ('travis-pro' === options.service_name && !options.repo_token) {
if (options.service_name === 'travis-pro' && !options.repo_token) {
logger.warn('Repo token could not be determined. Continuing without it. ' +
'This is necessary for private repos only, so may not be an issue at all.');
}
Expand Down
2 changes: 1 addition & 1 deletion test/convertLcovToCoveralls.js
Expand Up @@ -93,7 +93,7 @@ describe('convertLcovToCoveralls', () => {
fs.existsSync = originalExistsSync;

should.not.exist(err);
output.source_files[0].name.should.equal(path.posix.join("svgo", "config.js"));
output.source_files[0].name.should.equal(path.posix.join('svgo', 'config.js'));
done();
});
});
Expand Down
50 changes: 28 additions & 22 deletions test/getOptions.js
Expand Up @@ -134,10 +134,10 @@ describe('getOptions', () => {
it('should set service_name if it exists', done => {
testServiceName(getOptions, done);
});
it ("should set service_number if it exists", done => {
it('should set service_number if it exists', done => {
testServiceNumber(getOptions, done);
});
it("should set service_pull_request if it exists", done => {
it('should set service_pull_request if it exists', done => {
testServicePullRequest(getOptions, done);
});
it('should set service_name and service_job_id if it\'s running on travis-ci', done => {
Expand All @@ -164,7 +164,7 @@ describe('getOptions', () => {
it('should set service_name and service_job_id if it\'s running on Gitlab', done => {
testGitlab(getOptions, done);
});
it ("should set service_name and service_job_id if it's running on AppVeyor", done => {
it('should set service_name and service_job_id if it\'s running on AppVeyor', done => {
testAppVeyor(getOptions, done);
});
it('should set service_name and service_job_id if it\'s running via Surf', done => {
Expand Down Expand Up @@ -565,26 +565,32 @@ const testGitlab = (sut, done) => {
});
};

const testAppVeyor = function(sut, done) {
const testAppVeyor = (sut, done) => {
process.env.APPVEYOR = true;
process.env.APPVEYOR_BUILD_ID = "1234";
process.env.APPVEYOR_BUILD_NUMBER = "5678";
process.env.APPVEYOR_REPO_COMMIT = "e3e3e3e3e3e3e3e3e";
process.env.APPVEYOR_REPO_BRANCH = "feature";

sut(function(err, options){
options.service_name.should.equal("appveyor");
options.service_job_id.should.equal("1234");
options.service_job_number.should.equal("5678");
options.git.should.eql({ head:
{ id: 'e3e3e3e3e3e3e3e3e',
author_name: 'Unknown Author',
author_email: '',
committer_name: 'Unknown Committer',
committer_email: '',
message: 'Unknown Commit Message' },
branch: 'feature',
remotes: [] });
process.env.APPVEYOR_BUILD_ID = '1234';
process.env.APPVEYOR_BUILD_NUMBER = '5678';
process.env.APPVEYOR_REPO_COMMIT = 'e3e3e3e3e3e3e3e3e';
process.env.APPVEYOR_REPO_BRANCH = 'feature';

const git = {
head: {
id: 'e3e3e3e3e3e3e3e3e',
author_name: 'Unknown Author',
author_email: '',
committer_name: 'Unknown Committer',
committer_email: '',
message: 'Unknown Commit Message'
},
branch: 'feature',
remotes: []
};

sut((err, options) => {
should.not.exist(err);
options.service_name.should.equal('appveyor');
options.service_job_id.should.equal('1234');
options.service_job_number.should.equal('5678');
options.git.should.eql(git);
done();
});
};
Expand Down

0 comments on commit 3647673

Please sign in to comment.