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

Improve Code Coverage #562

Merged
merged 12 commits into from
Feb 5, 2018
Merged

Conversation

brandon93s
Copy link
Contributor

@brandon93s brandon93s commented Jan 15, 2018

Goals:

  • Improve code coverage
  • Start testing some classes directly
  • Add sinon to begin mocking

Notes:

  • There is some low hanging fruit, namely testing failure and exception branches, that can be tested.

src/Logger.js Outdated
@@ -108,6 +108,10 @@ class Logger {
this.lines++;
}
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Internal _log function to help with stubbing, and to avoid stubbing console.log directly (nasty side-effects).

@@ -1,15 +1,17 @@
let serverErrorList = {
const serverErrorList = {
EACCES: "You don't have access to bind the server to port {port}.",
EADDRINUSE: 'There is already a process listening on port {port}.'
};

function serverErrors(err, port) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code was previously built to handle unknown errors if (!desc) ..., but an exception on the .replace call would prevent this code path from ever executing.

Exposed by tests, fixed.

src/utils/fs.js Outdated
@@ -5,6 +5,7 @@ const mkdirp = require('mkdirp');
exports.readFile = promisify(fs.readFile);
exports.writeFile = promisify(fs.writeFile);
exports.stat = promisify(fs.stat);
exports.unlink = promisify(fs.unlink);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See notes in fs-cache tests.

@codecov-io
Copy link

codecov-io commented Jan 15, 2018

Codecov Report

Merging #562 into master will increase coverage by 4.91%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #562      +/-   ##
==========================================
+ Coverage   89.24%   94.15%   +4.91%     
==========================================
  Files          64       64              
  Lines        2017     2019       +2     
==========================================
+ Hits         1800     1901     +101     
+ Misses        217      118      -99
Impacted Files Coverage Δ
src/assets/WebManifestAsset.js 78.57% <ø> (ø) ⬆️
src/Logger.js 98.41% <100%> (+50.02%) ⬆️
src/utils/fs.js 100% <100%> (ø) ⬆️
src/utils/customErrors.js 100% <100%> (+66.66%) ⬆️
src/Bundler.js 91.48% <0%> (+2.59%) ⬆️
src/Asset.js 97.67% <0%> (+3.48%) ⬆️
src/utils/loadPlugins.js 100% <0%> (+10.52%) ⬆️
src/utils/generateCertificate.js 100% <0%> (+20.58%) ⬆️
src/utils/prettyError.js 100% <0%> (+21.42%) ⬆️
... and 1 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ab713a3...16d796d. Read the comment docs.

assert.equal(cached, null);
});

it('should remove file on delete', async () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cache.delete was not working due to fs.unlink missing from the fs utility. The implementation catches the error and fails silently. Does not appear to be used today, but is now working correctly.

Exposed by tests, fixed.

assert.equal(cached.dependencies[0].mtime, mtime);
assert.equal(cached.dependencies[1].mtime, undefined);
});

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added tests for #514.

@@ -1,7 +1,7 @@
module.exports = {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gives us coverage on the array branch of loadPlugins:

if (Array.isArray(plugins)) {
return await Promise.all(
plugins.map(async p => await loadPlugin(p, relative)).filter(Boolean)
);

Other posthtmlrc is object, for complete coverage.

@brandon93s brandon93s changed the title [WIP] Improve Code Coverage Improve Code Coverage Jan 15, 2018
@devongovett
Copy link
Member

Awesome, thanks for working on this! 🥇

@brandon93s
Copy link
Contributor Author

Tests have been updated with master. Notes & explanations can be found in the current and outdated self-review.

Copy link
Member

@devongovett devongovett left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome! 🏆

@devongovett devongovett merged commit fc641fa into parcel-bundler:master Feb 5, 2018
@brandon93s brandon93s deleted the coverage branch February 18, 2018 18:54
devongovett pushed a commit that referenced this pull request Oct 15, 2018
devongovett pushed a commit that referenced this pull request Oct 15, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants