Skip to content

Commit

Permalink
fix(builds): missing CHANGELOG.md no longer crashes the build pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
ashblue committed Apr 7, 2021
1 parent d1b40dc commit 5fc6b0e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
24 changes: 24 additions & 0 deletions src/file-utility/file-utility.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,30 @@ describe('fileUtility functions', () => {

expect(newTargetContent).toEqual(srcContent);
});

it('should not crash if the file does not exist', async () => {
const srcPath = `${tmpFolder}/a.md`;
const targetPath = `${tmpFolder}/b.md`;

await setup();

overwriteFile(srcPath, targetPath);
});

it('should write the file if the file destination does not exist', async () => {
const srcPath = `${tmpFolder}/a.md`;
const srcContent = nanoid();

const targetPath = `${tmpFolder}/b.md`;

await setup();
fs.writeFileSync(srcPath, srcContent);

overwriteFile(srcPath, targetPath);
const newTargetContent = fs.readFileSync(targetPath).toString();

expect(newTargetContent).toEqual(srcContent);
});
});

describe('overwriteJsonFileFields function', () => {
Expand Down
3 changes: 2 additions & 1 deletion src/file-utility/file-utility.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import fs from 'fs';
import fs, { existsSync } from 'fs';

export const overwriteFile = (fileSrcPath: string, fileTargetPath: string): void => {
if (!existsSync(fileSrcPath)) return;
const content = fs.readFileSync(fileSrcPath);
fs.writeFileSync(fileTargetPath, content);
};
Expand Down

0 comments on commit 5fc6b0e

Please sign in to comment.