From 27ff796862b5e8739227a89835fc836897764821 Mon Sep 17 00:00:00 2001 From: Mathieu Dutour Date: Mon, 4 Jan 2021 10:30:49 +0100 Subject: [PATCH] fix tests --- package-lock.json | 6 ++++++ package.json | 1 + tests/helper.test.ts | 17 +++++++++++------ tests/main.test.ts | 8 ++++---- tests/utils.test.ts | 8 +++++++- 5 files changed, 29 insertions(+), 11 deletions(-) diff --git a/package-lock.json b/package-lock.json index 4f71dc5b..8cbd1815 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1305,6 +1305,12 @@ "pretty-format": "^26.0.0" } }, + "@types/js-yaml": { + "version": "3.12.5", + "resolved": "https://registry.npmjs.org/@types/js-yaml/-/js-yaml-3.12.5.tgz", + "integrity": "sha512-JCcp6J0GV66Y4ZMDAQCXot4xprYB+Zfd3meK9+INSJeVZwJmHAW30BBEEkPzXswMXuiyReUGOP3GxrADc9wPww==", + "dev": true + }, "@types/minimist": { "version": "1.2.1", "resolved": "https://registry.npmjs.org/@types/minimist/-/minimist-1.2.1.tgz", diff --git a/package.json b/package.json index d9fd94ec..0ca68b5a 100644 --- a/package.json +++ b/package.json @@ -30,6 +30,7 @@ }, "devDependencies": { "@octokit/rest": "^18.0.12", + "@types/js-yaml": "^3.12.5", "@types/node": "^14.14.19", "@types/semver": "^7.1.0", "jest": "^26.6.3", diff --git a/tests/helper.test.ts b/tests/helper.test.ts index 38b84a34..728d5968 100644 --- a/tests/helper.test.ts +++ b/tests/helper.test.ts @@ -14,17 +14,22 @@ export function setInput(key: string, value: string) { process.env[`INPUT_${key.toUpperCase()}`] = value; } -export function setInputs(map: Object) { +export function setInputs(map: { [key: string]: string }) { Object.keys(map).forEach((key) => setInput(key, map[key])); } export function loadDefaultInputs() { - const actionYaml = fs.readFileSync(path.join(process.cwd(), 'action.yml')); - const actionJson = yaml.safeLoad(actionYaml); - const defaultInputs = Object.keys(actionJson.inputs) - .filter((key) => actionJson.inputs[key].default) + const actionYaml = fs.readFileSync( + path.join(process.cwd(), 'action.yml'), + 'utf-8' + ); + const actionJson = yaml.safeLoad(actionYaml) as { + inputs: { [key: string]: { default?: string } }; + }; + const defaultInputs = Object.keys(actionJson['inputs']) + .filter((key) => actionJson['inputs'][key].default) .reduce( - (obj, key) => ({ ...obj, [key]: actionJson.inputs[key].default }), + (obj, key) => ({ ...obj, [key]: actionJson['inputs'][key].default }), {} ); setInputs(defaultInputs); diff --git a/tests/main.test.ts b/tests/main.test.ts index cd01db68..008a6a51 100644 --- a/tests/main.test.ts +++ b/tests/main.test.ts @@ -41,7 +41,7 @@ describe('github-tag-action', () => { .spyOn(utils, 'getCommits') .mockImplementation(async (sha) => commits); - const validTags = []; + const validTags: any[] = []; jest .spyOn(utils, 'getValidTags') .mockImplementation(async () => validTags); @@ -66,12 +66,12 @@ describe('github-tag-action', () => { /* * Given */ - const commits = []; + const commits: any[] = []; jest .spyOn(utils, 'getCommits') .mockImplementation(async (sha) => commits); - const validTags = []; + const validTags: any[] = []; jest .spyOn(utils, 'getValidTags') .mockImplementation(async () => validTags); @@ -97,7 +97,7 @@ describe('github-tag-action', () => { * Given */ setInput('default_bump', 'false'); - const commits = []; + const commits: any[] = []; jest .spyOn(utils, 'getCommits') .mockImplementation(async (sha) => commits); diff --git a/tests/utils.test.ts b/tests/utils.test.ts index 4a073429..2c558e9a 100644 --- a/tests/utils.test.ts +++ b/tests/utils.test.ts @@ -107,7 +107,13 @@ describe('utils', () => { * Then */ expect(mockListTags).toHaveBeenCalled(); - expect(validTags[0]).toEqual({ name: '1.2.4-prerelease.2' }); + expect(validTags[0]).toEqual({ + name: '1.2.4-prerelease.2', + commit: { sha: 'string', url: 'string' }, + zipball_url: 'string', + tarball_url: 'string', + node_id: 'string', + }); }); describe('custom release types', () => {