diff options
| author | Kevin J Hoerr <kjhoerr@protonmail.com> | 2019-12-12 14:30:58 -0500 |
|---|---|---|
| committer | Kevin J Hoerr <kjhoerr@protonmail.com> | 2019-12-12 14:30:58 -0500 |
| commit | 91efa5ab51904667eaf3353008753ea99bf5b17d (patch) | |
| tree | 91e6b26f5e7b27c6a2bb22c1c5388afc8edec5d7 /src/templates.test.ts | |
| parent | 0d810aa92e9b54493a2e075c3bb497b3857a2119 (diff) | |
| download | ao-coverage-91efa5ab51904667eaf3353008753ea99bf5b17d.tar.gz ao-coverage-91efa5ab51904667eaf3353008753ea99bf5b17d.tar.bz2 ao-coverage-91efa5ab51904667eaf3353008753ea99bf5b17d.zip | |
Simplify and generalize template processing
"For the unit tests. For the unit tests!"
Diffstat (limited to 'src/templates.test.ts')
| -rw-r--r-- | src/templates.test.ts | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/src/templates.test.ts b/src/templates.test.ts new file mode 100644 index 0000000..1fb88b7 --- /dev/null +++ b/src/templates.test.ts @@ -0,0 +1,47 @@ +import processTemplate, { Template } from "./templates"; +import path from "path"; +import fs from "fs"; + +const genTemplate = (filename: string): Template => + ({ + inputFile: path.join(__dirname, "..", "example_reports", filename), + outputFile: path.join( + __dirname, + "..", + "build", + filename.replace(/template/, "txt") + ), + context: { that: "this", potential: "resolved" } + } as Template); + +describe("processTemplate", () => { + beforeAll(() => + fs.promises.mkdir(path.join(__dirname, "..", "build")).catch(() => null) + ); + + it("should process the template file with the given context", async () => { + // Arrange + const template = genTemplate("ex.template"); + + // Act + const result = await processTemplate(template); + + // Assert + expect(result.data).not.toBeNull(); + expect(result.data).toEqual("But what is this other than resolved?"); + expect(fs.existsSync(result.outputFile)).toEqual(true); + }); + + it("should process the blank file", async () => { + // Arrange + const template = genTemplate("blank.template"); + + // Act + const result = await processTemplate(template); + + // Assert + expect(result.data).not.toBeNull(); + expect(result.data).toEqual(""); + expect(fs.existsSync(result.outputFile)).toEqual(true); + }); +}); |
