Skip to content

Commit d70e6a4

Browse files
Ansuelgr2m
authored andcommitted
feat: add additional test for codeblock ```sh ignore
Add test for codeblock ```sh ignore to prevent and catch in future code change that would produce wrong parsing. This is a variant of the ``` test that makes the code block section target specific code. Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
1 parent f28daf5 commit d70e6a4

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```sh\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+
```sh
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
@@ -262,6 +262,45 @@ it("paragraph with ``` section", () => {
262262
expect(core.setOutput.mock.calls.length).toBe(2)
263263
});
264264

265+
it("paragraph with ```sh section", () => {
266+
const expectedOutput = require("./fixtures/paragraph-ignore-```sh/expected.json");
267+
const expectedOutputJson = JSON.stringify(expectedOutput, null, 2);
268+
269+
// mock ENV
270+
const env = {
271+
HOME: "<home path>",
272+
};
273+
274+
// mock event payload
275+
const eventPayload = require("./fixtures/paragraph-ignore-```sh/issue");
276+
277+
// mock fs
278+
const fs = {
279+
readFileSync(path, encoding) {
280+
expect(path).toBe("<template-path>");
281+
expect(encoding).toBe("utf8");
282+
return readFileSync("fixtures/paragraph-ignore-```sh/form.yml", "utf-8");
283+
},
284+
writeFileSync(path, content) {
285+
expect(path).toBe("<home path>/issue-parser-result.json");
286+
expect(content).toBe(expectedOutputJson);
287+
},
288+
};
289+
290+
// mock core
291+
const core = {
292+
getInput: jest.fn(() => '<template-path>'),
293+
setOutput: jest.fn(),
294+
};
295+
296+
run(env, eventPayload, fs, core);
297+
298+
expect(core.getInput).toHaveBeenCalledWith('template-path')
299+
expect(core.setOutput).toHaveBeenCalledWith('jsonString', JSON.stringify(expectedOutput, null, 2))
300+
expect(core.setOutput).toHaveBeenCalledWith('issueparser_textarea-one', 'Textarea input text 1\n\n```sh\n### To be ignored tag\n```')
301+
expect(core.setOutput.mock.calls.length).toBe(2)
302+
});
303+
265304
it("blank", () => {
266305
const expectedOutput = loadJson("./fixtures/blank/expected.json");
267306
const expectedOutputJson = JSON.stringify(expectedOutput, null, 2);

0 commit comments

Comments
 (0)