k8s-set-context/src/types/method.test.ts
Suneha Bose 1f527c033f
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
2026-03-26 17:25:46 -04:00

31 lines
1.3 KiB
TypeScript

import {describe, test, expect} from 'vitest'
import {Method, parseMethod} from './method.js'
describe('Method type', () => {
test('it has required values', () => {
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)
})
test('it can parse valid values from a string', () => {
expect(parseMethod('kubeconfig')).toBe(Method.KUBECONFIG)
expect(parseMethod('Kubeconfig')).toBe(Method.KUBECONFIG)
expect(parseMethod('KUBECONFIG')).toBe(Method.KUBECONFIG)
expect(parseMethod('service-account')).toBe(Method.SERVICE_ACCOUNT)
expect(parseMethod('Service-Account')).toBe(Method.SERVICE_ACCOUNT)
expect(parseMethod('SERVICE-ACCOUNT')).toBe(Method.SERVICE_ACCOUNT)
expect(parseMethod('service-principal')).toBe(Method.SERVICE_PRINCIPAL)
expect(parseMethod('Service-Principal')).toBe(Method.SERVICE_PRINCIPAL)
expect(parseMethod('SERVICE-PRINCIPAL')).toBe(Method.SERVICE_PRINCIPAL)
})
test("it will return undefined if it can't parse values from a string", () => {
expect(parseMethod('invalid')).toBe(undefined)
expect(parseMethod('unsupportedType')).toBe(undefined)
})
})