Skip to content

Commit 06dd03d

Browse files
committed
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 <[email protected]>
1 parent 1816705 commit 06dd03d

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```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
@@ -252,6 +252,45 @@ it("paragraph with ``` section", () => {
252252
expect(core.setOutput.mock.calls.length).toBe(2)
253253
});
254254

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

0 commit comments

Comments
 (0)