mirror of
https://github.com/Azure/k8s-deploy.git
synced 2026-06-24 21:50:00 +08:00
01cfe404ef
* 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
66 lines
2.0 KiB
TypeScript
66 lines
2.0 KiB
TypeScript
import {vi} from 'vitest'
|
|
import * as core from '@actions/core'
|
|
import {
|
|
BLUE_GREEN_VERSION_LABEL,
|
|
getManifestObjects,
|
|
GREEN_LABEL_VALUE
|
|
} from './blueGreenHelper.js'
|
|
import * as bgHelper from './blueGreenHelper.js'
|
|
import {Kubectl} from '../../types/kubectl.js'
|
|
import {
|
|
getServiceSpecLabel,
|
|
getUpdatedBlueGreenService,
|
|
validateServicesState
|
|
} from './serviceBlueGreenHelper.js'
|
|
|
|
let testObjects
|
|
const ingressFilepath = ['test/unit/manifests/test-ingress-new.yml']
|
|
vi.mock('../../types/kubectl')
|
|
const kubectl = new Kubectl('')
|
|
|
|
describe('blue/green service helper tests', () => {
|
|
beforeEach(() => {
|
|
vi.mocked(Kubectl).mockClear()
|
|
testObjects = getManifestObjects(ingressFilepath)
|
|
})
|
|
|
|
test('getUpdatedBlueGreenService', () => {
|
|
const newService = getUpdatedBlueGreenService(
|
|
testObjects.serviceEntityList[0],
|
|
GREEN_LABEL_VALUE
|
|
)
|
|
expect(newService.metadata.labels[BLUE_GREEN_VERSION_LABEL]).toBe(
|
|
GREEN_LABEL_VALUE
|
|
)
|
|
expect(newService.spec.selector[BLUE_GREEN_VERSION_LABEL]).toBe(
|
|
GREEN_LABEL_VALUE
|
|
)
|
|
})
|
|
|
|
test('validateServicesState', async () => {
|
|
const mockLabels = new Map<string, string>()
|
|
mockLabels[BLUE_GREEN_VERSION_LABEL] = bgHelper.GREEN_LABEL_VALUE
|
|
const mockSelectors = new Map<string, string>()
|
|
mockSelectors[BLUE_GREEN_VERSION_LABEL] = GREEN_LABEL_VALUE
|
|
vi.spyOn(bgHelper, 'fetchResource').mockImplementation(() =>
|
|
Promise.resolve({
|
|
kind: 'Service',
|
|
spec: {selector: mockSelectors},
|
|
metadata: {labels: mockLabels, name: 'nginx-service-green'}
|
|
})
|
|
)
|
|
expect(
|
|
await validateServicesState(kubectl, testObjects.serviceEntityList)
|
|
).toBe(true)
|
|
})
|
|
|
|
test('getServiceSpecLabel', () => {
|
|
testObjects.serviceEntityList[0].spec.selector[BLUE_GREEN_VERSION_LABEL] =
|
|
GREEN_LABEL_VALUE
|
|
|
|
expect(getServiceSpecLabel(testObjects.serviceEntityList[0])).toBe(
|
|
GREEN_LABEL_VALUE
|
|
)
|
|
})
|
|
})
|