mirror of
https://github.com/Azure/k8s-deploy.git
synced 2026-06-25 05:59:26 +08:00
Migrate to esbuild/Vitest and upgrade @actions/* to ESM-only versions (#492)
* Migrate build toolchain from ncc/Jest to esbuild/Vitest Replace the legacy ncc/Jest/Babel build stack with a modern ESM toolchain: Build: - Replace @vercel/ncc with esbuild (--platform=node --target=node20 --format=esm) - Add createRequire banner for CJS interop in ESM bundle - Add "type": "module" to package.json - Add tsc --noEmit typecheck script (esbuild strips types without checking) - Add typecheck to husky pre-commit hook Dependencies: - Bump @actions/core@3, exec@3, io@3, tool-cache@4 (ESM-only) - Replace jest/ts-jest/@babel/* with vitest@4 Tests: - Convert 29 test files: jest.fn()→vi.fn(), jest.mock()→vi.mock(), jest.spyOn()→vi.spyOn() - Fix vitest 4 compat: mockImplementation requires args, mock call tracking, await .rejects CI: - Update build step from ncc build → npm run build - Update composite action to use npm run build * Switch tsconfig to NodeNext module resolution Change module/moduleResolution from ES2022/bundler to NodeNext/NodeNext and target from ES2022 to ES2020. - Add .js extensions to all relative imports across 59 source/test files (required by NodeNext module resolution) - Add vitest/globals to tsconfig types array for global test API declarations
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import {createInlineArray} from './arrayUtils'
|
||||
import {createInlineArray} from './arrayUtils.js'
|
||||
|
||||
describe('array utilities', () => {
|
||||
it('creates an inline array', () => {
|
||||
|
||||
@@ -1,15 +1,18 @@
|
||||
import {vi} from 'vitest'
|
||||
vi.mock('@actions/io')
|
||||
|
||||
import * as io from '@actions/io'
|
||||
import {checkDockerPath} from './dockerUtils'
|
||||
import {checkDockerPath} from './dockerUtils.js'
|
||||
|
||||
describe('docker utilities', () => {
|
||||
it('checks if docker is installed', async () => {
|
||||
// docker installed
|
||||
const path = 'path'
|
||||
jest.spyOn(io, 'which').mockImplementationOnce(async () => path)
|
||||
vi.spyOn(io, 'which').mockImplementationOnce(async () => path)
|
||||
expect(() => checkDockerPath()).not.toThrow()
|
||||
|
||||
// docker not installed
|
||||
jest.spyOn(io, 'which').mockImplementationOnce(async () => {
|
||||
vi.spyOn(io, 'which').mockImplementationOnce(async () => {
|
||||
throw new Error('not found')
|
||||
})
|
||||
await expect(() => checkDockerPath()).rejects.toThrow()
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import * as io from '@actions/io'
|
||||
import {DeploymentConfig} from '../types/deploymentConfig'
|
||||
import {DeploymentConfig} from '../types/deploymentConfig.js'
|
||||
import * as core from '@actions/core'
|
||||
import {DockerExec} from '../types/docker'
|
||||
import {getNormalizedPath} from './githubUtils'
|
||||
import {DockerExec} from '../types/docker.js'
|
||||
import {getNormalizedPath} from './githubUtils.js'
|
||||
|
||||
export async function getDeploymentConfig(): Promise<DeploymentConfig> {
|
||||
let helmChartPaths: string[] =
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
import {parseDuration} from './durationUtils'
|
||||
import {vi, type Mocked} from 'vitest'
|
||||
import {parseDuration} from './durationUtils.js'
|
||||
import * as core from '@actions/core'
|
||||
|
||||
// Mock core.debug
|
||||
jest.mock('@actions/core')
|
||||
const mockCore = core as jest.Mocked<typeof core>
|
||||
vi.mock('@actions/core')
|
||||
const mockCore = core as Mocked<typeof core>
|
||||
|
||||
// Test data constants
|
||||
const VALID_TIMEOUTS = {
|
||||
@@ -46,7 +47,7 @@ const expectInvalidTimeout = (input: string, expectedError: string) => {
|
||||
|
||||
describe('validateTimeoutDuration', () => {
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks()
|
||||
vi.clearAllMocks()
|
||||
})
|
||||
|
||||
describe('valid timeout formats', () => {
|
||||
@@ -90,7 +91,7 @@ describe('validateTimeoutDuration', () => {
|
||||
'No unit specified for timeout "5", assuming minutes'
|
||||
)
|
||||
|
||||
jest.clearAllMocks()
|
||||
vi.clearAllMocks()
|
||||
|
||||
parseDuration('30s')
|
||||
expect(mockCore.debug).not.toHaveBeenCalled()
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
import * as fileUtils from './fileUtils'
|
||||
import {vi} from 'vitest'
|
||||
import * as fileUtils from './fileUtils.js'
|
||||
|
||||
import * as yaml from 'js-yaml'
|
||||
import fs from 'node:fs'
|
||||
import * as path from 'path'
|
||||
import {K8sObject} from '../types/k8sObject'
|
||||
import {K8sObject} from '../types/k8sObject.js'
|
||||
|
||||
const sampleYamlUrl =
|
||||
'https://raw.githubusercontent.com/kubernetes/website/main/content/en/examples/controllers/nginx-deployment.yaml'
|
||||
@@ -69,7 +70,7 @@ describe('File utils', () => {
|
||||
'manifest_test_dir'
|
||||
)
|
||||
|
||||
expect(
|
||||
await expect(
|
||||
fileUtils.getFilesFromDirectoriesAndURLs([badPath, goodPath])
|
||||
).rejects.toThrow()
|
||||
})
|
||||
@@ -108,8 +109,8 @@ describe('File utils', () => {
|
||||
|
||||
describe('moving files to temp', () => {
|
||||
it('correctly moves the contents of a file to the temporary directory', () => {
|
||||
jest.spyOn(fs, 'writeFileSync').mockImplementation(() => {})
|
||||
jest.spyOn(fs, 'readFileSync').mockImplementation((filename) => {
|
||||
vi.spyOn(fs, 'writeFileSync').mockImplementation(() => {})
|
||||
vi.spyOn(fs, 'readFileSync').mockImplementation((filename) => {
|
||||
return 'test contents'
|
||||
})
|
||||
const originalFilePath = path.join('path', 'in', 'repo')
|
||||
|
||||
@@ -4,10 +4,10 @@ import * as path from 'path'
|
||||
import * as core from '@actions/core'
|
||||
import * as os from 'os'
|
||||
import * as yaml from 'js-yaml'
|
||||
import {Errorable, succeeded, failed, Failed} from '../types/errorable'
|
||||
import {getCurrentTime} from './timeUtils'
|
||||
import {isHttpUrl} from './githubUtils'
|
||||
import {K8sObject} from '../types/k8sObject'
|
||||
import {Errorable, succeeded, failed, Failed} from '../types/errorable.js'
|
||||
import {getCurrentTime} from './timeUtils.js'
|
||||
import {isHttpUrl} from './githubUtils.js'
|
||||
import {K8sObject} from '../types/k8sObject.js'
|
||||
|
||||
export const urlFileKind = 'urlfile'
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ import {
|
||||
getNormalizedPath,
|
||||
isHttpUrl,
|
||||
normalizeWorkflowStrLabel
|
||||
} from './githubUtils'
|
||||
} from './githubUtils.js'
|
||||
|
||||
describe('Github utils', () => {
|
||||
it('normalizes workflow string labels', () => {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import {GitHubClient, OkStatusCode} from '../types/githubClient'
|
||||
import {GitHubClient, OkStatusCode} from '../types/githubClient.js'
|
||||
import * as core from '@actions/core'
|
||||
|
||||
export async function getWorkflowFilePath(
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
import {vi} from 'vitest'
|
||||
vi.mock('@actions/core')
|
||||
|
||||
import * as core from '@actions/core'
|
||||
import {ExecOutput} from '@actions/exec'
|
||||
import {checkForErrors} from './kubectlUtils'
|
||||
import {checkForErrors} from './kubectlUtils.js'
|
||||
|
||||
describe('Kubectl utils', () => {
|
||||
it('checks for errors', () => {
|
||||
@@ -39,7 +42,8 @@ describe('Kubectl utils', () => {
|
||||
).toThrow()
|
||||
|
||||
// with warn behavior
|
||||
jest.spyOn(core, 'warning').mockImplementation(() => {})
|
||||
const warnSpy = vi.spyOn(core, 'warning').mockImplementation(() => {})
|
||||
warnSpy.mockClear()
|
||||
let warningCalls = 0
|
||||
expect(() => checkForErrors([success], true)).not.toThrow()
|
||||
expect(core.warning).toHaveBeenCalledTimes(warningCalls)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import * as core from '@actions/core'
|
||||
import {ExecOutput} from '@actions/exec'
|
||||
import {Kubectl} from '../types/kubectl'
|
||||
import {Kubectl} from '../types/kubectl.js'
|
||||
|
||||
const NAMESPACE = 'namespace'
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import {KubernetesWorkload} from '../types/kubernetesTypes'
|
||||
import {KubernetesWorkload} from '../types/kubernetesTypes.js'
|
||||
|
||||
export function getImagePullSecrets(inputObject: any) {
|
||||
const kind = inputObject?.kind?.toLowerCase()
|
||||
|
||||
@@ -3,7 +3,7 @@ import {
|
||||
isServiceEntity,
|
||||
KubernetesWorkload,
|
||||
NullInputObjectError
|
||||
} from '../types/kubernetesTypes'
|
||||
} from '../types/kubernetesTypes.js'
|
||||
|
||||
export function updateSpecLabels(
|
||||
inputObject: any,
|
||||
|
||||
@@ -1,10 +1,29 @@
|
||||
import * as manifestStabilityUtils from './manifestStabilityUtils'
|
||||
import {Kubectl} from '../types/kubectl'
|
||||
import {ResourceTypeFleet, ResourceTypeManagedCluster} from '../actions/deploy'
|
||||
import {vi} from 'vitest'
|
||||
import type {MockInstance} from 'vitest'
|
||||
vi.mock('@actions/core', async (importOriginal) => {
|
||||
const actual: any = await importOriginal()
|
||||
return {
|
||||
...actual,
|
||||
getInput: vi.fn().mockReturnValue(''),
|
||||
debug: vi.fn(),
|
||||
info: vi.fn(),
|
||||
warning: vi.fn(),
|
||||
error: vi.fn(),
|
||||
setFailed: vi.fn(),
|
||||
setOutput: vi.fn()
|
||||
}
|
||||
})
|
||||
|
||||
import * as manifestStabilityUtils from './manifestStabilityUtils.js'
|
||||
import {Kubectl} from '../types/kubectl.js'
|
||||
import {
|
||||
ResourceTypeFleet,
|
||||
ResourceTypeManagedCluster
|
||||
} from '../actions/deploy.js'
|
||||
import {ExecOutput} from '@actions/exec'
|
||||
import {exitCode, stdout} from 'process'
|
||||
import * as core from '@actions/core'
|
||||
import * as timeUtils from './timeUtils'
|
||||
import * as timeUtils from './timeUtils.js'
|
||||
|
||||
describe('manifestStabilityUtils', () => {
|
||||
const kc = new Kubectl('')
|
||||
@@ -17,8 +36,8 @@ describe('manifestStabilityUtils', () => {
|
||||
]
|
||||
|
||||
it('should return immediately if the resource type is fleet', async () => {
|
||||
const spy = jest.spyOn(manifestStabilityUtils, 'checkManifestStability')
|
||||
const checkRolloutStatusSpy = jest.spyOn(kc, 'checkRolloutStatus')
|
||||
const spy = vi.spyOn(manifestStabilityUtils, 'checkManifestStability')
|
||||
const checkRolloutStatusSpy = vi.spyOn(kc, 'checkRolloutStatus')
|
||||
await manifestStabilityUtils.checkManifestStability(
|
||||
kc,
|
||||
resources,
|
||||
@@ -30,8 +49,8 @@ describe('manifestStabilityUtils', () => {
|
||||
})
|
||||
|
||||
it('should run fully if the resource type is managedCluster', async () => {
|
||||
const spy = jest.spyOn(manifestStabilityUtils, 'checkManifestStability')
|
||||
const checkRolloutStatusSpy = jest
|
||||
const spy = vi.spyOn(manifestStabilityUtils, 'checkManifestStability')
|
||||
const checkRolloutStatusSpy = vi
|
||||
.spyOn(kc, 'checkRolloutStatus')
|
||||
.mockImplementation(() => {
|
||||
return new Promise<ExecOutput>((resolve, reject) => {
|
||||
@@ -54,7 +73,7 @@ describe('manifestStabilityUtils', () => {
|
||||
|
||||
it('should pass timeout to checkRolloutStatus when provided', async () => {
|
||||
const timeout = '300s'
|
||||
const checkRolloutStatusSpy = jest
|
||||
const checkRolloutStatusSpy = vi
|
||||
.spyOn(kc, 'checkRolloutStatus')
|
||||
.mockImplementation(() => {
|
||||
return new Promise<ExecOutput>((resolve, reject) => {
|
||||
@@ -82,7 +101,7 @@ describe('manifestStabilityUtils', () => {
|
||||
})
|
||||
|
||||
it('should call checkRolloutStatus without timeout when not provided', async () => {
|
||||
const checkRolloutStatusSpy = jest
|
||||
const checkRolloutStatusSpy = vi
|
||||
.spyOn(kc, 'checkRolloutStatus')
|
||||
.mockImplementation(() => {
|
||||
return new Promise<ExecOutput>((resolve, reject) => {
|
||||
@@ -111,19 +130,19 @@ describe('manifestStabilityUtils', () => {
|
||||
|
||||
describe('checkManifestStability failure and resource-specific scenarios', () => {
|
||||
let kc: Kubectl
|
||||
let coreErrorSpy: jest.SpyInstance
|
||||
let coreInfoSpy: jest.SpyInstance
|
||||
let coreWarningSpy: jest.SpyInstance
|
||||
let coreErrorSpy: MockInstance
|
||||
let coreInfoSpy: MockInstance
|
||||
let coreWarningSpy: MockInstance
|
||||
|
||||
beforeEach(() => {
|
||||
kc = new Kubectl('', 'default')
|
||||
coreErrorSpy = jest.spyOn(core, 'error').mockImplementation()
|
||||
coreInfoSpy = jest.spyOn(core, 'info').mockImplementation()
|
||||
coreWarningSpy = jest.spyOn(core, 'warning').mockImplementation()
|
||||
coreErrorSpy = vi.spyOn(core, 'error').mockImplementation(() => {})
|
||||
coreInfoSpy = vi.spyOn(core, 'info').mockImplementation(() => {})
|
||||
coreWarningSpy = vi.spyOn(core, 'warning').mockImplementation(() => {})
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
jest.restoreAllMocks()
|
||||
vi.restoreAllMocks()
|
||||
})
|
||||
|
||||
it('should call describe and collect errors when a rollout fails', async () => {
|
||||
@@ -135,10 +154,10 @@ describe('checkManifestStability failure and resource-specific scenarios', () =>
|
||||
'Events:\n Type\tReason\tMessage\n Normal\tScalingReplicaSet\tScaled up replica set failing-app-123 to 1'
|
||||
|
||||
// Arrange: Mock rollout to fail and describe to succeed
|
||||
const checkRolloutStatusSpy = jest
|
||||
const checkRolloutStatusSpy = vi
|
||||
.spyOn(kc, 'checkRolloutStatus')
|
||||
.mockRejectedValue(rolloutError)
|
||||
const describeSpy = jest.spyOn(kc, 'describe').mockResolvedValue({
|
||||
const describeSpy = vi.spyOn(kc, 'describe').mockResolvedValue({
|
||||
stdout: describeOutput,
|
||||
stderr: '',
|
||||
exitCode: 0
|
||||
@@ -177,10 +196,10 @@ describe('checkManifestStability failure and resource-specific scenarios', () =>
|
||||
'Events:\n Type\tReason\tMessage\n Normal\tScalingReplicaSet\tScaled up replica set failing-app-123 to 1'
|
||||
|
||||
// Arrange: Mock rollout to fail and describe to succeed
|
||||
const checkRolloutStatusSpy = jest
|
||||
const checkRolloutStatusSpy = vi
|
||||
.spyOn(kc, 'checkRolloutStatus')
|
||||
.mockRejectedValue(rolloutError)
|
||||
const describeSpy = jest.spyOn(kc, 'describe').mockResolvedValue({
|
||||
const describeSpy = vi.spyOn(kc, 'describe').mockResolvedValue({
|
||||
stdout: describeOutput,
|
||||
stderr: '',
|
||||
exitCode: 0
|
||||
@@ -216,10 +235,10 @@ describe('checkManifestStability failure and resource-specific scenarios', () =>
|
||||
const resources = [{type: 'Pod', name: 'test-pod', namespace: 'default'}]
|
||||
|
||||
// Arrange: Spy on checkPodStatus and checkRolloutStatus
|
||||
const checkPodStatusSpy = jest
|
||||
const checkPodStatusSpy = vi
|
||||
.spyOn(manifestStabilityUtils, 'checkPodStatus')
|
||||
.mockResolvedValue() // Assume pod becomes ready
|
||||
const checkRolloutStatusSpy = jest.spyOn(kc, 'checkRolloutStatus')
|
||||
const checkRolloutStatusSpy = vi.spyOn(kc, 'checkRolloutStatus')
|
||||
|
||||
// Act
|
||||
await manifestStabilityUtils.checkManifestStability(
|
||||
@@ -240,10 +259,10 @@ describe('checkManifestStability failure and resource-specific scenarios', () =>
|
||||
const podError = new Error('Pod rollout failed')
|
||||
|
||||
// Arrange: Mock checkPodStatus to fail
|
||||
const checkPodStatusSpy = jest
|
||||
const checkPodStatusSpy = vi
|
||||
.spyOn(manifestStabilityUtils, 'checkPodStatus')
|
||||
.mockRejectedValue(podError)
|
||||
const describeSpy = jest.spyOn(kc, 'describe').mockResolvedValue({
|
||||
const describeSpy = vi.spyOn(kc, 'describe').mockResolvedValue({
|
||||
stdout: 'describe output',
|
||||
stderr: '',
|
||||
exitCode: 0
|
||||
@@ -271,7 +290,7 @@ describe('checkManifestStability failure and resource-specific scenarios', () =>
|
||||
|
||||
it('should wait for external IP for a LoadBalancer service', async () => {
|
||||
//Spying on sleep to avoid actual delays in tests
|
||||
jest.spyOn(timeUtils, 'sleep').mockResolvedValue(undefined)
|
||||
vi.spyOn(timeUtils, 'sleep').mockResolvedValue(undefined)
|
||||
const resources = [
|
||||
{type: 'service', name: 'test-svc', namespace: 'default'}
|
||||
]
|
||||
@@ -285,7 +304,7 @@ describe('checkManifestStability failure and resource-specific scenarios', () =>
|
||||
}
|
||||
|
||||
// Arrange: Mock getResource to simulate the IP being assigned on the second poll
|
||||
const getResourceSpy = jest
|
||||
const getResourceSpy = vi
|
||||
.spyOn(kc, 'getResource')
|
||||
// First call: Initial service check
|
||||
.mockResolvedValueOnce({
|
||||
@@ -328,10 +347,10 @@ describe('checkManifestStability failure and resource-specific scenarios', () =>
|
||||
|
||||
// Arrange: Mock getService to fail, and describe to succeed
|
||||
// Note: We mock getResource because getService is a private helper
|
||||
const getResourceSpy = jest
|
||||
const getResourceSpy = vi
|
||||
.spyOn(kc, 'getResource')
|
||||
.mockRejectedValue(getServiceError)
|
||||
const describeSpy = jest.spyOn(kc, 'describe').mockResolvedValue({
|
||||
const describeSpy = vi.spyOn(kc, 'describe').mockResolvedValue({
|
||||
stdout: 'describe output',
|
||||
stderr: '',
|
||||
exitCode: 0
|
||||
@@ -369,7 +388,7 @@ describe('checkManifestStability failure and resource-specific scenarios', () =>
|
||||
}
|
||||
|
||||
// Arrange
|
||||
const getResourceSpy = jest.spyOn(kc, 'getResource').mockResolvedValue({
|
||||
const getResourceSpy = vi.spyOn(kc, 'getResource').mockResolvedValue({
|
||||
stdout: JSON.stringify(clusterIpService),
|
||||
stderr: '',
|
||||
exitCode: 0
|
||||
@@ -392,19 +411,19 @@ describe('checkManifestStability failure and resource-specific scenarios', () =>
|
||||
|
||||
describe('checkManifestStability additional scenarios', () => {
|
||||
let kc: Kubectl
|
||||
let coreErrorSpy: jest.SpyInstance
|
||||
let coreInfoSpy: jest.SpyInstance
|
||||
let coreWarningSpy: jest.SpyInstance
|
||||
let coreErrorSpy: MockInstance
|
||||
let coreInfoSpy: MockInstance
|
||||
let coreWarningSpy: MockInstance
|
||||
|
||||
beforeEach(() => {
|
||||
kc = new Kubectl('')
|
||||
coreErrorSpy = jest.spyOn(core, 'error').mockImplementation()
|
||||
coreInfoSpy = jest.spyOn(core, 'info').mockImplementation()
|
||||
coreWarningSpy = jest.spyOn(core, 'warning').mockImplementation()
|
||||
coreErrorSpy = vi.spyOn(core, 'error').mockImplementation(() => {})
|
||||
coreInfoSpy = vi.spyOn(core, 'info').mockImplementation(() => {})
|
||||
coreWarningSpy = vi.spyOn(core, 'warning').mockImplementation(() => {})
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
jest.restoreAllMocks()
|
||||
vi.restoreAllMocks()
|
||||
})
|
||||
|
||||
it('should aggregate errors from deployment and pod failures', async () => {
|
||||
@@ -416,15 +435,15 @@ describe('checkManifestStability additional scenarios', () => {
|
||||
const podError = new Error('Pod not ready in time')
|
||||
|
||||
// Arrange: Mock failures
|
||||
const checkRolloutStatusSpy = jest
|
||||
const checkRolloutStatusSpy = vi
|
||||
.spyOn(kc, 'checkRolloutStatus')
|
||||
.mockRejectedValue(deploymentError)
|
||||
// For pod: simulate a pod check failure
|
||||
const checkPodStatusSpy = jest
|
||||
const checkPodStatusSpy = vi
|
||||
.spyOn(manifestStabilityUtils, 'checkPodStatus')
|
||||
.mockRejectedValue(podError)
|
||||
// For both, simulate a successful describe call to provide additional details
|
||||
const describeSpy = jest.spyOn(kc, 'describe').mockResolvedValue({
|
||||
const describeSpy = vi.spyOn(kc, 'describe').mockResolvedValue({
|
||||
stdout: 'describe aggregated output',
|
||||
stderr: '',
|
||||
exitCode: 0
|
||||
@@ -463,25 +482,25 @@ describe('checkManifestStability additional scenarios', () => {
|
||||
|
||||
// Arrange:
|
||||
// Deployment rollout succeeds
|
||||
jest.spyOn(kc, 'checkRolloutStatus').mockResolvedValue({
|
||||
vi.spyOn(kc, 'checkRolloutStatus').mockResolvedValue({
|
||||
exitCode: 0,
|
||||
stderr: '',
|
||||
stdout: ''
|
||||
})
|
||||
// Pod becomes ready
|
||||
jest.spyOn(manifestStabilityUtils, 'checkPodStatus').mockResolvedValue()
|
||||
vi.spyOn(manifestStabilityUtils, 'checkPodStatus').mockResolvedValue()
|
||||
// Simulate a LoadBalancer service that already has an external IP
|
||||
const stableService = {
|
||||
spec: {type: 'LoadBalancer'},
|
||||
status: {loadBalancer: {ingress: [{ip: '1.2.3.4'}]}}
|
||||
}
|
||||
jest.spyOn(kc, 'getResource').mockResolvedValue({
|
||||
vi.spyOn(kc, 'getResource').mockResolvedValue({
|
||||
stdout: JSON.stringify(stableService),
|
||||
stderr: '',
|
||||
exitCode: 0
|
||||
})
|
||||
// Provide a describe result to avoid warnings
|
||||
jest.spyOn(kc, 'describe').mockResolvedValue({
|
||||
vi.spyOn(kc, 'describe').mockResolvedValue({
|
||||
stdout: 'describe output stable',
|
||||
stderr: '',
|
||||
exitCode: 0
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import * as core from '@actions/core'
|
||||
import * as KubernetesConstants from '../types/kubernetesTypes'
|
||||
import {Kubectl, Resource} from '../types/kubectl'
|
||||
import {checkForErrors} from './kubectlUtils'
|
||||
import {sleep} from './timeUtils'
|
||||
import {ResourceTypeFleet} from '../actions/deploy'
|
||||
import {ClusterType} from '../inputUtils'
|
||||
import * as KubernetesConstants from '../types/kubernetesTypes.js'
|
||||
import {Kubectl, Resource} from '../types/kubectl.js'
|
||||
import {checkForErrors} from './kubectlUtils.js'
|
||||
import {sleep} from './timeUtils.js'
|
||||
import {ResourceTypeFleet} from '../actions/deploy.js'
|
||||
import {ClusterType} from '../inputUtils.js'
|
||||
|
||||
const IS_SILENT = false
|
||||
const POD = 'pod'
|
||||
|
||||
@@ -1,14 +1,17 @@
|
||||
import * as fileUtils from './fileUtils'
|
||||
import * as manifestUpdateUtils from './manifestUpdateUtils'
|
||||
import {vi} from 'vitest'
|
||||
vi.mock('fs')
|
||||
|
||||
import * as fileUtils from './fileUtils.js'
|
||||
import * as manifestUpdateUtils from './manifestUpdateUtils.js'
|
||||
import * as path from 'path'
|
||||
import * as fs from 'fs'
|
||||
|
||||
describe('manifestUpdateUtils', () => {
|
||||
jest.spyOn(fileUtils, 'moveFileToTmpDir').mockImplementation((filename) => {
|
||||
vi.spyOn(fileUtils, 'moveFileToTmpDir').mockImplementation((filename) => {
|
||||
return path.join('/tmp', filename)
|
||||
})
|
||||
jest.spyOn(fs, 'writeFileSync').mockImplementation(() => {})
|
||||
jest.spyOn(fs, 'readFileSync').mockImplementation((filename) => {
|
||||
vi.spyOn(fs, 'writeFileSync').mockImplementation(() => {})
|
||||
vi.spyOn(fs, 'readFileSync').mockImplementation((filename) => {
|
||||
return 'test contents'
|
||||
})
|
||||
|
||||
|
||||
@@ -2,25 +2,25 @@ import * as core from '@actions/core'
|
||||
import * as fs from 'fs'
|
||||
import * as yaml from 'js-yaml'
|
||||
import * as path from 'path'
|
||||
import * as fileHelper from './fileUtils'
|
||||
import {moveFileToTmpDir} from './fileUtils'
|
||||
import * as fileHelper from './fileUtils.js'
|
||||
import {moveFileToTmpDir} from './fileUtils.js'
|
||||
import {
|
||||
InputObjectKindNotDefinedError,
|
||||
InputObjectMetadataNotDefinedError,
|
||||
isWorkloadEntity,
|
||||
KubernetesWorkload,
|
||||
NullInputObjectError
|
||||
} from '../types/kubernetesTypes'
|
||||
} from '../types/kubernetesTypes.js'
|
||||
import {
|
||||
getSpecSelectorLabels,
|
||||
setSpecSelectorLabels
|
||||
} from './manifestSpecLabelUtils'
|
||||
} from './manifestSpecLabelUtils.js'
|
||||
import {
|
||||
getImagePullSecrets,
|
||||
setImagePullSecrets
|
||||
} from './manifestPullSecretUtils'
|
||||
import {Resource} from '../types/kubectl'
|
||||
import {K8sObject} from '../types/k8sObject'
|
||||
} from './manifestPullSecretUtils.js'
|
||||
import {Resource} from '../types/kubectl.js'
|
||||
import {K8sObject} from '../types/k8sObject.js'
|
||||
|
||||
export function updateManifestFiles(manifestFilePaths: string[]) {
|
||||
if (manifestFilePaths?.length === 0) {
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
import {
|
||||
getImagePullSecrets,
|
||||
setImagePullSecrets
|
||||
} from './manifestPullSecretUtils'
|
||||
import {updateSpecLabels} from './manifestSpecLabelUtils'
|
||||
import {getReplicaCount} from './manifestUpdateUtils'
|
||||
} from './manifestPullSecretUtils.js'
|
||||
import {updateSpecLabels} from './manifestSpecLabelUtils.js'
|
||||
import {getReplicaCount} from './manifestUpdateUtils.js'
|
||||
import * as yaml from 'js-yaml'
|
||||
import * as fs from 'fs'
|
||||
import {isWorkloadEntity, isDeploymentEntity} from '../types/kubernetesTypes.js'
|
||||
|
||||
describe('ScaledJob Support', () => {
|
||||
let scaledJobObject: any
|
||||
@@ -57,13 +58,11 @@ describe('ScaledJob Support', () => {
|
||||
|
||||
describe('Workload Classification', () => {
|
||||
it('should classify ScaledJob as workload entity', () => {
|
||||
const {isWorkloadEntity} = require('../types/kubernetesTypes')
|
||||
expect(isWorkloadEntity('ScaledJob')).toBe(true)
|
||||
expect(isWorkloadEntity('scaledjob')).toBe(true)
|
||||
})
|
||||
|
||||
it('should not classify ScaledJob as deployment entity', () => {
|
||||
const {isDeploymentEntity} = require('../types/kubernetesTypes')
|
||||
expect(isDeploymentEntity('scaledjob')).toBe(false)
|
||||
expect(isDeploymentEntity('ScaledJob')).toBe(false)
|
||||
})
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import {Kubectl} from '../types/kubectl'
|
||||
import {Kubectl} from '../types/kubectl.js'
|
||||
|
||||
const trafficSplitAPIVersionPrefix = 'split.smi-spec.io'
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ import {
|
||||
cleanLabel,
|
||||
removeInvalidLabelCharacters,
|
||||
VALID_LABEL_REGEX
|
||||
} from '../utilities/workflowAnnotationUtils'
|
||||
} from '../utilities/workflowAnnotationUtils.js'
|
||||
|
||||
describe('WorkflowAnnotationUtils', () => {
|
||||
describe('cleanLabel', () => {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import {DeploymentConfig} from '../types/deploymentConfig'
|
||||
import {DeploymentConfig} from '../types/deploymentConfig.js'
|
||||
|
||||
const ANNOTATION_PREFIX = 'actions.github.com'
|
||||
|
||||
|
||||
Reference in New Issue
Block a user