|
| 1 | +import assert from 'node:assert/strict' |
| 2 | +import path from 'node:path' |
| 3 | +import { beforeEach, before, describe, it, mock, type Mock } from 'node:test' |
| 4 | +import { browserSdkVersion } from '../lib/browserSdkVersion.ts' |
| 5 | +import type { CommandDetail } from './lib/testHelpers.ts' |
| 6 | +import { mockModule, mockCommandImplementation } from './lib/testHelpers.ts' |
| 7 | + |
| 8 | +const currentBrowserSdkVersionMajor = browserSdkVersion.split('.')[0] |
| 9 | + |
| 10 | +describe('deploy-prod-dc', () => { |
| 11 | + const commandMock = mock.fn() |
| 12 | + const checkTelemetryErrorsMock: Mock<(datacenters: string[], version: string) => Promise<void>> = mock.fn() |
| 13 | + |
| 14 | + let commands: CommandDetail[] |
| 15 | + let checkTelemetryErrorsCalls: Array<{ version: string; datacenters: string[] }> |
| 16 | + |
| 17 | + before(async () => { |
| 18 | + await mockModule(path.resolve(import.meta.dirname, '../lib/command.ts'), { command: commandMock }) |
| 19 | + await mockModule(path.resolve(import.meta.dirname, '../lib/executionUtils.ts'), { |
| 20 | + timeout: () => Promise.resolve(), |
| 21 | + }) |
| 22 | + await mockModule(path.resolve(import.meta.dirname, './lib/checkTelemetryErrors.ts'), { |
| 23 | + checkTelemetryErrors: checkTelemetryErrorsMock, |
| 24 | + }) |
| 25 | + }) |
| 26 | + |
| 27 | + beforeEach(() => { |
| 28 | + commands = mockCommandImplementation(commandMock) |
| 29 | + checkTelemetryErrorsCalls = [] |
| 30 | + checkTelemetryErrorsMock.mock.mockImplementation((datacenters: string[], version: string) => { |
| 31 | + checkTelemetryErrorsCalls.push({ version, datacenters }) |
| 32 | + return Promise.resolve() |
| 33 | + }) |
| 34 | + }) |
| 35 | + |
| 36 | + it('should deploy a given datacenter', async () => { |
| 37 | + await runScript('./deploy-prod-dc.ts', 'v6', 'us1') |
| 38 | + |
| 39 | + // Should not call checkTelemetryErrors by default (no flag) |
| 40 | + assert.strictEqual(checkTelemetryErrorsCalls.length, 0) |
| 41 | + |
| 42 | + assert.deepEqual(commands, [ |
| 43 | + { command: 'node ./scripts/deploy/deploy.ts prod v6 us1' }, |
| 44 | + { command: 'node ./scripts/deploy/upload-source-maps.ts v6 us1' }, |
| 45 | + ]) |
| 46 | + }) |
| 47 | + |
| 48 | + it('should deploy a given datacenter with check telemetry errors', async () => { |
| 49 | + await runScript('./deploy-prod-dc.ts', 'v6', 'us1', '--check-telemetry-errors') |
| 50 | + |
| 51 | + // Should call checkTelemetryErrors 31 times: 1 initial + 30 during gating |
| 52 | + assert.strictEqual(checkTelemetryErrorsCalls.length, 31) |
| 53 | + assert.deepEqual(checkTelemetryErrorsCalls[0], { |
| 54 | + version: `${currentBrowserSdkVersionMajor}.*`, |
| 55 | + datacenters: ['us1'], |
| 56 | + }) // Initial check |
| 57 | + assert.deepEqual(checkTelemetryErrorsCalls[30], { version: browserSdkVersion, datacenters: ['us1'] }) // Last gating check |
| 58 | + |
| 59 | + assert.deepEqual(commands, [ |
| 60 | + { command: 'node ./scripts/deploy/deploy.ts prod v6 us1' }, |
| 61 | + { command: 'node ./scripts/deploy/upload-source-maps.ts v6 us1' }, |
| 62 | + ]) |
| 63 | + }) |
| 64 | + |
| 65 | + it('should only check telemetry errors before deploying if the upload path is root', async () => { |
| 66 | + await runScript('./deploy-prod-dc.ts', 'v6', 'root', '--check-telemetry-errors') |
| 67 | + |
| 68 | + // Should only call checkTelemetryErrors once (no gating for root) |
| 69 | + assert.strictEqual(checkTelemetryErrorsCalls.length, 1) |
| 70 | + assert.deepEqual(checkTelemetryErrorsCalls[0], { |
| 71 | + version: `${currentBrowserSdkVersionMajor}.*`, |
| 72 | + datacenters: ['root'], |
| 73 | + }) |
| 74 | + |
| 75 | + assert.deepEqual(commands, [ |
| 76 | + { command: 'node ./scripts/deploy/deploy.ts prod v6 root' }, |
| 77 | + { command: 'node ./scripts/deploy/upload-source-maps.ts v6 root' }, |
| 78 | + ]) |
| 79 | + }) |
| 80 | + |
| 81 | + it('should deploy all minor datacenters', async () => { |
| 82 | + await runScript('./deploy-prod-dc.ts', 'v6', 'minor-dcs', '--no-check-telemetry-errors') |
| 83 | + |
| 84 | + // Should not call checkTelemetryErrors when --no-check-telemetry-errors is used |
| 85 | + assert.strictEqual(checkTelemetryErrorsCalls.length, 0) |
| 86 | + |
| 87 | + assert.deepEqual(commands, [ |
| 88 | + { command: 'node ./scripts/deploy/deploy.ts prod v6 us3,us5,ap1,ap2,prtest00' }, |
| 89 | + { command: 'node ./scripts/deploy/upload-source-maps.ts v6 us3,us5,ap1,ap2,prtest00' }, |
| 90 | + ]) |
| 91 | + }) |
| 92 | +}) |
| 93 | + |
| 94 | +async function runScript(scriptPath: string, ...args: string[]): Promise<void> { |
| 95 | + const { main } = (await import(scriptPath)) as { main: (...args: string[]) => Promise<void> } |
| 96 | + |
| 97 | + return main(...args) |
| 98 | +} |
0 commit comments