Skip to content

Commit 14c673f

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 <ansuelsmth@gmail.com>
1 parent ba96fbe commit 14c673f

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

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

0 commit comments

Comments
 (0)