-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: refactor index.js to achieve 100% test coverage (#13)
* achieve 100% test coverage This seeks to establish 100% test coverage by homing `run`'s testable logic in `run.js` and making `index.js` a logic-less invocation of `run`. ``` -----------|---------|----------|---------|---------|------------------- File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s -----------|---------|----------|---------|---------|------------------- All files | 100 | 100 | 100 | 100 | github.js | 100 | 100 | 100 | 100 | run.js | 100 | 100 | 100 | 100 | utils.js | 100 | 100 | 100 | 100 | -----------|---------|----------|---------|---------|------------------- Test Suites: 3 passed, 3 total Tests: 21 passed, 21 total Snapshots: 0 total Time: 0.855 s, estimated 1 s Ran all test suites. ✨ Done in 1.71s. ``` Signed-off-by: Mike Ball <[email protected]> * pr 13 patch * fix await issue * update dist build --------- Signed-off-by: Mike Ball <[email protected]> Co-authored-by: John Veldboom <[email protected]>
- Loading branch information
Showing
5 changed files
with
65 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,10 @@ | ||
const semver = require('semver') | ||
const core = require('@actions/core') | ||
const github = require('./github') | ||
const utils = require('./utils') | ||
const run = require('./run'); // semicolon is intentional for standardjs | ||
|
||
const run = async () => { | ||
const octokit = github.getOctokit(core.getInput('github-token')) | ||
|
||
const [owner, repo] = process.env.GITHUB_REPOSITORY.split('/') | ||
const sha = process.env.GITHUB_SHA | ||
|
||
let latestTag | ||
(async () => { | ||
try { | ||
latestTag = await github.getLatestTag(octokit, owner, repo) | ||
await run() | ||
} catch (err) { | ||
return core.setFailed(`unable to get latest tag - error: ${err.message} ${err?.response?.status}`) | ||
} | ||
|
||
// return a default version if no previous github tags | ||
if (!latestTag) { | ||
const incrementedVersion = semver.inc('0.0.0', core.getInput('default-bump')) | ||
return utils.setVersionOutputs(incrementedVersion, core.getInput('prefix')) | ||
} | ||
|
||
if (!semver.valid(latestTag.name)) { | ||
return core.setFailed(`latest tag name is not valid semver: ${JSON.stringify(latestTag)}`) | ||
core.setFailed(err.message) | ||
} | ||
|
||
// get commits from last tag and calculate version bump | ||
const commits = await github.compareCommits(octokit, owner, repo, latestTag?.commit?.sha, sha) | ||
const bump = await utils.getVersionBump(commits, core.getInput('default-bump')) | ||
|
||
const incrementedVersion = semver.inc(latestTag.name, bump) | ||
utils.setVersionOutputs(incrementedVersion, core.getInput('prefix')) | ||
} | ||
|
||
if (process.env.NODE_ENV !== 'test') run() | ||
|
||
module.exports = { run } | ||
})() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
const semver = require('semver') | ||
const core = require('@actions/core') | ||
const github = require('./github') | ||
const utils = require('./utils') | ||
|
||
module.exports = async () => { | ||
const octokit = github.getOctokit(core.getInput('github-token')) | ||
|
||
const [owner, repo] = process.env.GITHUB_REPOSITORY.split('/') | ||
const sha = process.env.GITHUB_SHA | ||
|
||
let latestTag | ||
try { | ||
latestTag = await github.getLatestTag(octokit, owner, repo) | ||
} catch (err) { | ||
return core.setFailed(`unable to get latest tag - error: ${err.message} ${err?.response?.status}`) | ||
} | ||
|
||
// return a default version if no previous github tags | ||
if (!latestTag) { | ||
const incrementedVersion = semver.inc('0.0.0', core.getInput('default-bump')) | ||
return utils.setVersionOutputs(incrementedVersion, core.getInput('prefix')) | ||
} | ||
|
||
if (!semver.valid(latestTag.name)) { | ||
return core.setFailed(`latest tag name is not valid semver: ${JSON.stringify(latestTag)}`) | ||
} | ||
|
||
// get commits from last tag and calculate version bump | ||
const commits = await github.compareCommits(octokit, owner, repo, latestTag?.commit?.sha, sha) | ||
const bump = await utils.getVersionBump(commits, core.getInput('default-bump')) | ||
|
||
const incrementedVersion = semver.inc(latestTag.name, bump) | ||
utils.setVersionOutputs(incrementedVersion, core.getInput('prefix')) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters