-
-
Notifications
You must be signed in to change notification settings - Fork 19
/
test.spec.js
181 lines (152 loc) · 5.58 KB
/
test.spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
const { readFileSync } = require("fs");
const { run } = require(".");
it("smoke test", () => {
expect(run).toBeDefined();
expect(typeof run).toBe("function");
});
it("readme example", () => {
const expectedOutput = require("./fixtures/readme-example/expected.json");
const expectedOutputJson = JSON.stringify(expectedOutput, null, 2);
// mock ENV
const env = {
HOME: "<home path>",
};
// mock event payload
const eventPayload = require("./fixtures/readme-example/issue");
// mock fs
const fs = {
readFileSync(path, encoding) {
expect(path).toBe("<template-path>");
expect(encoding).toBe("utf8");
return readFileSync("fixtures/readme-example/form.yml", "utf-8");
},
writeFileSync(path, content) {
expect(path).toBe("<home path>/issue-parser-result.json");
expect(content).toBe(expectedOutputJson);
},
};
// mock core
const core = {
getInput: jest.fn(() => '<template-path>'),
setOutput: jest.fn(),
};
run(env, eventPayload, fs, core);
expect(core.getInput).toHaveBeenCalledWith('template-path')
expect(core.setOutput).toHaveBeenCalledWith('jsonString', JSON.stringify(expectedOutput, null, 2))
expect(core.setOutput).toHaveBeenCalledWith('issueparser_favorite_dish', 'Pizza')
expect(core.setOutput).toHaveBeenCalledWith('issueparser_favorite_color', 'Red,Blue')
expect(core.setOutput.mock.calls.length).toBe(3)
});
it("full example", () => {
const expectedOutput = require("./fixtures/full-example/expected.json");
const expectedOutputJson = JSON.stringify(expectedOutput, null, 2);
// mock ENV
const env = {
HOME: "<home path>",
};
// mock event payload
const eventPayload = require("./fixtures/full-example/issue");
// mock fs
const fs = {
readFileSync(path, encoding) {
expect(path).toBe("<template-path>");
expect(encoding).toBe("utf8");
return readFileSync("fixtures/full-example/form.yml", "utf-8");
},
writeFileSync(path, content) {
expect(path).toBe("<home path>/issue-parser-result.json");
expect(content).toBe(expectedOutputJson);
},
};
// mock core
const core = {
getInput: jest.fn(() => '<template-path>'),
setOutput: jest.fn(),
};
run(env, eventPayload, fs, core);
expect(core.getInput).toHaveBeenCalledWith('template-path')
expect(core.setOutput).toHaveBeenCalledWith('jsonString', JSON.stringify(expectedOutput, null, 2))
expect(core.setOutput).toHaveBeenCalledWith('issueparser_contact', '[email protected]')
expect(core.setOutput).toHaveBeenCalledWith('issueparser_what_happened', 'A bug happened!')
expect(core.setOutput).toHaveBeenCalledWith('issueparser_version', '1.0.0')
expect(core.setOutput).toHaveBeenCalledWith('issueparser_browsers', 'Chrome, Safari')
expect(core.setOutput).toHaveBeenCalledWith('issueparser_anything_else', 'Never give up')
expect(core.setOutput).toHaveBeenCalledWith('issueparser_second_anything_else', 'Hot Dog is a Sandwich,Another item')
expect(core.setOutput).toHaveBeenCalledWith('issueparser_checkbox_without_an_id', '')
expect(core.setOutput.mock.calls.length).toBe(8)
});
it("multiple paragraphs", () => {
const expectedOutput = require("./fixtures/multiple-paragraphs/expected.json");
const expectedOutputJson = JSON.stringify(expectedOutput, null, 2);
// mock ENV
const env = {
HOME: "<home path>",
};
// mock event payload
const eventPayload = require("./fixtures/multiple-paragraphs/issue");
// mock fs
const fs = {
readFileSync(path, encoding) {
expect(path).toBe("<template-path>");
expect(encoding).toBe("utf8");
return readFileSync("fixtures/multiple-paragraphs/form.yml", "utf-8");
},
writeFileSync(path, content) {
expect(path).toBe("<home path>/issue-parser-result.json");
expect(content).toBe(expectedOutputJson);
},
};
// mock core
const core = {
getInput: jest.fn(() => '<template-path>'),
setOutput: jest.fn(),
};
run(env, eventPayload, fs, core);
expect(core.getInput).toHaveBeenCalledWith('template-path')
expect(core.setOutput).toHaveBeenCalledWith('jsonString', JSON.stringify(expectedOutput, null, 2))
expect(core.setOutput).toHaveBeenCalledWith('issueparser_textarea-one', '1st paragraph\n\n2nd paragraph')
expect(core.setOutput).toHaveBeenCalledWith('issueparser_textarea-two', '1st paragraph\n2nd paragraph')
expect(core.setOutput.mock.calls.length).toBe(3)
});
it("blank", () => {
const expectedOutput = require("./fixtures/blank/expected.json");
const expectedOutputJson = JSON.stringify(expectedOutput, null, 2);
// mock ENV
const env = {
HOME: "<home path>",
};
// mock event payload
const eventPayload = null;
// mock fs
const fs = {
readFileSync(path, encoding) {
expect(path).toBe("<template-path>");
expect(encoding).toBe("utf8");
return readFileSync("fixtures/blank/form.yml", "utf-8");
},
writeFileSync(path, content) {
expect(path).toBe("<home path>/issue-parser-result.json");
expect(content).toBe(expectedOutputJson);
},
};
// mock core
const core = {
getInput(inputName) {
expect(inputName).toBe("template-path");
return "<template-path>";
},
setOutput(outputName, outputValue) {
if (outputName === "jsonString") {
expect(outputValue).toBe(expectedOutputJson);
return;
}
if (outputName.startsWith("issueparser_")) {
const key = outputName.substr("issueparser_".length);
expect(Object.keys(expectedOutput)).toContain(key);
expect(outputValue).toBe(expectedOutput[key]);
return;
}
},
};
run(env, eventPayload, fs, core);
});