From d0673e739ed69e97c4dbb9b7d476a47e7243f4f8 Mon Sep 17 00:00:00 2001 From: Brett Higgins Date: Sat, 10 Oct 2020 21:27:41 -0400 Subject: [PATCH] fix: print version number that updater.writeVersion returns Closes expo-community/standard-version-expo#18. Closes expo-community/standard-version-expo#10. --- lib/lifecycles/bump.js | 6 +++-- package.json | 3 ++- test/core.spec.js | 32 +++++++++++++++++++++++++ test/mocks/increment-version.txt | 1 + test/mocks/updater/increment-updater.js | 7 ++++++ 5 files changed, 46 insertions(+), 3 deletions(-) create mode 100644 test/mocks/increment-version.txt create mode 100644 test/mocks/updater/increment-updater.js diff --git a/lib/lifecycles/bump.js b/lib/lifecycles/bump.js index 119025fb0..b769203c1 100644 --- a/lib/lifecycles/bump.js +++ b/lib/lifecycles/bump.js @@ -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. diff --git a/package.json b/package.json index b28260895..6064593cc 100644 --- a/package.json +++ b/package.json @@ -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" } } diff --git a/test/core.spec.js b/test/core.spec.js index 22d2b8e2c..ec8a6f383 100644 --- a/test/core.spec.js +++ b/test/core.spec.js @@ -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') @@ -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 () { diff --git a/test/mocks/increment-version.txt b/test/mocks/increment-version.txt new file mode 100644 index 000000000..d00491fd7 --- /dev/null +++ b/test/mocks/increment-version.txt @@ -0,0 +1 @@ +1 diff --git a/test/mocks/updater/increment-updater.js b/test/mocks/updater/increment-updater.js new file mode 100644 index 000000000..823fa0195 --- /dev/null +++ b/test/mocks/updater/increment-updater.js @@ -0,0 +1,7 @@ +module.exports.readVersion = function (contents) { + return Number.parseInt(contents) +} + +module.exports.writeVersion = function (contents, version) { + return this.readVersion(contents) + 1 +}