mirror of
https://github.com/Azure/k8s-set-context.git
synced 2026-06-29 10:49:28 +08:00
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:
@@ -1,7 +1,7 @@
|
||||
import {vi, describe, test, expect, beforeEach, afterEach} from 'vitest'
|
||||
import * as fs from 'fs'
|
||||
import * as core from '@actions/core'
|
||||
import {getRequiredInputError} from '../../tests/util'
|
||||
import {createKubeconfig, getDefaultKubeconfig} from './default'
|
||||
import {getRequiredInputError} from '../../tests/util.js'
|
||||
import {createKubeconfig, getDefaultKubeconfig} from './default.js'
|
||||
|
||||
describe('Default kubeconfig', () => {
|
||||
test('it creates a kubeconfig with proper format', () => {
|
||||
@@ -51,6 +51,11 @@ describe('Default kubeconfig', () => {
|
||||
process.env['INPUT_METHOD'] = 'default'
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
delete process.env['INPUT_KUBECONFIG']
|
||||
delete process.env['INPUT_KUBECONFIG-ENCODING']
|
||||
})
|
||||
|
||||
test('it throws error without kubeconfig', () => {
|
||||
expect(() => getDefaultKubeconfig()).toThrow(
|
||||
getRequiredInputError('kubeconfig')
|
||||
@@ -66,39 +71,25 @@ describe('Default kubeconfig', () => {
|
||||
|
||||
test('returns kubeconfig as plaintext when encoding is plaintext', () => {
|
||||
const kc = 'example kc'
|
||||
jest.spyOn(core, 'getInput').mockImplementation((name: string) => {
|
||||
if (name === 'method') return 'default'
|
||||
if (name === 'kubeconfig-encoding') return 'plaintext'
|
||||
if (name === 'kubeconfig') return kc
|
||||
return ''
|
||||
})
|
||||
process.env['INPUT_KUBECONFIG'] = kc
|
||||
process.env['INPUT_KUBECONFIG-ENCODING'] = 'plaintext'
|
||||
|
||||
expect(getDefaultKubeconfig()).toBe(kc)
|
||||
})
|
||||
|
||||
test('it gets default config through base64 kubeconfig input', () => {
|
||||
const kc = 'example kc'
|
||||
const base64Kc = Buffer.from(kc, 'utf-8').toString('base64')
|
||||
|
||||
jest.spyOn(core, 'getInput').mockImplementation((name: string) => {
|
||||
if (name === 'method') return 'default'
|
||||
if (name === 'kubeconfig-encoding') return 'base64'
|
||||
if (name === 'kubeconfig') return base64Kc
|
||||
return ''
|
||||
})
|
||||
process.env['INPUT_KUBECONFIG'] = base64Kc
|
||||
process.env['INPUT_KUBECONFIG-ENCODING'] = 'base64'
|
||||
|
||||
expect(getDefaultKubeconfig()).toBe(kc)
|
||||
})
|
||||
|
||||
test('it throws error for unknown kubeconfig-encoding', () => {
|
||||
const kc = 'example kc'
|
||||
const unknownEncoding = 'foobar'
|
||||
|
||||
jest.spyOn(core, 'getInput').mockImplementation((name: string) => {
|
||||
if (name === 'method') return 'default'
|
||||
if (name === 'kubeconfig-encoding') return unknownEncoding
|
||||
if (name === 'kubeconfig') return kc
|
||||
return ''
|
||||
})
|
||||
process.env['INPUT_KUBECONFIG'] = kc
|
||||
process.env['INPUT_KUBECONFIG-ENCODING'] = 'foobar'
|
||||
|
||||
expect(() => getDefaultKubeconfig()).toThrow(
|
||||
"Invalid kubeconfig-encoding: 'foobar'. Must be 'plaintext' or 'base64'."
|
||||
|
||||
Reference in New Issue
Block a user