|
1 | 1 | const path = require('path'); |
2 | 2 | const test = require('ava'); |
3 | | -const {outputFile, readFile} = require('fs-extra'); |
| 3 | +const {outputFile, readFile, pathExists} = require('fs-extra'); |
4 | 4 | const {stub} = require('sinon'); |
5 | 5 | const tempy = require('tempy'); |
6 | 6 | const prepare = require('../lib/prepare.js'); |
@@ -90,3 +90,76 @@ test.serial('Create new changelog with title if specified', async (t) => { |
90 | 90 |
|
91 | 91 | t.is((await readFile(changelogPath)).toString(), `${changelogTitle}\n\n${notes}\n`); |
92 | 92 | }); |
| 93 | + |
| 94 | +test.serial('Skip creation of changelog if skipOnPrerelease is set on prerelease branches', async (t) => { |
| 95 | + const cwd = tempy.directory(); |
| 96 | + const notes = 'Test release note'; |
| 97 | + const changelogFile = 'CHANGELOG.md'; |
| 98 | + const changelogPath = path.resolve(cwd, changelogFile); |
| 99 | + |
| 100 | + await prepare( |
| 101 | + {skipOnPrerelease: true}, |
| 102 | + {cwd, nextRelease: {notes}, branch: {type: 'prerelease', main: false}, logger: t.context.logger} |
| 103 | + ); |
| 104 | + |
| 105 | + // Verify the content of the CHANGELOG.md |
| 106 | + t.is(await pathExists(changelogPath), false); |
| 107 | + t.deepEqual(t.context.log.args[0], [ |
| 108 | + 'Skipping because branch is a prerelease branch and option skipOnPrerelease is active', |
| 109 | + ]); |
| 110 | +}); |
| 111 | + |
| 112 | +test('Skip update of changelog if skipOnPrerelease is set on prerelease branches', async (t) => { |
| 113 | + const cwd = tempy.directory(); |
| 114 | + const notes = 'Test release note'; |
| 115 | + const changelogFile = 'CHANGELOG.md'; |
| 116 | + const changelogPath = path.resolve(cwd, changelogFile); |
| 117 | + await outputFile(changelogPath, 'Initial CHANGELOG'); |
| 118 | + |
| 119 | + await prepare( |
| 120 | + {skipOnPrerelease: true}, |
| 121 | + {cwd, nextRelease: {notes}, branch: {type: 'prerelease', main: false}, logger: t.context.logger} |
| 122 | + ); |
| 123 | + |
| 124 | + // Verify the content of the CHANGELOG.md |
| 125 | + t.is((await readFile(changelogPath)).toString(), `Initial CHANGELOG`); |
| 126 | + t.deepEqual(t.context.log.args[0], [ |
| 127 | + 'Skipping because branch is a prerelease branch and option skipOnPrerelease is active', |
| 128 | + ]); |
| 129 | +}); |
| 130 | + |
| 131 | +test('Skip update of changelog if skipOnPrerelease is set on release branches but it is not main', async (t) => { |
| 132 | + const cwd = tempy.directory(); |
| 133 | + const notes = 'Test release note'; |
| 134 | + const changelogFile = 'CHANGELOG.md'; |
| 135 | + const changelogPath = path.resolve(cwd, changelogFile); |
| 136 | + await outputFile(changelogPath, 'Initial CHANGELOG'); |
| 137 | + |
| 138 | + await prepare( |
| 139 | + {skipOnPrerelease: true}, |
| 140 | + {cwd, nextRelease: {notes}, branch: {type: 'release', main: false}, logger: t.context.logger} |
| 141 | + ); |
| 142 | + |
| 143 | + // Verify the content of the CHANGELOG.md |
| 144 | + t.is((await readFile(changelogPath)).toString(), `Initial CHANGELOG`); |
| 145 | + t.deepEqual(t.context.log.args[0], [ |
| 146 | + 'Skipping because branch is a prerelease branch and option skipOnPrerelease is active', |
| 147 | + ]); |
| 148 | +}); |
| 149 | + |
| 150 | +test('Ensure update of changelog if skipOnPrerelease is not set on prerelease branches', async (t) => { |
| 151 | + const cwd = tempy.directory(); |
| 152 | + const notes = 'Test release note'; |
| 153 | + const changelogFile = 'CHANGELOG.md'; |
| 154 | + const changelogPath = path.resolve(cwd, changelogFile); |
| 155 | + await outputFile(changelogPath, 'Initial CHANGELOG'); |
| 156 | + |
| 157 | + await prepare( |
| 158 | + {skipOnPrerelease: false}, |
| 159 | + {cwd, nextRelease: {notes}, branch: {type: 'prerelease', main: false}, logger: t.context.logger} |
| 160 | + ); |
| 161 | + |
| 162 | + // Verify the content of the CHANGELOG.md |
| 163 | + t.is((await readFile(changelogPath)).toString(), `${notes}\n\nInitial CHANGELOG\n`); |
| 164 | + t.deepEqual(t.context.log.args[0], ['Update %s', changelogPath]); |
| 165 | +}); |
0 commit comments