mirror of
https://github.com/Azure/k8s-deploy.git
synced 2026-04-19 05:32:19 +08:00
* 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
71 lines
2.4 KiB
TypeScript
71 lines
2.4 KiB
TypeScript
import {
|
|
getImagePullSecrets,
|
|
setImagePullSecrets
|
|
} 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
|
|
|
|
beforeEach(() => {
|
|
const fileContents = fs.readFileSync(
|
|
'test/unit/manifests/test-scaledjob.yml'
|
|
)
|
|
scaledJobObject = yaml.load(fileContents.toString()) as any
|
|
})
|
|
|
|
describe('Image Pull Secrets', () => {
|
|
it('should get image pull secrets from ScaledJob', () => {
|
|
const secrets = getImagePullSecrets(scaledJobObject)
|
|
expect(secrets).toEqual([{name: 'test-secret'}])
|
|
})
|
|
|
|
it('should set image pull secrets in ScaledJob', () => {
|
|
const newSecrets = [{name: 'new-secret'}, {name: 'another-secret'}]
|
|
setImagePullSecrets(scaledJobObject, newSecrets)
|
|
|
|
const updatedSecrets = getImagePullSecrets(scaledJobObject)
|
|
expect(updatedSecrets).toEqual(newSecrets)
|
|
})
|
|
})
|
|
|
|
describe('Spec Labels', () => {
|
|
it('should update spec labels in ScaledJob', () => {
|
|
const newLabels = new Map<string, string>()
|
|
newLabels['environment'] = 'test'
|
|
newLabels['version'] = '1.0.0'
|
|
|
|
updateSpecLabels(scaledJobObject, newLabels, false)
|
|
|
|
const updatedLabels =
|
|
scaledJobObject.spec.jobTargetRef.template.metadata.labels
|
|
expect(updatedLabels['app']).toBe('test-scaledjob') // original label
|
|
expect(updatedLabels['environment']).toBe('test') // new label
|
|
expect(updatedLabels['version']).toBe('1.0.0') // new label
|
|
})
|
|
})
|
|
|
|
describe('Replica Count', () => {
|
|
it('should return 0 for ScaledJob replica count', () => {
|
|
const replicaCount = getReplicaCount(scaledJobObject)
|
|
expect(replicaCount).toBe(0)
|
|
})
|
|
})
|
|
|
|
describe('Workload Classification', () => {
|
|
it('should classify ScaledJob as workload entity', () => {
|
|
expect(isWorkloadEntity('ScaledJob')).toBe(true)
|
|
expect(isWorkloadEntity('scaledjob')).toBe(true)
|
|
})
|
|
|
|
it('should not classify ScaledJob as deployment entity', () => {
|
|
expect(isDeploymentEntity('scaledjob')).toBe(false)
|
|
expect(isDeploymentEntity('ScaledJob')).toBe(false)
|
|
})
|
|
})
|
|
})
|