Skip to content

Commit f2e83bf

Browse files
authored
Merge pull request #11 from brettdh/fix-dry-run-version
fix: print version number that updater.writeVersion returns
2 parents 08a0121 + d0673e7 commit f2e83bf

File tree

5 files changed

+46
-3
lines changed

5 files changed

+46
-3
lines changed

lib/lifecycles/bump.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -152,15 +152,17 @@ function updateConfigs (args, newVersion) {
152152

153153
if (!stat.isFile()) return
154154
const contents = fs.readFileSync(configPath, 'utf8')
155+
const newContents = updater.updater.writeVersion(contents, newVersion)
156+
const realNewVersion = updater.updater.readVersion(newContents)
155157
checkpoint(
156158
args,
157159
'bumping version in ' + updater.filename + ' from %s to %s',
158-
[updater.updater.readVersion(contents), newVersion]
160+
[updater.updater.readVersion(contents), realNewVersion]
159161
)
160162
writeFile(
161163
args,
162164
configPath,
163-
updater.updater.writeVersion(contents, newVersion)
165+
newContents
164166
)
165167
// flag any config files that we modify the version # for
166168
// as having been updated.

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
"mockery": "^2.1.0",
6565
"nyc": "^15.1.0",
6666
"shelljs": "^0.8.4",
67-
"std-mocks": "^1.0.1"
67+
"std-mocks": "^1.0.1",
68+
"strip-ansi": "^6.0.0"
6869
}
6970
}

test/core.spec.js

+32
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const { Readable } = require('stream')
99
const mockFS = require('mock-fs')
1010
const mockery = require('mockery')
1111
const stdMocks = require('std-mocks')
12+
const stripAnsi = require('strip-ansi')
1213

1314
const cli = require('../command')
1415
const formatCommitMessage = require('../lib/format-commit-message')
@@ -572,6 +573,37 @@ describe('commit-and-tag-version', function () {
572573
})
573574
fs.readFileSync('VERSION_TRACKER.txt', 'utf-8').should.equal('1.1.0')
574575
})
576+
577+
it('displays the new version from custom bumper with --dry-run', async function () {
578+
const updater = 'increment-updater.js'
579+
const updaterModule = require('./mocks/updater/increment-updater')
580+
mock({
581+
bump: 'minor',
582+
fs: {
583+
'increment-version.txt': fs.readFileSync(
584+
'./test/mocks/increment-version.txt'
585+
)
586+
}
587+
})
588+
mockery.registerMock(resolve(process.cwd(), updater), updaterModule)
589+
590+
const origInfo = console.info
591+
const capturedOutput = []
592+
console.info = (...args) => {
593+
capturedOutput.push(...args)
594+
origInfo(...args)
595+
}
596+
try {
597+
await exec({
598+
bumpFiles: [{ filename: 'increment-version.txt', updater: 'increment-updater.js' }],
599+
dryRun: true
600+
})
601+
const logOutput = capturedOutput.join(' ')
602+
stripAnsi(logOutput).should.include('bumping version in increment-version.txt from 1 to 2')
603+
} finally {
604+
console.info = origInfo
605+
}
606+
})
575607
})
576608

577609
describe('custom `packageFiles` support', function () {

test/mocks/increment-version.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1
+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module.exports.readVersion = function (contents) {
2+
return Number.parseInt(contents)
3+
}
4+
5+
module.exports.writeVersion = function (contents, version) {
6+
return this.readVersion(contents) + 1
7+
}

0 commit comments

Comments
 (0)