-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: use
cwd
and env
options passed by core
feat: use `cwd` and `env` options passed by core BREAKING CHANGE: require `semantic-release` >= `15.8.0`
- Loading branch information
Showing
6 changed files
with
80 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,85 +1,92 @@ | ||
import path from 'path'; | ||
import test from 'ava'; | ||
import {outputFile, readFile} from 'fs-extra'; | ||
import {stub} from 'sinon'; | ||
import tempy from 'tempy'; | ||
import prepare from '../lib/prepare'; | ||
|
||
// Save the current working diretory | ||
const cwd = process.cwd(); | ||
|
||
test.beforeEach(t => { | ||
// Change current working directory to a temp directory | ||
process.chdir(tempy.directory()); | ||
// Stub the logger | ||
t.context.log = stub(); | ||
t.context.logger = {log: t.context.log}; | ||
}); | ||
|
||
test.afterEach.always(() => { | ||
// Restore the current working directory | ||
process.chdir(cwd); | ||
}); | ||
|
||
test.serial('Create new CHANGELOG.md', async t => { | ||
test('Create new CHANGELOG.md', async t => { | ||
const cwd = tempy.directory(); | ||
const notes = 'Test release note'; | ||
const changelogFile = 'CHANGELOG.md'; | ||
const changelogPath = path.resolve(cwd, changelogFile); | ||
|
||
await prepare({}, notes, t.context.logger); | ||
await prepare({}, {cwd, nextRelease: {notes}, logger: t.context.logger}); | ||
|
||
// Verify the content of the CHANGELOG.md | ||
t.is((await readFile('CHANGELOG.md')).toString(), `${notes}\n`); | ||
t.is((await readFile(changelogPath)).toString(), `${notes}\n`); | ||
|
||
t.deepEqual(t.context.log.args[0], ['Create %s', 'CHANGELOG.md']); | ||
t.deepEqual(t.context.log.args[0], ['Create %s', changelogPath]); | ||
}); | ||
|
||
test.serial('Create new changelog with custom path', async t => { | ||
test('Create new changelog with custom path', async t => { | ||
const cwd = tempy.directory(); | ||
const notes = 'Test release note'; | ||
const changelogFile = 'docs/changelog.txt'; | ||
const changelogPath = path.resolve(cwd, 'docs/changelog.txt'); | ||
|
||
await prepare({changelogFile}, notes, t.context.logger); | ||
await prepare({changelogFile}, {cwd, nextRelease: {notes}, logger: t.context.logger}); | ||
|
||
// Verify the content of the CHANGELOG.md | ||
t.is((await readFile(changelogFile)).toString(), `${notes}\n`); | ||
t.is((await readFile(changelogPath)).toString(), `${notes}\n`); | ||
|
||
t.deepEqual(t.context.log.args[0], ['Create %s', changelogFile]); | ||
t.deepEqual(t.context.log.args[0], ['Create %s', changelogPath]); | ||
}); | ||
|
||
test.serial('Prepend the CHANGELOG.md if there is an existing one', async t => { | ||
test('Prepend the CHANGELOG.md if there is an existing one', async t => { | ||
const cwd = tempy.directory(); | ||
const notes = 'Test release note'; | ||
await outputFile('CHANGELOG.md', 'Initial CHANGELOG'); | ||
const changelogFile = 'CHANGELOG.md'; | ||
const changelogPath = path.resolve(cwd, changelogFile); | ||
await outputFile(changelogPath, 'Initial CHANGELOG'); | ||
|
||
await prepare({}, notes, t.context.logger); | ||
await prepare({}, {cwd, nextRelease: {notes}, logger: t.context.logger}); | ||
|
||
// Verify the content of the CHANGELOG.md | ||
t.is((await readFile('CHANGELOG.md')).toString(), `${notes}\n\nInitial CHANGELOG\n`); | ||
t.deepEqual(t.context.log.args[0], ['Update %s', 'CHANGELOG.md']); | ||
t.is((await readFile(changelogPath)).toString(), `${notes}\n\nInitial CHANGELOG\n`); | ||
t.deepEqual(t.context.log.args[0], ['Update %s', changelogPath]); | ||
}); | ||
|
||
test.serial('Prepend title in the CHANGELOG.md if there is none', async t => { | ||
test('Prepend title in the CHANGELOG.md if there is none', async t => { | ||
const cwd = tempy.directory(); | ||
const notes = 'Test release note'; | ||
await outputFile('CHANGELOG.md', 'Initial CHANGELOG'); | ||
|
||
const changelogTitle = '# My Changelog Title'; | ||
await prepare({changelogTitle}, notes, t.context.logger); | ||
const changelogFile = 'CHANGELOG.md'; | ||
const changelogPath = path.resolve(cwd, changelogFile); | ||
await outputFile(changelogPath, 'Initial CHANGELOG'); | ||
|
||
await prepare({changelogTitle}, {cwd, nextRelease: {notes}, logger: t.context.logger}); | ||
|
||
t.is((await readFile('CHANGELOG.md')).toString(), `${changelogTitle}\n\n${notes}\n\nInitial CHANGELOG\n`); | ||
t.is((await readFile(changelogPath)).toString(), `${changelogTitle}\n\n${notes}\n\nInitial CHANGELOG\n`); | ||
}); | ||
|
||
test.serial('Keep the title at the top of the CHANGELOG.md', async t => { | ||
test('Keep the title at the top of the CHANGELOG.md', async t => { | ||
const cwd = tempy.directory(); | ||
const notes = 'Test release note'; | ||
const changelogTitle = '# My Changelog Title'; | ||
await outputFile('CHANGELOG.md', `${changelogTitle}\n\nInitial CHANGELOG`); | ||
const changelogFile = 'CHANGELOG.md'; | ||
const changelogPath = path.resolve(cwd, changelogFile); | ||
await outputFile(changelogPath, `${changelogTitle}\n\nInitial CHANGELOG`); | ||
|
||
await prepare({changelogTitle}, notes, t.context.logger); | ||
await prepare({changelogTitle}, {cwd, nextRelease: {notes}, logger: t.context.logger}); | ||
|
||
t.is((await readFile('CHANGELOG.md')).toString(), `${changelogTitle}\n\n${notes}\n\nInitial CHANGELOG\n`); | ||
t.is((await readFile(changelogPath)).toString(), `${changelogTitle}\n\n${notes}\n\nInitial CHANGELOG\n`); | ||
}); | ||
|
||
test.serial('Create new changelog with title if specified', async t => { | ||
const cwd = tempy.directory(); | ||
const notes = 'Test release note'; | ||
const changelogTitle = '# My Changelog Title'; | ||
const changelogFile = 'HISTORY.md'; | ||
const changelogPath = path.resolve(cwd, changelogFile); | ||
|
||
await prepare({changelogTitle, changelogFile}, notes, t.context.logger); | ||
await prepare({changelogTitle, changelogFile}, {cwd, nextRelease: {notes}, logger: t.context.logger}); | ||
|
||
t.is((await readFile(changelogFile)).toString(), `${changelogTitle}\n\n${notes}\n`); | ||
t.is((await readFile(changelogPath)).toString(), `${changelogTitle}\n\n${notes}\n`); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters