Compare commits

..

4 commits
v5 ... main

Author SHA1 Message Date
David Gamero
5f8d8195ef
Migrate to ESM with esbuild and vitest (#243)
Some checks are pending
CodeQL Advanced / Analyze (javascript-typescript) (push) Waiting to run
Integration test for setup-kubectl / Validate release and master branch (push) Waiting to run
Run prettify / Prettier Check (push) Waiting to run
Run unit tests. / build (push) Waiting to run
* Migrate to ESM with esbuild, vitest and upgrade @actions/* to ESM-only versions

* fix: update lockfile for npm ci compatibility

---------

Co-authored-by: Suneha Bose <suneha.bose@gmail.com>
2026-04-03 10:48:25 -07:00
dependabot[bot]
08845d9b5a
Bump github/codeql-action in /.github/workflows in the actions group (#245)
Some checks failed
CodeQL Advanced / Analyze (javascript-typescript) (push) Has been cancelled
Integration test for setup-kubectl / Validate release and master branch (push) Has been cancelled
Run prettify / Prettier Check (push) Has been cancelled
Run unit tests. / build (push) Has been cancelled
Bumps the actions group in /.github/workflows with 1 update: [github/codeql-action](https://github.com/github/codeql-action).


Updates `github/codeql-action` from 4.33.0 to 4.35.1
- [Release notes](https://github.com/github/codeql-action/releases)
- [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md)
- [Commits](b1bff81932...c10b8064de)

---
updated-dependencies:
- dependency-name: github/codeql-action
  dependency-version: 4.35.1
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: actions
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-03-31 00:40:30 +13:00
dependabot[bot]
f59556b0f1
Bump handlebars from 4.7.8 to 4.7.9 (#244)
Some checks are pending
CodeQL Advanced / Analyze (javascript-typescript) (push) Waiting to run
Integration test for setup-kubectl / Validate release and master branch (push) Waiting to run
Run prettify / Prettier Check (push) Waiting to run
Run unit tests. / build (push) Waiting to run
Bumps [handlebars](https://github.com/handlebars-lang/handlebars.js) from 4.7.8 to 4.7.9.
- [Release notes](https://github.com/handlebars-lang/handlebars.js/releases)
- [Changelog](https://github.com/handlebars-lang/handlebars.js/blob/v4.7.9/release-notes.md)
- [Commits](https://github.com/handlebars-lang/handlebars.js/compare/v4.7.8...v4.7.9)

---
updated-dependencies:
- dependency-name: handlebars
  dependency-version: 4.7.9
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-03-29 22:05:44 +13:00
dependabot[bot]
50eb4152fb
Bump picomatch (#242)
Some checks failed
CodeQL Advanced / Analyze (javascript-typescript) (push) Has been cancelled
Integration test for setup-kubectl / Validate release and master branch (push) Has been cancelled
Run prettify / Prettier Check (push) Has been cancelled
Run unit tests. / build (push) Has been cancelled
Bumps  and [picomatch](https://github.com/micromatch/picomatch). These dependencies needed to be updated together.

Updates `picomatch` from 2.3.1 to 2.3.2
- [Release notes](https://github.com/micromatch/picomatch/releases)
- [Changelog](https://github.com/micromatch/picomatch/blob/master/CHANGELOG.md)
- [Commits](https://github.com/micromatch/picomatch/compare/2.3.1...2.3.2)

Updates `picomatch` from 4.0.2 to 4.0.4
- [Release notes](https://github.com/micromatch/picomatch/releases)
- [Changelog](https://github.com/micromatch/picomatch/blob/master/CHANGELOG.md)
- [Commits](https://github.com/micromatch/picomatch/compare/2.3.1...2.3.2)

---
updated-dependencies:
- dependency-name: picomatch
  dependency-version: 2.3.2
  dependency-type: indirect
- dependency-name: picomatch
  dependency-version: 4.0.4
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-03-26 12:38:51 +13:00
12 changed files with 1510 additions and 41703 deletions

View file

@ -59,7 +59,7 @@ jobs:
# Initializes the CodeQL tools for scanning. # Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL - name: Initialize CodeQL
uses: github/codeql-action/init@b1bff81932f5cdfc8695c7752dcee935dcd061c8 # v3.29.5 uses: github/codeql-action/init@c10b8064de6f491fea524254123dbe5e09572f13 # v4.35.1
with: with:
languages: ${{ matrix.language }} languages: ${{ matrix.language }}
build-mode: ${{ matrix.build-mode }} build-mode: ${{ matrix.build-mode }}
@ -86,6 +86,6 @@ jobs:
echo ' make release' echo ' make release'
exit 1 exit 1
- name: Perform CodeQL Analysis - name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@b1bff81932f5cdfc8695c7752dcee935dcd061c8 # v3.29.5 uses: github/codeql-action/analyze@c10b8064de6f491fea524254123dbe5e09572f13 # v4.35.1
with: with:
category: '/language:${{matrix.language}}' category: '/language:${{matrix.language}}'

1
.gitignore vendored
View file

@ -330,3 +330,4 @@ ASALocalRun/
node_modules node_modules
# Transpiled JS # Transpiled JS
lib/

View file

@ -1,18 +0,0 @@
module.exports = {
clearMocks: true,
moduleFileExtensions: ['js', 'ts'],
testEnvironment: 'node',
testMatch: ['**/*.test.ts'],
transform: {
'^.+\\.ts$': 'ts-jest'
},
verbose: true,
coverageThreshold: {
global: {
branches: 0,
functions: 14,
lines: 27,
statements: 27
}
}
}

34286
lib/index.js

File diff suppressed because one or more lines are too long

8699
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -3,10 +3,12 @@
"version": "5.0.0", "version": "5.0.0",
"private": true, "private": true,
"main": "lib/index.js", "main": "lib/index.js",
"type": "module",
"scripts": { "scripts": {
"build": "npm i ncc && npx ncc build src/index.ts -o lib", "build": "tsc --noEmit && esbuild src/index.ts --bundle --platform=node --target=node20 --format=esm --outfile=lib/index.js --banner:js=\"import { createRequire } from 'module';const require = createRequire(import.meta.url);\"",
"test": "jest", "typecheck": "tsc --noEmit",
"test-coverage": "jest --coverage", "test": "vitest run",
"test-coverage": "vitest run --coverage",
"format": "prettier --write .", "format": "prettier --write .",
"format-check": "prettier --check .", "format-check": "prettier --check .",
"prepare": "husky" "prepare": "husky"
@ -19,19 +21,16 @@
"author": "GitHub", "author": "GitHub",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@actions/core": "^2.0.2", "@actions/core": "^3.0.0",
"@actions/exec": "^2.0.0", "@actions/exec": "^3.0.0",
"@actions/tool-cache": "^3.0.0", "@actions/tool-cache": "^4.0.0"
"ncc": "^0.3.6"
}, },
"devDependencies": { "devDependencies": {
"@types/jest": "^30.0.0",
"@types/node": "^25.0.9", "@types/node": "^25.0.9",
"@vercel/ncc": "^0.38.4", "esbuild": "^0.27.4",
"husky": "^9.1.7", "husky": "^9.1.7",
"jest": "^30.2.0",
"prettier": "3.8.0", "prettier": "3.8.0",
"ts-jest": "^29.4.6", "typescript": "5.9.3",
"typescript": "5.9.3" "vitest": "^4.0.18"
} }
} }

View file

@ -42,7 +42,7 @@ export async function getLatestPatchVersion(
} }
return latestPatch return latestPatch
} catch (error) { } catch (error) {
core.debug(error) core.debug(String(error))
core.warning('GetLatestPatchVersionFailed') core.warning('GetLatestPatchVersionFailed')
throw new Error(`Failed to get latest patch version for ${version}`) throw new Error(`Failed to get latest patch version for ${version}`)
} }

View file

@ -1,4 +1,4 @@
import {run} from './run' import {run} from './run.js'
import * as core from '@actions/core' import * as core from '@actions/core'
run().catch(core.setFailed) run().catch(core.setFailed)

View file

@ -1,28 +1,43 @@
import * as run from './run' import {vi, describe, test, expect, beforeEach} from 'vitest'
import { import * as path from 'path'
import * as util from 'util'
vi.mock('os')
vi.mock('fs')
vi.mock('@actions/tool-cache', async (importOriginal) => {
const actual = await importOriginal<typeof import('@actions/tool-cache')>()
return {
...actual,
downloadTool: vi.fn(),
find: vi.fn(),
cacheFile: vi.fn()
}
})
vi.mock('@actions/core')
const os = await import('os')
const fs = await import('fs')
const toolCache = await import('@actions/tool-cache')
const core = await import('@actions/core')
const run = await import('./run.js')
const {
getkubectlDownloadURL, getkubectlDownloadURL,
getKubectlArch, getKubectlArch,
getExecutableExtension, getExecutableExtension,
getLatestPatchVersion getLatestPatchVersion
} from './helpers' } = await import('./helpers.js')
import * as os from 'os'
import * as toolCache from '@actions/tool-cache'
import * as fs from 'fs'
import * as path from 'path'
import * as core from '@actions/core'
import * as util from 'util'
describe('Testing all functions in run file.', () => { describe('Testing all functions in run file.', () => {
beforeEach(() => { beforeEach(() => {
jest.clearAllMocks() vi.clearAllMocks()
}) })
test('getExecutableExtension() - return .exe when os is Windows', () => { test('getExecutableExtension() - return .exe when os is Windows', () => {
jest.spyOn(os, 'type').mockReturnValue('Windows_NT') vi.mocked(os.type).mockReturnValue('Windows_NT')
expect(getExecutableExtension()).toBe('.exe') expect(getExecutableExtension()).toBe('.exe')
expect(os.type).toHaveBeenCalled() expect(os.type).toHaveBeenCalled()
}) })
test('getExecutableExtension() - return empty string for non-windows OS', () => { test('getExecutableExtension() - return empty string for non-windows OS', () => {
jest.spyOn(os, 'type').mockReturnValue('Darwin') vi.mocked(os.type).mockReturnValue('Darwin')
expect(getExecutableExtension()).toBe('') expect(getExecutableExtension()).toBe('')
expect(os.type).toHaveBeenCalled() expect(os.type).toHaveBeenCalled()
}) })
@ -33,7 +48,7 @@ describe('Testing all functions in run file.', () => {
])( ])(
'getKubectlArch() - return on %s os arch %s kubectl arch', 'getKubectlArch() - return on %s os arch %s kubectl arch',
(osArch, kubectlArch) => { (osArch, kubectlArch) => {
jest.spyOn(os, 'arch').mockReturnValue(osArch as NodeJS.Architecture) vi.mocked(os.arch).mockReturnValue(osArch as NodeJS.Architecture)
expect(getKubectlArch()).toBe(kubectlArch) expect(getKubectlArch()).toBe(kubectlArch)
expect(os.arch).toHaveBeenCalled() expect(os.arch).toHaveBeenCalled()
} }
@ -41,7 +56,7 @@ describe('Testing all functions in run file.', () => {
test.each([['arm'], ['arm64'], ['amd64']])( test.each([['arm'], ['arm64'], ['amd64']])(
'getkubectlDownloadURL() - return the URL to download %s kubectl for Linux', 'getkubectlDownloadURL() - return the URL to download %s kubectl for Linux',
(arch) => { (arch) => {
jest.spyOn(os, 'type').mockReturnValue('Linux') vi.mocked(os.type).mockReturnValue('Linux')
const kubectlLinuxUrl = util.format( const kubectlLinuxUrl = util.format(
'https://dl.k8s.io/release/v1.15.0/bin/linux/%s/kubectl', 'https://dl.k8s.io/release/v1.15.0/bin/linux/%s/kubectl',
arch arch
@ -53,7 +68,7 @@ describe('Testing all functions in run file.', () => {
test.each([['arm'], ['arm64'], ['amd64']])( test.each([['arm'], ['arm64'], ['amd64']])(
'getkubectlDownloadURL() - return the URL to download %s kubectl for Darwin', 'getkubectlDownloadURL() - return the URL to download %s kubectl for Darwin',
(arch) => { (arch) => {
jest.spyOn(os, 'type').mockReturnValue('Darwin') vi.mocked(os.type).mockReturnValue('Darwin')
const kubectlDarwinUrl = util.format( const kubectlDarwinUrl = util.format(
'https://dl.k8s.io/release/v1.15.0/bin/darwin/%s/kubectl', 'https://dl.k8s.io/release/v1.15.0/bin/darwin/%s/kubectl',
arch arch
@ -65,7 +80,7 @@ describe('Testing all functions in run file.', () => {
test.each([['arm'], ['arm64'], ['amd64']])( test.each([['arm'], ['arm64'], ['amd64']])(
'getkubectlDownloadURL() - return the URL to download %s kubectl for Windows', 'getkubectlDownloadURL() - return the URL to download %s kubectl for Windows',
(arch) => { (arch) => {
jest.spyOn(os, 'type').mockReturnValue('Windows_NT') vi.mocked(os.type).mockReturnValue('Windows_NT')
const kubectlWindowsUrl = util.format( const kubectlWindowsUrl = util.format(
'https://dl.k8s.io/release/v1.15.0/bin/windows/%s/kubectl.exe', 'https://dl.k8s.io/release/v1.15.0/bin/windows/%s/kubectl.exe',
arch arch
@ -75,40 +90,30 @@ describe('Testing all functions in run file.', () => {
} }
) )
test('getStableKubectlVersion() - download stable version file, read version and return it', async () => { test('getStableKubectlVersion() - download stable version file, read version and return it', async () => {
jest vi.mocked(toolCache.downloadTool).mockResolvedValue('pathToTool')
.spyOn(toolCache, 'downloadTool') vi.mocked(fs.readFileSync).mockReturnValue('v1.20.4')
.mockReturnValue(Promise.resolve('pathToTool'))
jest.spyOn(fs, 'readFileSync').mockReturnValue('v1.20.4')
expect(await run.getStableKubectlVersion()).toBe('v1.20.4') expect(await run.getStableKubectlVersion()).toBe('v1.20.4')
expect(toolCache.downloadTool).toHaveBeenCalled() expect(toolCache.downloadTool).toHaveBeenCalled()
expect(fs.readFileSync).toHaveBeenCalledWith('pathToTool', 'utf8') expect(fs.readFileSync).toHaveBeenCalledWith('pathToTool', 'utf8')
}) })
test('getStableKubectlVersion() - return default v1.15.0 if version read is empty', async () => { test('getStableKubectlVersion() - return default v1.15.0 if version read is empty', async () => {
jest vi.mocked(toolCache.downloadTool).mockResolvedValue('pathToTool')
.spyOn(toolCache, 'downloadTool') vi.mocked(fs.readFileSync).mockReturnValue('')
.mockReturnValue(Promise.resolve('pathToTool'))
jest.spyOn(fs, 'readFileSync').mockReturnValue('')
expect(await run.getStableKubectlVersion()).toBe('v1.15.0') expect(await run.getStableKubectlVersion()).toBe('v1.15.0')
expect(toolCache.downloadTool).toHaveBeenCalled() expect(toolCache.downloadTool).toHaveBeenCalled()
expect(fs.readFileSync).toHaveBeenCalledWith('pathToTool', 'utf8') expect(fs.readFileSync).toHaveBeenCalledWith('pathToTool', 'utf8')
}) })
test('getStableKubectlVersion() - return default v1.15.0 if unable to download file', async () => { test('getStableKubectlVersion() - return default v1.15.0 if unable to download file', async () => {
jest vi.mocked(toolCache.downloadTool).mockRejectedValue('Unable to download.')
.spyOn(toolCache, 'downloadTool')
.mockRejectedValue('Unable to download.')
expect(await run.getStableKubectlVersion()).toBe('v1.15.0') expect(await run.getStableKubectlVersion()).toBe('v1.15.0')
expect(toolCache.downloadTool).toHaveBeenCalled() expect(toolCache.downloadTool).toHaveBeenCalled()
}) })
test('downloadKubectl() - download kubectl, add it to toolCache and return path to it', async () => { test('downloadKubectl() - download kubectl, add it to toolCache and return path to it', async () => {
jest.spyOn(toolCache, 'find').mockReturnValue('') vi.mocked(toolCache.find).mockReturnValue('')
jest vi.mocked(toolCache.downloadTool).mockResolvedValue('pathToTool')
.spyOn(toolCache, 'downloadTool') vi.mocked(toolCache.cacheFile).mockResolvedValue('pathToCachedTool')
.mockReturnValue(Promise.resolve('pathToTool')) vi.mocked(os.type).mockReturnValue('Windows_NT')
jest vi.mocked(fs.chmodSync).mockImplementation(() => {})
.spyOn(toolCache, 'cacheFile')
.mockReturnValue(Promise.resolve('pathToCachedTool'))
jest.spyOn(os, 'type').mockReturnValue('Windows_NT')
jest.spyOn(fs, 'chmodSync').mockImplementation(() => {})
expect(await run.downloadKubectl('v1.15.0')).toBe( expect(await run.downloadKubectl('v1.15.0')).toBe(
path.join('pathToCachedTool', 'kubectl.exe') path.join('pathToCachedTool', 'kubectl.exe')
) )
@ -122,10 +127,10 @@ describe('Testing all functions in run file.', () => {
) )
}) })
test('downloadKubectl() - throw DownloadKubectlFailed error when unable to download kubectl', async () => { test('downloadKubectl() - throw DownloadKubectlFailed error when unable to download kubectl', async () => {
jest.spyOn(toolCache, 'find').mockReturnValue('') vi.mocked(toolCache.find).mockReturnValue('')
jest vi.mocked(toolCache.downloadTool).mockRejectedValue(
.spyOn(toolCache, 'downloadTool') 'Unable to download kubectl.'
.mockRejectedValue('Unable to download kubectl.') )
await expect(run.downloadKubectl('v1.15.0')).rejects.toThrow( await expect(run.downloadKubectl('v1.15.0')).rejects.toThrow(
'DownloadKubectlFailed' 'DownloadKubectlFailed'
) )
@ -135,9 +140,9 @@ describe('Testing all functions in run file.', () => {
test('downloadKubectl() - throw kubectl not found error when receive 404 response', async () => { test('downloadKubectl() - throw kubectl not found error when receive 404 response', async () => {
const kubectlVersion = 'v1.15.0' const kubectlVersion = 'v1.15.0'
const arch = 'arm128' const arch = 'arm128'
jest.spyOn(os, 'arch').mockReturnValue(arch as any) vi.mocked(os.arch).mockReturnValue(arch as NodeJS.Architecture)
jest.spyOn(toolCache, 'find').mockReturnValue('') vi.mocked(toolCache.find).mockReturnValue('')
jest.spyOn(toolCache, 'downloadTool').mockImplementation((_) => { vi.mocked(toolCache.downloadTool).mockImplementation((_) => {
throw new toolCache.HTTPError(404) throw new toolCache.HTTPError(404)
}) })
await expect(run.downloadKubectl(kubectlVersion)).rejects.toThrow( await expect(run.downloadKubectl(kubectlVersion)).rejects.toThrow(
@ -152,11 +157,10 @@ describe('Testing all functions in run file.', () => {
expect(toolCache.downloadTool).toHaveBeenCalled() expect(toolCache.downloadTool).toHaveBeenCalled()
}) })
test('downloadKubectl() - return path to existing cache of kubectl', async () => { test('downloadKubectl() - return path to existing cache of kubectl', async () => {
jest.spyOn(core, 'getInput').mockImplementation(() => 'v1.15.5') vi.mocked(core.getInput).mockImplementation(() => 'v1.15.5')
jest.spyOn(toolCache, 'find').mockReturnValue('pathToCachedTool') vi.mocked(toolCache.find).mockReturnValue('pathToCachedTool')
jest.spyOn(os, 'type').mockReturnValue('Windows_NT') vi.mocked(os.type).mockReturnValue('Windows_NT')
jest.spyOn(fs, 'chmodSync').mockImplementation(() => {}) vi.mocked(fs.chmodSync).mockImplementation(() => {})
jest.spyOn(toolCache, 'downloadTool')
expect(await run.downloadKubectl('v1.15.0')).toBe( expect(await run.downloadKubectl('v1.15.0')).toBe(
path.join('pathToCachedTool', 'kubectl.exe') path.join('pathToCachedTool', 'kubectl.exe')
) )
@ -169,8 +173,8 @@ describe('Testing all functions in run file.', () => {
expect(toolCache.downloadTool).not.toHaveBeenCalled() expect(toolCache.downloadTool).not.toHaveBeenCalled()
}) })
test('getLatestPatchVersion() - download and return latest patch version', async () => { test('getLatestPatchVersion() - download and return latest patch version', async () => {
jest.spyOn(toolCache, 'downloadTool').mockResolvedValue('pathToTool') vi.mocked(toolCache.downloadTool).mockResolvedValue('pathToTool')
jest.spyOn(fs, 'readFileSync').mockReturnValue('v1.27.15') vi.mocked(fs.readFileSync).mockReturnValue('v1.27.15')
const result = await getLatestPatchVersion('1', '27') const result = await getLatestPatchVersion('1', '27')
@ -181,8 +185,8 @@ describe('Testing all functions in run file.', () => {
}) })
test('getLatestPatchVersion() - throw error when patch version is empty', async () => { test('getLatestPatchVersion() - throw error when patch version is empty', async () => {
jest.spyOn(toolCache, 'downloadTool').mockResolvedValue('pathToTool') vi.mocked(toolCache.downloadTool).mockResolvedValue('pathToTool')
jest.spyOn(fs, 'readFileSync').mockReturnValue('') vi.mocked(fs.readFileSync).mockReturnValue('')
await expect(getLatestPatchVersion('1', '27')).rejects.toThrow( await expect(getLatestPatchVersion('1', '27')).rejects.toThrow(
'Failed to get latest patch version for 1.27' 'Failed to get latest patch version for 1.27'
@ -190,17 +194,17 @@ describe('Testing all functions in run file.', () => {
}) })
test('getLatestPatchVersion() - throw error when download fails', async () => { test('getLatestPatchVersion() - throw error when download fails', async () => {
jest vi.mocked(toolCache.downloadTool).mockRejectedValue(
.spyOn(toolCache, 'downloadTool') new Error('Network error')
.mockRejectedValue(new Error('Network error')) )
await expect(getLatestPatchVersion('1', '27')).rejects.toThrow( await expect(getLatestPatchVersion('1', '27')).rejects.toThrow(
'Failed to get latest patch version for 1.27' 'Failed to get latest patch version for 1.27'
) )
}) })
test('resolveKubectlVersion() - expands major.minor to latest patch', async () => { test('resolveKubectlVersion() - expands major.minor to latest patch', async () => {
jest.spyOn(toolCache, 'downloadTool').mockResolvedValue('pathToTool') vi.mocked(toolCache.downloadTool).mockResolvedValue('pathToTool')
jest.spyOn(fs, 'readFileSync').mockReturnValue('v1.27.15') vi.mocked(fs.readFileSync).mockReturnValue('v1.27.15')
const result = await run.resolveKubectlVersion('1.27') const result = await run.resolveKubectlVersion('1.27')
expect(result).toBe('v1.27.15') expect(result).toBe('v1.27.15')
@ -215,20 +219,20 @@ describe('Testing all functions in run file.', () => {
expect(result).toBe('v1.27.15') expect(result).toBe('v1.27.15')
}) })
test('resolveKubectlVersion() - expands v-prefixed major.minor to latest patch', async () => { test('resolveKubectlVersion() - expands v-prefixed major.minor to latest patch', async () => {
jest.spyOn(toolCache, 'downloadTool').mockResolvedValue('pathToTool') vi.mocked(toolCache.downloadTool).mockResolvedValue('pathToTool')
jest.spyOn(fs, 'readFileSync').mockReturnValue('v1.27.15') vi.mocked(fs.readFileSync).mockReturnValue('v1.27.15')
const result = await run.resolveKubectlVersion('v1.27') const result = await run.resolveKubectlVersion('v1.27')
expect(result).toBe('v1.27.15') expect(result).toBe('v1.27.15')
}) })
test('run() - download specified version and set output', async () => { test('run() - download specified version and set output', async () => {
jest.spyOn(core, 'getInput').mockReturnValue('v1.15.5') vi.mocked(core.getInput).mockReturnValue('v1.15.5')
jest.spyOn(toolCache, 'find').mockReturnValue('pathToCachedTool') vi.mocked(toolCache.find).mockReturnValue('pathToCachedTool')
jest.spyOn(os, 'type').mockReturnValue('Windows_NT') vi.mocked(os.type).mockReturnValue('Windows_NT')
jest.spyOn(fs, 'chmodSync').mockImplementation() vi.mocked(fs.chmodSync).mockImplementation()
jest.spyOn(core, 'addPath').mockImplementation() vi.mocked(core.addPath).mockImplementation()
jest.spyOn(console, 'log').mockImplementation() vi.spyOn(console, 'log').mockImplementation()
jest.spyOn(core, 'setOutput').mockImplementation() vi.mocked(core.setOutput).mockImplementation()
expect(await run.run()).toBeUndefined() expect(await run.run()).toBeUndefined()
expect(core.getInput).toHaveBeenCalledWith('version', {required: true}) expect(core.getInput).toHaveBeenCalledWith('version', {required: true})
expect(core.addPath).toHaveBeenCalledWith('pathToCachedTool') expect(core.addPath).toHaveBeenCalledWith('pathToCachedTool')
@ -238,17 +242,15 @@ describe('Testing all functions in run file.', () => {
) )
}) })
test('run() - get latest version, download it and set output', async () => { test('run() - get latest version, download it and set output', async () => {
jest.spyOn(core, 'getInput').mockReturnValue('latest') vi.mocked(core.getInput).mockReturnValue('latest')
jest vi.mocked(toolCache.downloadTool).mockResolvedValue('pathToTool')
.spyOn(toolCache, 'downloadTool') vi.mocked(fs.readFileSync).mockReturnValue('v1.20.4')
.mockReturnValue(Promise.resolve('pathToTool')) vi.mocked(toolCache.find).mockReturnValue('pathToCachedTool')
jest.spyOn(fs, 'readFileSync').mockReturnValue('v1.20.4') vi.mocked(os.type).mockReturnValue('Windows_NT')
jest.spyOn(toolCache, 'find').mockReturnValue('pathToCachedTool') vi.mocked(fs.chmodSync).mockImplementation()
jest.spyOn(os, 'type').mockReturnValue('Windows_NT') vi.mocked(core.addPath).mockImplementation()
jest.spyOn(fs, 'chmodSync').mockImplementation() vi.spyOn(console, 'log').mockImplementation()
jest.spyOn(core, 'addPath').mockImplementation() vi.mocked(core.setOutput).mockImplementation()
jest.spyOn(console, 'log').mockImplementation()
jest.spyOn(core, 'setOutput').mockImplementation()
expect(await run.run()).toBeUndefined() expect(await run.run()).toBeUndefined()
expect(toolCache.downloadTool).toHaveBeenCalledWith( expect(toolCache.downloadTool).toHaveBeenCalledWith(
'https://dl.k8s.io/release/stable.txt' 'https://dl.k8s.io/release/stable.txt'

View file

@ -8,7 +8,7 @@ import {
getKubectlArch, getKubectlArch,
getExecutableExtension, getExecutableExtension,
getLatestPatchVersion getLatestPatchVersion
} from './helpers' } from './helpers.js'
const kubectlToolName = 'kubectl' const kubectlToolName = 'kubectl'
const stableKubectlVersion = 'v1.15.0' const stableKubectlVersion = 'v1.15.0'

View file

@ -1,8 +1,12 @@
{ {
"compilerOptions": { "compilerOptions": {
"target": "ES2020", "target": "ES2020",
"module": "commonjs", "module": "NodeNext",
"lib": ["ES2020", "DOM"] "moduleResolution": "NodeNext",
"rootDir": "./src",
"outDir": "./lib",
"skipLibCheck": true,
"noEmit": true
}, },
"exclude": ["node_modules", "test"] "exclude": ["node_modules", "**/*.test.ts", "vitest.config.ts"]
} }

10
vitest.config.ts Normal file
View file

@ -0,0 +1,10 @@
import {defineConfig} from 'vitest/config'
export default defineConfig({
test: {
globals: true,
environment: 'node',
include: ['**/*.test.ts'],
clearMocks: true
}
})