Skip to content

Commit

Permalink
test: set RUNNER_TEMP instead of HOME
Browse files Browse the repository at this point in the history
  • Loading branch information
gr2m committed May 29, 2024
1 parent 7296f08 commit 3c890f0
Showing 1 changed file with 95 additions and 35 deletions.
130 changes: 95 additions & 35 deletions test.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,25 @@ it("readme example", () => {

// mock core
const core = {
getInput: jest.fn(() => '<template-path>'),
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)
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", () => {
Expand Down Expand Up @@ -73,21 +82,42 @@ it("full example", () => {

// mock core
const core = {
getInput: jest.fn(() => '<template-path>'),
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', 'me@me.com')
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)
expect(core.getInput).toHaveBeenCalledWith("template-path");
expect(core.setOutput).toHaveBeenCalledWith(
"jsonString",
JSON.stringify(expectedOutput, null, 2)
);
expect(core.setOutput).toHaveBeenCalledWith(
"issueparser_contact",
"me@me.com"
);
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("mismatched parsing", () => {
Expand All @@ -96,7 +126,7 @@ it("mismatched parsing", () => {

// mock ENV
const env = {
HOME: "<home path>",
RUNNER_TEMP: "<home path>",
};

// mock event payload
Expand All @@ -117,21 +147,42 @@ it("mismatched parsing", () => {

// mock core
const core = {
getInput: jest.fn(() => '<template-path>'),
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_your_contact_details', 'me@me.com')
expect(core.setOutput).toHaveBeenCalledWith('issueparser_what_happened', 'A bug happened!')
expect(core.setOutput).toHaveBeenCalledWith('issueparser_version', '1.0.0')
expect(core.setOutput).toHaveBeenCalledWith('issueparser_what_browsers_are_you_seeing_the_problem_on', 'Chrome, Safari')
expect(core.setOutput).toHaveBeenCalledWith('issueparser_what_else', 'Never give up')
expect(core.setOutput).toHaveBeenCalledWith('issueparser_and_with_that', 'Hot Dog is a Sandwich,Another item')
expect(core.setOutput).toHaveBeenCalledWith('issueparser_checkbox_without_an_id', '')
expect(core.setOutput.mock.calls.length).toBe(8)
expect(core.getInput).toHaveBeenCalledWith("template-path");
expect(core.setOutput).toHaveBeenCalledWith(
"jsonString",
JSON.stringify(expectedOutput, null, 2)
);
expect(core.setOutput).toHaveBeenCalledWith(
"issueparser_your_contact_details",
"me@me.com"
);
expect(core.setOutput).toHaveBeenCalledWith(
"issueparser_what_happened",
"A bug happened!"
);
expect(core.setOutput).toHaveBeenCalledWith("issueparser_version", "1.0.0");
expect(core.setOutput).toHaveBeenCalledWith(
"issueparser_what_browsers_are_you_seeing_the_problem_on",
"Chrome, Safari"
);
expect(core.setOutput).toHaveBeenCalledWith(
"issueparser_what_else",
"Never give up"
);
expect(core.setOutput).toHaveBeenCalledWith(
"issueparser_and_with_that",
"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", () => {
Expand Down Expand Up @@ -161,17 +212,26 @@ it("multiple paragraphs", () => {

// mock core
const core = {
getInput: jest.fn(() => '<template-path>'),
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)
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", () => {
Expand Down

0 comments on commit 3c890f0

Please sign in to comment.