generated from threeal/action-starter
-
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.
feat: add option for independent Yarn version retrieval (#194)
* refactor: move the `getYarnVersion` function to `src/yarn/version.ts` * feat: add `options.corepack` option to `getYarnVersion` function
- Loading branch information
Showing
7 changed files
with
96 additions
and
44 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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 |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { jest } from "@jest/globals"; | ||
|
||
jest.unstable_mockModule("@actions/exec", () => ({ | ||
getExecOutput: jest.fn(), | ||
})); | ||
|
||
describe("get Yarn version", () => { | ||
beforeEach(async () => { | ||
const { getExecOutput } = await import("@actions/exec"); | ||
|
||
jest.mocked(getExecOutput).mockReset().mockResolvedValueOnce({ | ||
exitCode: 0, | ||
stdout: "1.2.3", | ||
stderr: "", | ||
}); | ||
}); | ||
|
||
it("should get Yarn version", async () => { | ||
const { getExecOutput } = await import("@actions/exec"); | ||
const { getYarnVersion } = await import("./version.js"); | ||
|
||
const version = await getYarnVersion(); | ||
|
||
expect(getExecOutput).toHaveBeenCalledTimes(1); | ||
expect(getExecOutput).toHaveBeenCalledWith("yarn", ["--version"], { | ||
silent: true, | ||
}); | ||
|
||
expect(version).toEqual("1.2.3"); | ||
}); | ||
|
||
it("should get Yarn version using Corepack", async () => { | ||
const { getExecOutput } = await import("@actions/exec"); | ||
const { getYarnVersion } = await import("./version.js"); | ||
|
||
const version = await getYarnVersion({ corepack: true }); | ||
|
||
expect(getExecOutput).toHaveBeenCalledTimes(1); | ||
expect(getExecOutput).toHaveBeenCalledWith( | ||
"corepack", | ||
["yarn", "--version"], | ||
{ | ||
silent: true, | ||
}, | ||
); | ||
|
||
expect(version).toEqual("1.2.3"); | ||
}); | ||
}); |
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,18 @@ | ||
import { getExecOutput } from "@actions/exec"; | ||
|
||
/** | ||
* Get the current Yarn version. | ||
* | ||
* @param options.corepack - Whether to get the current Yarn version using Corepack or not. | ||
* @returns A promise resolving to the current Yarn version. | ||
*/ | ||
export async function getYarnVersion(options?: { | ||
corepack: boolean; | ||
}): Promise<string> { | ||
const commandLine = options?.corepack ? "corepack" : "yarn"; | ||
const args = options?.corepack ? ["yarn", "--version"] : ["--version"]; | ||
const res = await getExecOutput(commandLine, args, { | ||
silent: true, | ||
}); | ||
return res.stdout.trim(); | ||
} |