|
2 | 2 |
|
3 | 3 | 'use strict' |
4 | 4 |
|
5 | | -var shell = require('shelljs') |
6 | | -var fs = require('fs') |
7 | | -var path = require('path') |
8 | | -var stream = require('stream') |
9 | | -var mockGit = require('mock-git') |
10 | | -var mockery = require('mockery') |
11 | | -var semver = require('semver') |
12 | | -var formatCommitMessage = require('./lib/format-commit-message') |
13 | | -var cli = require('./command') |
14 | | -var standardVersion = require('./index') |
| 5 | +const shell = require('shelljs') |
| 6 | +const fs = require('fs') |
| 7 | +const path = require('path') |
| 8 | +const stream = require('stream') |
| 9 | +const mockGit = require('mock-git') |
| 10 | +const mockery = require('mockery') |
| 11 | +const semver = require('semver') |
| 12 | +const formatCommitMessage = require('./lib/format-commit-message') |
| 13 | +const cli = require('./command') |
| 14 | +const standardVersion = require('./index') |
15 | 15 |
|
16 | 16 | require('chai').should() |
17 | 17 |
|
@@ -45,7 +45,6 @@ function writePackageJson (version, option) { |
45 | 45 | option = option || {} |
46 | 46 | var pkg = Object.assign(option, { version: version }) |
47 | 47 | fs.writeFileSync('package.json', JSON.stringify(pkg), 'utf-8') |
48 | | - delete require.cache[require.resolve(path.join(process.cwd(), 'package.json'))] |
49 | 48 | } |
50 | 49 |
|
51 | 50 | function writeBowerJson (version, option) { |
@@ -96,6 +95,16 @@ function initInTempFolder () { |
96 | 95 | shell.cd('tmp') |
97 | 96 | shell.exec('git init') |
98 | 97 | commit('root-commit') |
| 98 | + ;['package.json', |
| 99 | + 'manifest.json', |
| 100 | + 'bower.json' |
| 101 | + ].forEach(metadata => { |
| 102 | + try { |
| 103 | + delete require.cache[require.resolve(path.join(process.cwd(), metadata))] |
| 104 | + } catch (err) { |
| 105 | + // we haven't loaded the metadata file yet. |
| 106 | + } |
| 107 | + }) |
99 | 108 | writePackageJson('1.0.0') |
100 | 109 | } |
101 | 110 |
|
@@ -746,7 +755,10 @@ describe('standard-version', function () { |
746 | 755 | describe('without a package file to bump', function () { |
747 | 756 | it('should exit with error', function () { |
748 | 757 | shell.rm('package.json') |
749 | | - return require('./index')({ silent: true }) |
| 758 | + return require('./index')({ |
| 759 | + silent: true, |
| 760 | + gitTagFallback: false |
| 761 | + }) |
750 | 762 | .catch((err) => { |
751 | 763 | err.message.should.equal('no package file found') |
752 | 764 | }) |
@@ -886,4 +898,47 @@ describe('standard-version', function () { |
886 | 898 | }) |
887 | 899 | }) |
888 | 900 | }) |
| 901 | + |
| 902 | + describe('.gitignore', () => { |
| 903 | + beforeEach(function () { |
| 904 | + writeBowerJson('1.0.0') |
| 905 | + }) |
| 906 | + |
| 907 | + it('does not update files present in .gitignore', () => { |
| 908 | + fs.writeFileSync('.gitignore', 'bower.json', 'utf-8') |
| 909 | + |
| 910 | + commit('feat: first commit') |
| 911 | + shell.exec('git tag -a v1.0.0 -m "my awesome first release"') |
| 912 | + commit('feat: new feature!') |
| 913 | + return require('./index')({ silent: true }) |
| 914 | + .then(() => { |
| 915 | + JSON.parse(fs.readFileSync('bower.json', 'utf-8')).version.should.equal('1.0.0') |
| 916 | + getPackageVersion().should.equal('1.1.0') |
| 917 | + }) |
| 918 | + }) |
| 919 | + }) |
| 920 | + |
| 921 | + describe('gitTagFallback', () => { |
| 922 | + it('defaults to 1.0.0 if no tags in git history', () => { |
| 923 | + shell.rm('package.json') |
| 924 | + commit('feat: first commit') |
| 925 | + return require('./index')({ silent: true }) |
| 926 | + .then(() => { |
| 927 | + const output = shell.exec('git tag') |
| 928 | + output.stdout.should.include('v1.1.0') |
| 929 | + }) |
| 930 | + }) |
| 931 | + |
| 932 | + it('bases version on last tag, if tags are found', () => { |
| 933 | + shell.rm('package.json') |
| 934 | + shell.exec('git tag -a v5.0.0 -m "a release"') |
| 935 | + shell.exec('git tag -a v3.0.0 -m "another release"') |
| 936 | + commit('feat: another commit') |
| 937 | + return require('./index')({ silent: true }) |
| 938 | + .then(() => { |
| 939 | + const output = shell.exec('git tag') |
| 940 | + output.stdout.should.include('v5.1.0') |
| 941 | + }) |
| 942 | + }) |
| 943 | + }) |
889 | 944 | }) |
0 commit comments