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

test: refactored test suite to use mocks #636

Merged
merged 21 commits into from
Sep 7, 2020

Conversation

eemeli
Copy link
Contributor

@eemeli eemeli commented Jul 25, 2020

The test suite was really slow, to the extent that it made working on the library difficult. So I mostly fixed that here. Where previously it could take multiple minutes for it to complete, it's now at about 15 seconds total on my machine. And if you skip the commit & tag tests (now in test/git.spec.js), it's about 2 seconds. The coverage reporting does add a bit to that, of course.

Mostly the time savings come from not spawning wrapper processes around everything and mocking external dependencies and the filesystem whenever possible. A few tests are also dropped, as they were only testing external dependencies, rather than this library's own code.

The only non-test-code change is to lib/updaters/index.js, where the type-specific updaters are now loaded at the start, rather than on demand; this made mocking the filesystem around them significantly easier.

Code coverage does not change significantly during this change. Tests are split into three files, and moved to the test/ directory.

Eemeli Aro added 20 commits July 24, 2020 13:56
I.e. where test cases call execCliAsync() or require('./index')
This drops the following to tests:
- throws error when not specifying a release type
- exits with error code if "scripts" is not an object
- exits with error code if "skip" is not an object
- handles commit messages longer than 80 characters
- includes merge commits

These were not testing standard-version, but yargs and
conventional-changelog.
This temporarily makes the test suite output rather verbose.
Using a require() with a user-controllable path can be dangerous, as it allows
for directory traversal with an updater.type like '../../../../somewhere/else',
and it makes mocking the filesystem rather difficult.
Sets core.autocrlf false in git config, for Windows environments
@eemeli
Copy link
Contributor Author

eemeli commented Jul 27, 2020

Fixed the remaining Windows test issues.

Where previously the CI timings for the test suite took were 6min for the Ubuntu tests & a bit under 9min on Windows, it now takes 1.5 min & a bit under 4 min, respectively. I also added an npm run test:unit script, which skips the tests that use an actual git directory; that one completes in about 2 seconds.

Copy link
Member

@bcoe bcoe left a comment

Choose a reason for hiding this comment

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

👍 this is a great improvement to the test suite.

@bcoe bcoe changed the title Speed up test suite test: refactored test suite to use mocks Sep 7, 2020
@@ -1,13 +1,17 @@
const path = require('path')
const JSON_BUMP_FILES = require('../../defaults').bumpFiles
const updatersByType = {
Copy link
Member

Choose a reason for hiding this comment

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

I like this refactor but it should probably be in a separate PR?

@bcoe bcoe merged commit 274f694 into conventional-changelog:master Sep 7, 2020
@eemeli eemeli deleted the test-fast branch September 9, 2020 17:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants