mirror of
https://github.com/Azure/k8s-deploy.git
synced 2026-04-16 03:22:18 +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
120 lines
3.7 KiB
TypeScript
120 lines
3.7 KiB
TypeScript
import {
|
|
DEPLOYMENT_TYPES,
|
|
DiscoveryAndLoadBalancerResource,
|
|
isDeploymentEntity,
|
|
isIngressEntity,
|
|
isServiceEntity,
|
|
isWorkloadEntity,
|
|
KubernetesWorkload,
|
|
ResourceKindNotDefinedError,
|
|
ServiceTypes,
|
|
WORKLOAD_TYPES,
|
|
WORKLOAD_TYPES_WITH_ROLLOUT_STATUS
|
|
} from './kubernetesTypes.js'
|
|
|
|
describe('Kubernetes types', () => {
|
|
it('contains kubernetes workloads', () => {
|
|
expect(KubernetesWorkload.POD).toBe('Pod')
|
|
expect(KubernetesWorkload.REPLICASET).toBe('Replicaset')
|
|
expect(KubernetesWorkload.DEPLOYMENT).toBe('Deployment')
|
|
expect(KubernetesWorkload.STATEFUL_SET).toBe('StatefulSet')
|
|
expect(KubernetesWorkload.DAEMON_SET).toBe('DaemonSet')
|
|
expect(KubernetesWorkload.JOB).toBe('job')
|
|
expect(KubernetesWorkload.CRON_JOB).toBe('cronjob')
|
|
expect(KubernetesWorkload.SCALED_JOB).toBe('scaledjob')
|
|
})
|
|
|
|
it('contains discovery and load balancer resources', () => {
|
|
expect(DiscoveryAndLoadBalancerResource.SERVICE).toBe('service')
|
|
expect(DiscoveryAndLoadBalancerResource.INGRESS).toBe('ingress')
|
|
})
|
|
|
|
it('contains service types', () => {
|
|
expect(ServiceTypes.LOAD_BALANCER).toBe('LoadBalancer')
|
|
expect(ServiceTypes.NODE_PORT).toBe('NodePort')
|
|
expect(ServiceTypes.CLUSTER_IP).toBe('ClusterIP')
|
|
})
|
|
|
|
it('contains deployment types', () => {
|
|
const expected = [
|
|
'deployment',
|
|
'replicaset',
|
|
'daemonset',
|
|
'pod',
|
|
'statefulset'
|
|
]
|
|
expect(expected.every((val) => DEPLOYMENT_TYPES.includes(val))).toBe(true)
|
|
})
|
|
|
|
it('contains workload types', () => {
|
|
const expected = [
|
|
'deployment',
|
|
'replicaset',
|
|
'daemonset',
|
|
'pod',
|
|
'statefulset',
|
|
'job',
|
|
'cronjob',
|
|
'scaledjob'
|
|
]
|
|
expect(expected.every((val) => WORKLOAD_TYPES.includes(val))).toBe(true)
|
|
})
|
|
|
|
it('contains workload types with rollout status', () => {
|
|
const expected = ['deployment', 'daemonset', 'statefulset']
|
|
expect(
|
|
expected.every((val) =>
|
|
WORKLOAD_TYPES_WITH_ROLLOUT_STATUS.includes(val)
|
|
)
|
|
).toBe(true)
|
|
})
|
|
|
|
it('checks if kind is deployment entity', () => {
|
|
// throws on no kind
|
|
expect(() => isDeploymentEntity(undefined)).toThrow(
|
|
ResourceKindNotDefinedError
|
|
)
|
|
|
|
expect(isDeploymentEntity('deployment')).toBe(true)
|
|
expect(isDeploymentEntity('Deployment')).toBe(true)
|
|
expect(isDeploymentEntity('deploymenT')).toBe(true)
|
|
expect(isDeploymentEntity('DEPLOYMENT')).toBe(true)
|
|
})
|
|
|
|
it('checks if kind is workload entity', () => {
|
|
// throws on no kind
|
|
expect(() => isWorkloadEntity(undefined)).toThrow(
|
|
ResourceKindNotDefinedError
|
|
)
|
|
|
|
expect(isWorkloadEntity('deployment')).toBe(true)
|
|
expect(isWorkloadEntity('Deployment')).toBe(true)
|
|
expect(isWorkloadEntity('deploymenT')).toBe(true)
|
|
expect(isWorkloadEntity('DEPLOYMENT')).toBe(true)
|
|
})
|
|
|
|
it('checks if kind is service entity', () => {
|
|
// throws on no kind
|
|
expect(() => isServiceEntity(undefined)).toThrow(
|
|
ResourceKindNotDefinedError
|
|
)
|
|
|
|
expect(isServiceEntity('service')).toBe(true)
|
|
expect(isServiceEntity('Service')).toBe(true)
|
|
expect(isServiceEntity('servicE')).toBe(true)
|
|
expect(isServiceEntity('SERVICE')).toBe(true)
|
|
})
|
|
|
|
it('checks if kind is ingress entity', () => {
|
|
// throws on no kind
|
|
expect(() => isIngressEntity(undefined)).toThrow(
|
|
ResourceKindNotDefinedError
|
|
)
|
|
|
|
expect(isIngressEntity('ingress')).toBe(true)
|
|
expect(isIngressEntity('Ingress')).toBe(true)
|
|
expect(isIngressEntity('ingresS')).toBe(true)
|
|
expect(isIngressEntity('INGRESS')).toBe(true)
|
|
})
|
|
})
|