Migrate to ESM with esbuild, vitest (#227)

* Migrate to ESM, esbuild, vitest, and update actions/* to latest

- Update @actions/core to 3.x, @actions/exec to 3.x, @actions/io to 3.x
- Replace @vercel/ncc + babel with esbuild (build.mjs) targeting Node 20 ESM
- Replace jest/babel-jest/ts-jest with vitest and @vitest/coverage-v8
- Update tsconfig to NodeNext module resolution with strict mode
- Add explicit .js extensions to all relative imports (NodeNext requirement)
- Fix implicit any index signatures in parseCluster and parseMethod
- Migrate all test files from jest to vi.mock/vi.mocked APIs
- Fix ESM module spying limitations using vi.mock() at module level
- Fix env var test pollution in default.test.ts with afterEach cleanup

* remove build.mjs and update build script

* update pkg lock

* update pkg lock
This commit is contained in:
Suneha Bose
2026-03-26 14:25:46 -07:00
committed by GitHub
parent eb220500b5
commit 1f527c033f
22 changed files with 1821 additions and 10364 deletions
+3 -2
View File
@@ -1,8 +1,9 @@
import {Cluster, parseCluster} from './cluster'
import {describe, test, expect} from 'vitest'
import {Cluster, parseCluster} from './cluster.js'
describe('Cluster type', () => {
test('it has required values', () => {
const vals = <any>Object.values(Cluster)
const vals = Object.values(Cluster) as string[]
expect(vals.includes('arc')).toBe(true)
expect(vals.includes('generic')).toBe(true)
})
+7 -6
View File
@@ -8,9 +8,10 @@ export enum Cluster {
* @param str The cluster type (case insensitive)
* @returns The Cluster enum or undefined if it can't be parsed
*/
export const parseCluster = (str: string): Cluster | undefined =>
Cluster[
Object.keys(Cluster).filter(
(k) => Cluster[k].toString().toLowerCase() === str.toLowerCase()
)[0] as keyof typeof Cluster
]
export const parseCluster = (str: string): Cluster | undefined => {
const key = Object.keys(Cluster).find(
(k) =>
Cluster[k as keyof typeof Cluster].toLowerCase() === str.toLowerCase()
) as keyof typeof Cluster | undefined
return key !== undefined ? Cluster[key] : undefined
}
+2 -1
View File
@@ -1,4 +1,5 @@
import {parseK8sSecret, K8sSecret} from './k8sSecret'
import {describe, test, expect} from 'vitest'
import {parseK8sSecret} from './k8sSecret.js'
describe('K8sSecret type', () => {
describe('Parsing from any', () => {
+3 -2
View File
@@ -1,8 +1,9 @@
import {Method, parseMethod} from './method'
import {describe, test, expect} from 'vitest'
import {Method, parseMethod} from './method.js'
describe('Method type', () => {
test('it has required values', () => {
const vals = <any>Object.values(Method)
const vals = Object.values(Method) as string[]
expect(vals.includes('kubeconfig')).toBe(true)
expect(vals.includes('service-account')).toBe(true)
expect(vals.includes('service-principal')).toBe(true)
+7 -6
View File
@@ -9,9 +9,10 @@ export enum Method {
* @param str The method (case insensitive)
* @returns The Method enum or undefined if it can't be parsed
*/
export const parseMethod = (str: string): Method | undefined =>
Method[
Object.keys(Method).filter(
(k) => Method[k].toString().toLowerCase() === str.toLowerCase()
)[0] as keyof typeof Method
]
export const parseMethod = (str: string): Method | undefined => {
const key = Object.keys(Method).find(
(k) =>
Method[k as keyof typeof Method].toLowerCase() === str.toLowerCase()
) as keyof typeof Method | undefined
return key !== undefined ? Method[key] : undefined
}