Skip to content

Commit

Permalink
feat: add additional test for codeblock ``` ignore
Browse files Browse the repository at this point in the history
Add test for codeblock ``` ignore to prevent and catch in future code
change that would produce wrong parsing.

Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
  • Loading branch information
Ansuel committed Apr 26, 2024
1 parent 4a7eb3e commit 20e3584
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 0 deletions.
3 changes: 3 additions & 0 deletions fixtures/paragraph-ignore-```/expected.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"textarea-one": "Textarea input text 1\n\n```\n### To be ignored tag\n```"
}
9 changes: 9 additions & 0 deletions fixtures/paragraph-ignore-```/form.yml
Original file line number Diff line number Diff line change
@@ -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
7 changes: 7 additions & 0 deletions fixtures/paragraph-ignore-```/issue-body.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
### My textarea input

Textarea input text 1

```
### To be ignored tag
```
6 changes: 6 additions & 0 deletions fixtures/paragraph-ignore-```/issue.js
Original file line number Diff line number Diff line change
@@ -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")
39 changes: 39 additions & 0 deletions test.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: "<home path>",
};

// mock event payload
const eventPayload = require("./fixtures/paragraph-ignore-```/issue");

// mock fs
const fs = {
readFileSync(path, encoding) {
expect(path).toBe("<template-path>");
expect(encoding).toBe("utf8");
return readFileSync("fixtures/paragraph-ignore-```/form.yml", "utf-8");
},
writeFileSync(path, content) {
expect(path).toBe("<home path>/issue-parser-result.json");
expect(content).toBe(expectedOutputJson);
},
};

// mock core
const core = {
getInput: jest.fn(() => '<template-path>'),
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);
Expand Down

0 comments on commit 20e3584

Please sign in to comment.