Skip to content

Commit

Permalink
fix: print version number that updater.writeVersion returns
Browse files Browse the repository at this point in the history
  • Loading branch information
brettdh committed Oct 11, 2020
1 parent 0a801d9 commit b48389d
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 3 deletions.
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 @@ -66,6 +66,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
}

0 comments on commit b48389d

Please sign in to comment.