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

fix: print version number that updater.writeVersion returns #11

Merged
merged 1 commit into from
May 25, 2022
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
6 changes: 4 additions & 2 deletions lib/lifecycles/bump.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,15 +149,17 @@ function updateConfigs (args, newVersion) {

if (!stat.isFile()) return
const contents = fs.readFileSync(configPath, 'utf8')
const newContents = updater.updater.writeVersion(contents, newVersion)
const realNewVersion = updater.updater.readVersion(newContents)
checkpoint(
args,
'bumping version in ' + updater.filename + ' from %s to %s',
[updater.updater.readVersion(contents), newVersion]
[updater.updater.readVersion(contents), realNewVersion]
)
writeFile(
args,
configPath,
updater.updater.writeVersion(contents, newVersion)
newContents
)
// flag any config files that we modify the version # for
// as having been updated.
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
"mockery": "^2.1.0",
"nyc": "^14.1.1",
"shelljs": "^0.8.4",
"std-mocks": "^1.0.1"
"std-mocks": "^1.0.1",
"strip-ansi": "^6.0.0"
}
}
32 changes: 32 additions & 0 deletions test/core.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const { Readable } = require('stream')
const mockFS = require('mock-fs')
const mockery = require('mockery')
const stdMocks = require('std-mocks')
const stripAnsi = require('strip-ansi')

const cli = require('../command')
const formatCommitMessage = require('../lib/format-commit-message')
Expand Down Expand Up @@ -526,6 +527,37 @@ describe('standard-version', function () {
})
fs.readFileSync('VERSION_TRACKER.txt', 'utf-8').should.equal('1.1.0')
})

it('displays the new version from custom bumper with --dry-run', async function () {
const updater = 'increment-updater.js'
const updaterModule = require('./mocks/updater/increment-updater')
mock({
bump: 'minor',
fs: {
'increment-version.txt': fs.readFileSync(
'./test/mocks/increment-version.txt'
)
}
})
mockery.registerMock(resolve(process.cwd(), updater), updaterModule)

const origInfo = console.info
const capturedOutput = []
console.info = (...args) => {
capturedOutput.push(...args)
origInfo(...args)
}
try {
await exec({
bumpFiles: [{ filename: 'increment-version.txt', updater: 'increment-updater.js' }],
dryRun: true
})
const logOutput = capturedOutput.join(' ')
stripAnsi(logOutput).should.include('bumping version in increment-version.txt from 1 to 2')
} finally {
console.info = origInfo
}
})
})

describe('custom `packageFiles` support', function () {
Expand Down
1 change: 1 addition & 0 deletions test/mocks/increment-version.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1
7 changes: 7 additions & 0 deletions test/mocks/updater/increment-updater.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports.readVersion = function (contents) {
return Number.parseInt(contents)
}

module.exports.writeVersion = function (contents, version) {
return this.readVersion(contents) + 1
}