Skip to content
This repository has been archived by the owner on Nov 5, 2024. It is now read-only.

Commit

Permalink
Fix getFlowVersion (#235)
Browse files Browse the repository at this point in the history
  • Loading branch information
Luze26 authored May 23, 2024
1 parent 6e74d86 commit 1b630d2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/nasty-otters-chew.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@onflow/flow-js-testing": patch
---

Add fallback for version checking CLI when JSON not supported
14 changes: 12 additions & 2 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,18 @@ export async function getFlowVersion(flowCommand = "flow") {
"Could not determine Flow CLI version, please make sure it is installed and available in your PATH"
)

Check warning on line 53 in src/utils.js

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
} else {
const versionStr = JSON.parse(stdout).version
const version = semver.parse(versionStr)
let versionStr
try {
versionStr = JSON.parse(stdout).version
} catch (error) {
// fallback to regex for older versions of the CLI without JSON output
const rxResult = /^Version: ([^\s]+)/m.exec(stdout)

Check warning on line 60 in src/utils.js

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
if (rxResult) {
versionStr = rxResult[1]

Check warning on line 62 in src/utils.js

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
}

Check warning on line 63 in src/utils.js

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement

Check warning on line 63 in src/utils.js

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch
}

const version = versionStr ? semver.parse(versionStr) : undefined

Check warning on line 66 in src/utils.js

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch
if (!version) {
reject(`Invalid Flow CLI version string: ${versionStr}`)

Check warning on line 68 in src/utils.js

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
}

Check warning on line 69 in src/utils.js

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch
Expand Down

0 comments on commit 1b630d2

Please sign in to comment.