Skip to content

Commit

Permalink
(mathieudutour#145) reset inputs between tests
Browse files Browse the repository at this point in the history
  • Loading branch information
martin-hartmond-mw committed Apr 21, 2023
1 parent 08da861 commit d87bb15
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions tests/action.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,7 @@ describe('github-tag-action', () => {
beforeEach(() => {
jest.clearAllMocks();
setBranch('prerelease');
loadDefaultInputs();
setInput('pre_release_branches', 'prerelease');
});

Expand Down
9 changes: 8 additions & 1 deletion tests/helper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ export function setInputs(map: { [key: string]: string }) {
Object.keys(map).forEach((key) => setInput(key, map[key]));
}

export function resetInputs(map: { [key: string]: string }) {
Object.keys(process.env)
.filter(k => k.startsWith("INPUT_"))
.forEach(k => delete process.env[k]);
Object.keys(map).forEach((key) => setInput(key, map[key]));
}

export function loadDefaultInputs() {
const actionYaml = fs.readFileSync(
path.join(process.cwd(), 'action.yml'),
Expand All @@ -40,7 +47,7 @@ export function loadDefaultInputs() {
(obj, key) => ({ ...obj, [key]: actionJson['inputs'][key].default }),
{}
);
setInputs(defaultInputs);
resetInputs(defaultInputs);
}

// Don't know how to have this file only for test but not have 'tsc' complain. So I made it a test file...
Expand Down

0 comments on commit d87bb15

Please sign in to comment.