Skip to content

Commit

Permalink
Bugs (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
max-vasin authored Feb 25, 2021
1 parent e082736 commit 892d654
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 5 deletions.
4 changes: 3 additions & 1 deletion deploy/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@
"@actions/core": "1.2.5",
"semver": "7.3.4",
"latest-version": "5.1.0",
"lodash.set": "4.3.2"
"lodash.set": "4.3.2",
"lodash.isempty": "4.4.0"
},
"devDependencies": {
"@types/semver": "7.3.4",
"@types/lodash.omit": "4.5.6",
"@types/lodash.set": "4.3.6",
"@types/lodash.isempty": "4.4.6",
"jest": "26.6.3",
"ts-jest": "26.5.1",
"lodash.omit": "4.5.0",
Expand Down
13 changes: 9 additions & 4 deletions deploy/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { URL } from 'url'
import * as path from 'path'
import * as core from '@actions/core'
import setByPath from 'lodash.set'
import isEmpty from 'lodash.isempty'
import { execSync } from 'child_process'
import { readFileSync, writeFileSync } from 'fs'
import latestVersion from 'latest-version'
Expand Down Expand Up @@ -36,8 +37,9 @@ export const main = async (): Promise<void> => {
}

const specificCliVersion = core.getInput('cli_version')
const cliVersion =
specificCliVersion ?? (await latestVersion('resolve-cloud'))
const cliVersion = isEmpty(specificCliVersion)
? await latestVersion('resolve-cloud')
: specificCliVersion

core.debug(`setting cloud CLI version to (${cliVersion})`)
setByPath(pkg, 'devDependencies.resolve-cloud', cliVersion)
Expand Down Expand Up @@ -77,10 +79,13 @@ export const main = async (): Promise<void> => {
: (val) => val

const inputAppName = core.getInput('name')
let targetAppName = randomizer(inputAppName ?? readPackage(pkgFile).name)
core.debug(`input app name: ${inputAppName}`)

core.debug(`target application path: ${appDir}`)
const targetAppName = randomizer(
isEmpty(inputAppName) ? readPackage(pkgFile).name : inputAppName
)
core.debug(`target application name: ${targetAppName}`)
core.debug(`target application path: ${appDir}`)

if (!parseBoolean(core.getInput('local_run'))) {
writeResolveRc(
Expand Down
23 changes: 23 additions & 0 deletions deploy/test/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,17 @@ test('cloud cli version patched to latest available', async () => {
)
})

test('cloud cli version patched to latest available (specific version is empty string)', async () => {
actionInput.cli_version = ''

await main()

expect(mLatestVersion).toHaveBeenCalledWith('resolve-cloud')
expect(getPackageContent()?.devDependencies?.['resolve-cloud']).toEqual(
'1.2.3'
)
})

test('cloud cli version patched to specific version', async () => {
actionInput.cli_version = '5.4.3'

Expand Down Expand Up @@ -271,6 +282,18 @@ test('app name from package.json', async () => {
)
})

test('app name from package.json (input is empty string)', async () => {
actionInput.name = ''
actionInput.randomize_name = 'false'

await main()

expect(mCLI).toHaveBeenCalledWith(
expect.stringContaining(`--name package`),
expect.anything()
)
})

test('randomized app name from package.json', async () => {
actionInput.randomize_name = 'true'

Expand Down

0 comments on commit 892d654

Please sign in to comment.