Skip to content

Commit

Permalink
Merge pull request #23996 from storybookjs/shaun/fix-chanelog-json-bu…
Browse files Browse the repository at this point in the history
…ilder

Scripts: Fix the changelog writer to escape doublequotes
  • Loading branch information
Shaun Evening authored Aug 29, 2023
2 parents 1a3850d + 9656e43 commit 7669124
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
39 changes: 39 additions & 0 deletions scripts/release/__tests__/write-changelog.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,45 @@ describe('Write changelog', () => {
`);
});

it('should escape double quotes for json files', async () => {
getChangesMock.mockResolvedValue({
changes: [],
changelogText: `## 7.0.1
- React: Make it reactive
- Revert "CLI: Not UI"
- 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
- Revert "CLI: Not UI"
- 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
- Revert \\"CLI: Not UI\\"
- CLI: Not UI",
},
"version": "7.0.1",
}
`);
});

it('should write to prerelase changelogs and version files in docs', async () => {
getChangesMock.mockResolvedValue({
changes: [],
Expand Down
2 changes: 1 addition & 1 deletion scripts/release/write-changelog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ const writeToDocsVersionFile = async ({
console.log(`📝 Writing changelog to ${chalk.blue(path)}`);
}

const textWithoutHeading = changelogText.split('\n').slice(2).join('\n');
const textWithoutHeading = changelogText.split('\n').slice(2).join('\n').replaceAll('"', '\\"');

const content = {
version,
Expand Down

0 comments on commit 7669124

Please sign in to comment.