Skip to content

Commit 20e3584

Browse files
committed
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 <[email protected]>
1 parent 4a7eb3e commit 20e3584

File tree

5 files changed

+64
-0
lines changed

5 files changed

+64
-0
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"textarea-one": "Textarea input text 1\n\n```\n### To be ignored tag\n```"
3+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
body:
2+
- type: textarea
3+
id: textarea-one
4+
attributes:
5+
label: My textarea input
6+
- type: textarea
7+
id: textarea-two
8+
attributes:
9+
label: Another textarea input
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
### My textarea input
2+
3+
Textarea input text 1
4+
5+
```
6+
### To be ignored tag
7+
```
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
const { resolve } = require("path");
2+
const { readFileSync } = require("fs");
3+
4+
const issueBodyPath = resolve(__dirname, "issue-body.md");
5+
6+
module.exports = readFileSync(issueBodyPath, "utf-8")

test.spec.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,45 @@ it("paragraph with confusing ####", () => {
169169
expect(core.setOutput.mock.calls.length).toBe(2)
170170
});
171171

172+
it("paragraph with ``` section", () => {
173+
const expectedOutput = require("./fixtures/paragraph-ignore-```/expected.json");
174+
const expectedOutputJson = JSON.stringify(expectedOutput, null, 2);
175+
176+
// mock ENV
177+
const env = {
178+
HOME: "<home path>",
179+
};
180+
181+
// mock event payload
182+
const eventPayload = require("./fixtures/paragraph-ignore-```/issue");
183+
184+
// mock fs
185+
const fs = {
186+
readFileSync(path, encoding) {
187+
expect(path).toBe("<template-path>");
188+
expect(encoding).toBe("utf8");
189+
return readFileSync("fixtures/paragraph-ignore-```/form.yml", "utf-8");
190+
},
191+
writeFileSync(path, content) {
192+
expect(path).toBe("<home path>/issue-parser-result.json");
193+
expect(content).toBe(expectedOutputJson);
194+
},
195+
};
196+
197+
// mock core
198+
const core = {
199+
getInput: jest.fn(() => '<template-path>'),
200+
setOutput: jest.fn(),
201+
};
202+
203+
run(env, eventPayload, fs, core);
204+
205+
expect(core.getInput).toHaveBeenCalledWith('template-path')
206+
expect(core.setOutput).toHaveBeenCalledWith('jsonString', JSON.stringify(expectedOutput, null, 2))
207+
expect(core.setOutput).toHaveBeenCalledWith('issueparser_textarea-one', 'Textarea input text 1\n\n```\n### To be ignored tag\n```')
208+
expect(core.setOutput.mock.calls.length).toBe(2)
209+
});
210+
172211
it("blank", () => {
173212
const expectedOutput = require("./fixtures/blank/expected.json");
174213
const expectedOutputJson = JSON.stringify(expectedOutput, null, 2);

0 commit comments

Comments
 (0)