|
1 | 1 | "use strict";
|
2 | 2 |
|
3 |
| -const { extractHash } = require("./testUtils"); |
| 3 | +const { extractHash, appendDataIfFileExists } = require("./testUtils"); |
| 4 | +const { writeFileSync, unlinkSync, readFileSync } = require("fs"); |
| 5 | +const { resolve } = require("path"); |
4 | 6 |
|
5 | 7 | describe("extractHash functionality", () => {
|
6 | 8 | it("should throw Error if there is empty string", () => {
|
@@ -101,3 +103,29 @@ Child ${config2Name}:
|
101 | 103 | expect(hashInfo.config[1]).toEqual({ name: config2Name, hash: config2Hash });
|
102 | 104 | });
|
103 | 105 | });
|
| 106 | + |
| 107 | +describe("appendFile functionality", () => { |
| 108 | + describe("positive test-cases", () => { |
| 109 | + const junkFile = resolve(__dirname, "junkFile.js"); |
| 110 | + |
| 111 | + beforeEach(() => { |
| 112 | + writeFileSync(junkFile, ""); |
| 113 | + }); |
| 114 | + afterEach(() => { |
| 115 | + unlinkSync(junkFile); |
| 116 | + }); |
| 117 | + it("should append data to file if file exists", () => { |
| 118 | + const expectedData = "//junk comment"; |
| 119 | + appendDataIfFileExists(__dirname, junkFile, expectedData); |
| 120 | + const actualData = readFileSync(junkFile).toString(); |
| 121 | + |
| 122 | + expect(actualData).toBe(expectedData); |
| 123 | + }); |
| 124 | + }); |
| 125 | + |
| 126 | + describe("negative test-cases", () => { |
| 127 | + it("should throw error if file does not exist", () => { |
| 128 | + expect(() => appendDataIfFileExists(__dirname, "does-not-exist.js", "junk data")).toThrowError(); |
| 129 | + }); |
| 130 | + }); |
| 131 | +}); |
0 commit comments