Skip to content

Commit f28daf5

Browse files
Ansuelgr2m
authored andcommitted
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 <ansuelsmth@gmail.com>
1 parent 48ade79 commit f28daf5

5 files changed

Lines changed: 64 additions & 0 deletions

File tree

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
@@ -223,6 +223,45 @@ it("paragraph with confusing ####", () => {
223223
expect(core.setOutput.mock.calls.length).toBe(2)
224224
});
225225

226+
it("paragraph with ``` section", () => {
227+
const expectedOutput = require("./fixtures/paragraph-ignore-```/expected.json");
228+
const expectedOutputJson = JSON.stringify(expectedOutput, null, 2);
229+
230+
// mock ENV
231+
const env = {
232+
HOME: "<home path>",
233+
};
234+
235+
// mock event payload
236+
const eventPayload = require("./fixtures/paragraph-ignore-```/issue");
237+
238+
// mock fs
239+
const fs = {
240+
readFileSync(path, encoding) {
241+
expect(path).toBe("<template-path>");
242+
expect(encoding).toBe("utf8");
243+
return readFileSync("fixtures/paragraph-ignore-```/form.yml", "utf-8");
244+
},
245+
writeFileSync(path, content) {
246+
expect(path).toBe("<home path>/issue-parser-result.json");
247+
expect(content).toBe(expectedOutputJson);
248+
},
249+
};
250+
251+
// mock core
252+
const core = {
253+
getInput: jest.fn(() => '<template-path>'),
254+
setOutput: jest.fn(),
255+
};
256+
257+
run(env, eventPayload, fs, core);
258+
259+
expect(core.getInput).toHaveBeenCalledWith('template-path')
260+
expect(core.setOutput).toHaveBeenCalledWith('jsonString', JSON.stringify(expectedOutput, null, 2))
261+
expect(core.setOutput).toHaveBeenCalledWith('issueparser_textarea-one', 'Textarea input text 1\n\n```\n### To be ignored tag\n```')
262+
expect(core.setOutput.mock.calls.length).toBe(2)
263+
});
264+
226265
it("blank", () => {
227266
const expectedOutput = loadJson("./fixtures/blank/expected.json");
228267
const expectedOutputJson = JSON.stringify(expectedOutput, null, 2);

0 commit comments

Comments
 (0)