From 20e35849943c88cd9a34ce3463fe8bd85d08db7d Mon Sep 17 00:00:00 2001 From: Christian Marangi Date: Fri, 26 Apr 2024 18:58:26 +0200 Subject: [PATCH] feat: add additional test for codeblock ``` ignore Add test for codeblock ``` ignore to prevent and catch in future code change that would produce wrong parsing. Signed-off-by: Christian Marangi --- fixtures/paragraph-ignore-```/expected.json | 3 ++ fixtures/paragraph-ignore-```/form.yml | 9 +++++ fixtures/paragraph-ignore-```/issue-body.md | 7 ++++ fixtures/paragraph-ignore-```/issue.js | 6 ++++ test.spec.js | 39 +++++++++++++++++++++ 5 files changed, 64 insertions(+) create mode 100644 fixtures/paragraph-ignore-```/expected.json create mode 100644 fixtures/paragraph-ignore-```/form.yml create mode 100644 fixtures/paragraph-ignore-```/issue-body.md create mode 100644 fixtures/paragraph-ignore-```/issue.js diff --git a/fixtures/paragraph-ignore-```/expected.json b/fixtures/paragraph-ignore-```/expected.json new file mode 100644 index 0000000..2f8fdda --- /dev/null +++ b/fixtures/paragraph-ignore-```/expected.json @@ -0,0 +1,3 @@ +{ + "textarea-one": "Textarea input text 1\n\n```\n### To be ignored tag\n```" +} diff --git a/fixtures/paragraph-ignore-```/form.yml b/fixtures/paragraph-ignore-```/form.yml new file mode 100644 index 0000000..cb5bf9f --- /dev/null +++ b/fixtures/paragraph-ignore-```/form.yml @@ -0,0 +1,9 @@ +body: + - type: textarea + id: textarea-one + attributes: + label: My textarea input + - type: textarea + id: textarea-two + attributes: + label: Another textarea input diff --git a/fixtures/paragraph-ignore-```/issue-body.md b/fixtures/paragraph-ignore-```/issue-body.md new file mode 100644 index 0000000..ebe88ce --- /dev/null +++ b/fixtures/paragraph-ignore-```/issue-body.md @@ -0,0 +1,7 @@ +### My textarea input + +Textarea input text 1 + +``` +### To be ignored tag +``` diff --git a/fixtures/paragraph-ignore-```/issue.js b/fixtures/paragraph-ignore-```/issue.js new file mode 100644 index 0000000..6851c74 --- /dev/null +++ b/fixtures/paragraph-ignore-```/issue.js @@ -0,0 +1,6 @@ +const { resolve } = require("path"); +const { readFileSync } = require("fs"); + +const issueBodyPath = resolve(__dirname, "issue-body.md"); + +module.exports = readFileSync(issueBodyPath, "utf-8") diff --git a/test.spec.js b/test.spec.js index f3f1a61..51ca14a 100644 --- a/test.spec.js +++ b/test.spec.js @@ -169,6 +169,45 @@ it("paragraph with confusing ####", () => { expect(core.setOutput.mock.calls.length).toBe(2) }); +it("paragraph with ``` section", () => { + const expectedOutput = require("./fixtures/paragraph-ignore-```/expected.json"); + const expectedOutputJson = JSON.stringify(expectedOutput, null, 2); + + // mock ENV + const env = { + HOME: "", + }; + + // mock event payload + const eventPayload = require("./fixtures/paragraph-ignore-```/issue"); + + // mock fs + const fs = { + readFileSync(path, encoding) { + expect(path).toBe(""); + expect(encoding).toBe("utf8"); + return readFileSync("fixtures/paragraph-ignore-```/form.yml", "utf-8"); + }, + writeFileSync(path, content) { + expect(path).toBe("/issue-parser-result.json"); + expect(content).toBe(expectedOutputJson); + }, + }; + + // mock core + const core = { + getInput: jest.fn(() => ''), + setOutput: jest.fn(), + }; + + run(env, eventPayload, fs, core); + + expect(core.getInput).toHaveBeenCalledWith('template-path') + expect(core.setOutput).toHaveBeenCalledWith('jsonString', JSON.stringify(expectedOutput, null, 2)) + expect(core.setOutput).toHaveBeenCalledWith('issueparser_textarea-one', 'Textarea input text 1\n\n```\n### To be ignored tag\n```') + expect(core.setOutput.mock.calls.length).toBe(2) +}); + it("blank", () => { const expectedOutput = require("./fixtures/blank/expected.json"); const expectedOutputJson = JSON.stringify(expectedOutput, null, 2);