|
| 1 | +import assert from 'node:assert/strict' |
| 2 | +import path from 'node:path' |
| 3 | +import { beforeEach, before, describe, it, mock } from 'node:test' |
| 4 | +import type { CommandDetail } from './lib/testHelpers.ts' |
| 5 | +import { mockModule, mockCommandImplementation } from './lib/testHelpers.ts' |
| 6 | + |
| 7 | +// eslint-disable-next-line |
| 8 | +describe.only('deploy-prod-dc', () => { |
| 9 | + const commandMock = mock.fn() |
| 10 | + |
| 11 | + let commands: CommandDetail[] |
| 12 | + |
| 13 | + before(async () => { |
| 14 | + await mockModule(path.resolve(import.meta.dirname, '../lib/command.ts'), { command: commandMock }) |
| 15 | + await mockModule(path.resolve(import.meta.dirname, '../lib/executionUtils.ts'), { |
| 16 | + timeout: () => Promise.resolve(), |
| 17 | + }) |
| 18 | + }) |
| 19 | + |
| 20 | + beforeEach(() => { |
| 21 | + commands = mockCommandImplementation(commandMock) |
| 22 | + }) |
| 23 | + |
| 24 | + it('should deploy a given datacenter', async () => { |
| 25 | + await runScript('./deploy-prod-dc.ts', 'v6', 'us1') |
| 26 | + |
| 27 | + assert.deepEqual(commands, [ |
| 28 | + { command: 'node ./scripts/deploy/deploy.ts prod v6 us1' }, |
| 29 | + { command: 'node ./scripts/deploy/upload-source-maps.ts v6 us1' }, |
| 30 | + ]) |
| 31 | + }) |
| 32 | + |
| 33 | + it('should deploy a given datacenter with check monitors', async () => { |
| 34 | + await runScript('./deploy-prod-dc.ts', 'v6', 'us1', '--check-monitors') |
| 35 | + |
| 36 | + assert.deepEqual(commands, [ |
| 37 | + { command: 'node ./scripts/deploy/check-monitors.ts us1' }, |
| 38 | + { command: 'node ./scripts/deploy/deploy.ts prod v6 us1' }, |
| 39 | + { command: 'node ./scripts/deploy/upload-source-maps.ts v6 us1' }, |
| 40 | + // 1 monitor check per minute for 30 minutes |
| 41 | + ...Array.from({ length: 30 }, () => ({ command: 'node ./scripts/deploy/check-monitors.ts us1' })), |
| 42 | + ]) |
| 43 | + }) |
| 44 | + |
| 45 | + it('should only check monitors before deploying if the upload path is root', async () => { |
| 46 | + await runScript('./deploy-prod-dc.ts', 'v6', 'root', '--check-monitors') |
| 47 | + |
| 48 | + assert.deepEqual(commands, [ |
| 49 | + { command: 'node ./scripts/deploy/check-monitors.ts root' }, |
| 50 | + { command: 'node ./scripts/deploy/deploy.ts prod v6 root' }, |
| 51 | + { command: 'node ./scripts/deploy/upload-source-maps.ts v6 root' }, |
| 52 | + ]) |
| 53 | + }) |
| 54 | + |
| 55 | + it('should deploy all minor datacenters', async () => { |
| 56 | + await runScript('./deploy-prod-dc.ts', 'v6', 'minor-dcs', '--no-check-monitors') |
| 57 | + |
| 58 | + assert.deepEqual(commands, [ |
| 59 | + { command: 'node ./scripts/deploy/deploy.ts prod v6 us3,us5,ap1,ap2,prtest00' }, |
| 60 | + { command: 'node ./scripts/deploy/upload-source-maps.ts v6 us3,us5,ap1,ap2,prtest00' }, |
| 61 | + ]) |
| 62 | + }) |
| 63 | +}) |
| 64 | + |
| 65 | +async function runScript(scriptPath: string, ...args: string[]): Promise<void> { |
| 66 | + const { main } = (await import(scriptPath)) as { main: (...args: string[]) => Promise<void> } |
| 67 | + |
| 68 | + return main(...args) |
| 69 | +} |
0 commit comments