-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #23235 from storybookjs/23000-bug-new-release-flow…
…-doesnt-update-versions-on-docs-site Release tooling: Update docs version files when releasing (cherry picked from commit 35fc07b)
- Loading branch information
1 parent
2721da8
commit 26ff28a
Showing
3 changed files
with
164 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
/* eslint-disable global-require */ | ||
/* eslint-disable no-underscore-dangle */ | ||
import path from 'path'; | ||
import dedent from 'ts-dedent'; | ||
import { run as writeChangelog } from '../write-changelog'; | ||
import * as changesUtils from '../utils/get-changes'; | ||
|
||
// eslint-disable-next-line jest/no-mocks-import | ||
jest.mock('fs-extra', () => require('../../../code/__mocks__/fs-extra')); | ||
const fsExtra = require('fs-extra'); | ||
|
||
const getChangesMock = jest.spyOn(changesUtils, 'getChanges'); | ||
|
||
jest.spyOn(console, 'log').mockImplementation(() => {}); | ||
jest.spyOn(console, 'warn').mockImplementation(() => {}); | ||
jest.spyOn(console, 'error').mockImplementation(() => {}); | ||
|
||
const STABLE_CHANGELOG_PATH = path.join(__dirname, '..', '..', '..', 'CHANGELOG.md'); | ||
const PRERELEASE_CHANGELOG_PATH = path.join(__dirname, '..', '..', '..', 'CHANGELOG.prerelease.md'); | ||
const LATEST_VERSION_PATH = path.join( | ||
__dirname, | ||
'..', | ||
'..', | ||
'..', | ||
'docs', | ||
'versions', | ||
'latest.json' | ||
); | ||
const NEXT_VERSION_PATH = path.join(__dirname, '..', '..', '..', 'docs', 'versions', 'next.json'); | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
const EXISTING_STABLE_CHANGELOG = dedent`## 7.0.0 | ||
- Core: Some change`; | ||
|
||
const EXISTING_PRERELEASE_CHANGELOG = dedent`## 7.1.0-alpha.20 | ||
- CLI: Super fast now`; | ||
|
||
fsExtra.__setMockFiles({ | ||
[STABLE_CHANGELOG_PATH]: EXISTING_STABLE_CHANGELOG, | ||
[PRERELEASE_CHANGELOG_PATH]: EXISTING_PRERELEASE_CHANGELOG, | ||
}); | ||
|
||
describe('Write changelog', () => { | ||
it('should write to stable changelogs and version files in docs', async () => { | ||
getChangesMock.mockResolvedValue({ | ||
changes: [], | ||
changelogText: `## 7.0.1 | ||
- React: Make it reactive | ||
- CLI: Not UI`, | ||
}); | ||
|
||
await writeChangelog(['7.0.1'], {}); | ||
|
||
expect(fsExtra.writeFile).toHaveBeenCalledTimes(1); | ||
expect(fsExtra.writeFile.mock.calls[0][0]).toBe(STABLE_CHANGELOG_PATH); | ||
expect(fsExtra.writeFile.mock.calls[0][1]).toMatchInlineSnapshot(` | ||
"## 7.0.1 | ||
- React: Make it reactive | ||
- CLI: Not UI | ||
## 7.0.0 | ||
- Core: Some change" | ||
`); | ||
expect(fsExtra.writeJson).toBeCalledTimes(1); | ||
expect(fsExtra.writeJson.mock.calls[0][0]).toBe(LATEST_VERSION_PATH); | ||
expect(fsExtra.writeJson.mock.calls[0][1]).toMatchInlineSnapshot(` | ||
{ | ||
"info": { | ||
"plain": "- React: Make it reactive | ||
- CLI: Not UI", | ||
}, | ||
"version": "7.0.1", | ||
} | ||
`); | ||
}); | ||
|
||
it('should write to prerelase changelogs and version files in docs', async () => { | ||
getChangesMock.mockResolvedValue({ | ||
changes: [], | ||
changelogText: `## 7.1.0-alpha.21 | ||
- React: Make it reactive | ||
- CLI: Not UI`, | ||
}); | ||
|
||
await writeChangelog(['7.1.0-alpha.21'], {}); | ||
|
||
expect(fsExtra.writeFile).toHaveBeenCalledTimes(1); | ||
expect(fsExtra.writeFile.mock.calls[0][0]).toBe(PRERELEASE_CHANGELOG_PATH); | ||
expect(fsExtra.writeFile.mock.calls[0][1]).toMatchInlineSnapshot(` | ||
"## 7.1.0-alpha.21 | ||
- React: Make it reactive | ||
- CLI: Not UI | ||
## 7.1.0-alpha.20 | ||
- CLI: Super fast now" | ||
`); | ||
expect(fsExtra.writeJson).toBeCalledTimes(1); | ||
expect(fsExtra.writeJson.mock.calls[0][0]).toBe(NEXT_VERSION_PATH); | ||
expect(fsExtra.writeJson.mock.calls[0][1]).toMatchInlineSnapshot(` | ||
{ | ||
"info": { | ||
"plain": "- React: Make it reactive | ||
- CLI: Not UI", | ||
}, | ||
"version": "7.1.0-alpha.21", | ||
} | ||
`); | ||
}); | ||
}); |
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