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

Minor lint tweaks #285

Merged
merged 1 commit into from
Apr 23, 2020
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
19 changes: 14 additions & 5 deletions lib/convertLcovToCoveralls.js
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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