mirror of
https://github.com/Azure/k8s-deploy.git
synced 2026-04-13 18:12: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
49 lines
1.5 KiB
TypeScript
49 lines
1.5 KiB
TypeScript
import {
|
|
getNormalizedPath,
|
|
isHttpUrl,
|
|
normalizeWorkflowStrLabel
|
|
} from './githubUtils.js'
|
|
|
|
describe('Github utils', () => {
|
|
it('normalizes workflow string labels', () => {
|
|
const workflowsPath = '.github/workflows/'
|
|
|
|
const path = 'test/path/test'
|
|
expect(normalizeWorkflowStrLabel(workflowsPath + path)).toBe(path)
|
|
expect(normalizeWorkflowStrLabel(path)).toBe(path)
|
|
expect(normalizeWorkflowStrLabel(path + workflowsPath)).toBe(
|
|
path + workflowsPath
|
|
)
|
|
expect(normalizeWorkflowStrLabel(path + ' ' + path)).toBe(
|
|
path + '_' + path
|
|
)
|
|
})
|
|
|
|
it('normalizes path', () => {
|
|
const httpUrl = 'http://www.test.com'
|
|
expect(getNormalizedPath(httpUrl)).toBe(httpUrl)
|
|
|
|
const httpsUrl = 'https://www.test.com'
|
|
expect(getNormalizedPath(httpsUrl)).toBe(httpsUrl)
|
|
|
|
const repo = 'gh_repo'
|
|
const sha = 'gh_sha'
|
|
const path = 'path'
|
|
process.env.GITHUB_REPOSITORY = repo
|
|
process.env.GITHUB_SHA = sha
|
|
expect(getNormalizedPath(path)).toBe(
|
|
`https://github.com/${repo}/blob/${sha}/${path}`
|
|
)
|
|
})
|
|
|
|
it('checks if url is http', () => {
|
|
expect(isHttpUrl('www.test.com')).toBe(false)
|
|
expect(isHttpUrl('http.test.com')).toBe(false)
|
|
expect(isHttpUrl('http:.test.com')).toBe(false)
|
|
expect(isHttpUrl('http:/.test.com')).toBe(false)
|
|
|
|
expect(isHttpUrl('https://www.test.com')).toBe(true)
|
|
expect(isHttpUrl('http://wwww.test.com')).toBe(true)
|
|
})
|
|
})
|